What I'm trying to do: I have a page that consists of pairs of two sentences each. The pairs are separated by a whole line break. My problem is that when I have an odd number of pairs, the second sentence will automatically be placed on the next column.
How can I use LaTeX to make block structures that multicol does not ignore, to keep the two sentences together? If there's better code to solve this problem, or a better column implementation (though I don't believe I can use \twocolumn in the document declaration), please post it.
My current code:
\documentclass{article}
\usepackage{fullpage}
\usepackage{multicol}
\setlength{\parindent}{0pt}
\setlength{\parskip}{\baselineskip}
\newcommand{\pair}[2]{
\emph{#1}\\*
#2
}
\begin{document}
\begin{multicols}{2}
\pair{Sentence 1.}{Sentence 2.}
\pair{Sentence 2 (pair 2).}{Sentence 2 (pair 2).}
\pair{The last pair, first sentence.}{Last sentence.}
\end{multicols}
\end{document}
This generates: http://img541.imageshack.us/img541/3444/columns.png . The second pair is what I am trying to avoid.
Try this:
\newcommand{\pair}[2]{%
\parbox{\hsize}{\emph{#1}\\*#2}\par}
Related
How do I combine \afterpage and \endfloat to easily switch between having figures and tables at the end of the document or having them in the text?
I want to easily choose between my figures at the end of the document and my figures in the text. Because of that, sometimes I will use \afterpage package and other times I will use \endfloat would be nice to combine both.
Right now, all the times I try to run \endfloat when I have a clear page, I get the following message:
Argument of \efloat#xfloat has an extra }.
I already tried to include after page in the DeclareDelayedFloatFlavor, something like:
\DeclareDelayedFloatFlavor{afterpage}{figure}
It did not work.
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{float}
\usepackage{afterpage}
% ---------------------
%figures at the end
% ---------------------
\usepackage[nolists]{endfloat}
% force landscape at the end
\begin{document}
{\afterpage{
\begin{figure}
\end{figure}
}
\end{document}
If you want to switch between having figures within the text and at the end, I suggest to only use the endfloat package. Commenting or commenting it's optional argument disable will allow you to quickly alternate between figures at the end or in the text.
I'm not entirely certain what the purpose of afterpage was in your example, but if you used it to move the figure to a separate page, this can conveniently be done with the p floating specifier.
\documentclass{article}
\usepackage[
disable
]{endfloat}
\begin{document}
test
\begin{figure}[p]
xxx
\caption{caption}
\end{figure}
test
\end{document}
I have a list of names which I would like to input into a given surrounding, e.g. a box. Put in a different way: I'd like LaTex to create a surrounding for every item in a given list.
Here's my list:
Frank, Fred, Fran
Here's my surrounding:
\fbox{\name}
\name does the following: it inputs the first item from the list and creates another \fbox for each successive item in the list until the end of the list, as a result outputting the same as (but saving the typing of)
\fbox{Frank}
\fbox{Fred}
\fbox{Fran}
I am thinking of the list of names as a "count" (redefining 1 as Frank, 2 as Fred...) and this might be the wrong approach.
I realise that a command can probably not do those two things at once.
If there's a simple solution to this: what is it called and where can I find it? searching for 'variables' or 'foreach' didn't help.
Depending on your application, you can either specify the list explicitly, or in a file:
As an explicit list (see How to iterate over a comma separated list?):
\documentclass{article}
\usepackage{etoolbox}
\newcommand{\printlist}[1]{%
\begin{enumerate}
\renewcommand*{\do}[1]{\item \fbox{##1}}%
\docsvlist{#1}%
\end{enumerate}%
}
\begin{document}
\printlist{Frank, Fred, Fran}
\end{document}
As a file in (say) names.csv:
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{names.csv}
Frank
Fred
Fran
\end{filecontents*}
\usepackage{datatool}
\newcommand{\printlist}[1]{%
\DTLloaddb[noheader,keys=name]{namesdb}{#1}% Load names database file
\begin{enumerate}
\DTLforeach{namesdb}{\name=name}{\item \fbox{\name}}
\end{enumerate}
}
\begin{document}
\printlist{names.csv}
\end{document}
In both instances, the output resembles:
I need a macro that extracts pairs of number from a string that looks like this:
n1-m1,n2-m2,n3-m3,n4-m4 (it could be longer)
where n1,m1,n2,m2,... are numbers from 0 - 15. How can I go about getting the pairs (n1,m1), and (n2,m2), (n3,m3), etc inside my macro? I will need to use each pair once, after which I can, if needed, disregard the pair.
Assuming each digit is a 2-digit number (not an elegant thing to do), and butchering a code I found by Debilski in this forum, I managed to get the first pair doing the following:
\documentclass[11pt]{article}
\def\macroGetPairs #1{\getPairs#1.\wholeString}
\def\getPairs#1#2-#3#4,#5\wholeString {
\if#1.%
\else
% Test if pair was successfully extracted
Got pair (#1#2,#3#4). Still left: #5\\
% Begin recursion
%\takeTheRest#5\ofTheString
\fi}
\def\takeTheRest#1\ofTheString\fi
{\fi \getPairs#1\wholeString}
\begin{document}
\macroGetPairs{10-43,40-51,60-73,83-97}
\end{document}
However, I am not sure how to get the recursion working for me to get the rest of the pairs. I thought that simply uncommenting the line
%\takeTheRest#5\ofTheString
should do it, but it does not work. Note that the macro's test call is:
\macroGetPairs{10-43,40-51,60-73,83-97}
Any suggestions? Thank you very much,
ERM
This seems to get your test to work:
\documentclass{article}
\def\macroGetPairs#1{\getPairs#1,.\wholeString}
\def\getPairs#1#2-#3#4,#5\wholeString {%
Got pair (#1#2,#3#4).\\
\if#5.\else%
\getPairs#5\wholeString
\fi}
\begin{document}
\noindent\macroGetPairs{10-43,40-51,60-73,83-97}
\end{document}
Your code was basically working, but there was no way for \getPairs to match its input on the final expansion (\getPairs 83-97). Your end-of-recursion test (\if#1.) was also testing #1 rather than #5, which is what I've done here. Maybe if there was some different way of formatting the argument to \getPairs that would have worked.
I have a list/sublist structure in my LaTeX document. By default, the sublist is delimited with letters, so you end up with this:
1. Item
(a) sub item
(b) sub item
In my document, I've got more than 26 sub items, so I was running into a Counter overflow error, which I fixed by rewriting the sub item label, so that they now look like this
1. Item
1.1 sub item
1.2 sub item
I've put a label on one of the items so that I can reference the specific step later on. The problem is that when the reference is rendered, it's rendered using a letter, not the number of the sub item.
Here's a sample doc that shows the problem.
\documentclass[11pt]{report}
\begin{document}
\renewcommand{\labelenumii}{\arabic{enumi}.\arabic{enumii}}
\begin{enumerate}
\item Item
\begin{enumerate}
\item \label{lbl} Label here
\end{enumerate}
\end{enumerate}
Ref: \ref{lbl}
\end{document}
This gets rendered like this:
1. Item
1.1 Label here
Ref: 1a
So instead of saying "Ref: 1.1", it's using "Ref: 1.a". Is there a way to make the \ref use the numbering of the source enumeration? If not, is there anyway to generate correct references to items in a sublist with more than 26 items?
I'm looking at my copy of The LaTeX Companion, p.129, and from what I'm seeing I would suggest something like the following:
\renewcommand{\theenumii}{\arabic{enumii}}
\renewcommand{\labelenumii}{\theenumi.\theenumii.}
\makeatletter
\renewcommand{\p#enumii}{\theenumi.}
\makeatother
I don't have access to a working LaTeX environment to test this at the moment, though.
So for 2 nested lists it should be done in the following way:
\begin{enumerate}
\renewcommand{\theenumi}{\arabic{enumi}}
\renewcommand{\theenumii}{\arabic{enumii}}
\renewcommand{\theenumiii}{\arabic{enumiii}}
\renewcommand{\labelenumi}{\theenumi.}
\renewcommand{\labelenumii}{\theenumi.\theenumii.}
\renewcommand{\labelenumiii}{\theenumi.\theenumii.\theenumiii.}
\makeatletter
\renewcommand{\p#enumii}{\theenumi.}
\renewcommand{\p#enumiii}{\theenumi.\theenumii.}
\makeatother
...
\end{enumerate}
It has taken to me too much time to understand it.
I hope this helps as this thread helped me.
Thanks.
This stems out of How can one number paragraphs in LaTeX?, which I asked earlier today:
Running with Brent.Longborough's suggestion for how to number paragraphs in a document:
\setcounter{secnumdepth}{5}
...
\paragraph{If we want to}
\paragraph{do something}
This results in LaTeX producing something likeso:
0.0.0.1 If we want to
0.0.0.2 do something
How can one change the numbering scheme of \paragraph{} to produce something like:
1. If we want to
2. do something
or alternatively
A. If we want to
B. do something
Thank you.
To change the number referenced when referring to paragraphs, you want to change \theparagraph. Here's an example:
\documentclass[12pt]{article}
\setcounter{secnumdepth}{5}
\renewcommand\theparagraph{\roman{paragraph}}
\usepackage{lipsum}
\begin{document}
\paragraph{foo} \lipsum[1]
\paragraph{bar} \lipsum[2]
\end{document}
Instead of \roman you can also use \Roman, \arabic, \alph, \Alph. Although if you have lots of paragraphs you'll want to use the alphalph package and use \alphalph to get more than 26 paragraphs.
Note that \paragraph takes an argument for the "paragraph title". If you never want that, you'll probably want to define your own command to simplify things:
\newcommand\PARA{\paragraph{}}
You'll also probably want to remove the way that paragraphs are numbered "within" sections; i.e., they reset from "1" for every new section. You can get around this with something like
\usepackage{remreset}
\makeatletter
\#removefromreset{paragraph}{section}
\makeatother