11

Some LaTeX commands accept multiple optional arguments. Here are some examples:

  • \makebox[<width>][<pos>]{<text>}
  • \framebox[<width>][<pos>]{<text>}
  • \parbox[<pos>][<height>][<contentpos>]{<width>}{<text>}
  • \raisebox{<lift>}[<height>][<depth>]{<text>}
  • \begin{minipage}[<pos>][<height>][<contentpos>]{<width>} <content> \end{minipage} (actually an environment)

(But my question is meant in a fully general way.)

It would seem intuitive that if only a proper subset of optional arguments is supplied, they are filled in starting from the left. (<- Note that this guess turns out to be incorrect!)

But is the behavior documented somewhere? Does anybody know of any counterexamples? There is no a priori reason why all commands would have to behave like that.

  • Actually the missing ones are not "filled", because the corresponding natural dimension is used (and the alignment <contentpos> is meaningless in this case). For \parbox and minipage the first optional argument has a default value c – egreg Dec 23 '13 at 22:30
  • 1
    The citation commands offered by biblatex are counterexamples, aren't they? That is \autocite[A]{key} is equivalent to \autocite[][A]{key}. To get A read for the first optional argument, you have to write \autocite[A][]{key} explicitly. Is that what you meant? – cfr Dec 24 '13 at 0:10
  • Or are you concerned only with commands in base? – cfr Dec 24 '13 at 4:20
  • You should consider searching for the mentioned macros in source2e. Their usage and definitions are described there. – Werner Dec 24 '13 at 4:23
  • 1
    @LoverofStructure No, there's no general convention about how to interpret missing optional arguments. – egreg Dec 24 '13 at 10:11
11

There is no general convention for interpreting missing optional arguments. What you take as examples shows this: there is no “filling from the left”, which wouldn't make much sense.

In some cases the command behaves differently than those you cite. For example, citation commands in biblatex have the form

\command[prenote][postnote]{keys}

and a missing second optional argument makes the first to be interpreted as postnote. This is a choice made by the programmer.

This is not a “counterexample”, because no general rule can be stated.


The four commands and the environment you mention are described in the LaTeX manual, but the extended syntax, that is the second and third optional arguments to \parbox and minipage, is described only in the LaTeX Companion.

  • \makebox[wdth][pos]{text} is at page 217 of the LaTeX manual. The second optional argument makes sense only if the first is specified; it defaults to c and may also be l, r or s. They mean “center”, “left”, “right” and “spread”; the first three are almost obvious because they mean how the material is placed with respect to the stated width; the last one means that the spaces in the material will be stretched to fill the stated width.

  • \framebox has exactly the same syntax as \makebox

  • \raisebox{raise_len}[width][depth]{text} is at page 219 of the LaTeX manual. The second optional argument for stating the depth of the resulting box can be used only if the first one is specified.

  • \parbox[pos][height][inner-pos]{width}{text} can be found at page 866 of the LaTeX Companion (second edition). The LaTeX manual mentions only the first optional argument. For minipage the arguments have exactly the same meaning.

What do the optional arguments of \parbox and minipage do?

The third optional argument can be given only if preceded by the other two; the second only if preceded by the first.

The first optional argument can be c (default), t or b, saying how the resulting box will be vertically aligned with respect to the surrounding material. For t the alignment will be with respect to the baseline of the first item in the box, for b the last item will be used; c means the box is vertically centered, half above the baseline and half below it (almost).

The second optional argument states a vertical dimension for the box. Here's an example; \rod just draws a measuring rule with a marker for the baseline sticking at its left; \fbox is used to show the box extension.

\documentclass{article}
\newcommand{\rod}[2]{%
  \leavevmode\smash\llap{\vrule height .2pt depth .2pt width 4pt \vrule height #1 depth #2}%
}

\setlength{\fboxsep}{0pt}

\begin{document}

\rod{2cm}{0pt}
\fbox{\parbox[b][2cm]{.3\textwidth}{
  Some text\\
  some other text\\
  again
}}

\end{document}

enter image description here

We might use c for the third optional argument

\parbox[b][2cm][c]{.3\textwidth}{...}

and we'd get

enter image description here

Note that the box's extension is the same, only the text inside is moved to be at the center of the available space. If the third argument is not expressed, it defaults to be the same as the first.

The last optional argument can also be s, but some flexible space must be provided. For instance

\parbox[b][2cm][s]{.3\textwidth}{
  Some text\\[\fill]
  some other text\\[\fill]
  again
}

would produce

enter image description here

Note that in none of the above cases the depth of the last item in the box is taken into consideration as far as the vertical dimension is concerned. In the second example the box is exactly 2cm in the vertical direction because the last item is the filling glue, which has no depth.

Here's a combined example for “top” outer alignment. Similar considerations as before apply.

\documentclass{article}
\newcommand{\rod}[2]{%
  \leavevmode\smash\llap{\vrule height .2pt depth .2pt width 4pt \vrule height #1 depth #2}%
}

\setlength{\fboxsep}{0pt}

\begin{document}

\rod{\ht\strutbox}{\dimexpr2cm-\ht\strutbox}
\fbox{\parbox[t][2cm]{.3\textwidth}{
  \strut Some text\\
  some other text\\
  again
}}

\rod{0pt}{2cm}
\fbox{\parbox[t][2cm][b]{.3\textwidth}{
  \strut Some text\\
  some other text\\
  again
}}

\rod{\ht\strutbox}{\dimexpr2cm-\ht\strutbox}
\fbox{\parbox[t][2cm][s]{.3\textwidth}{
  \strut Some text\\
  some other text\\[\fill]
  again
}}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.