Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Lamport, LaTeX: A document preparation system, states on p. 104:

There are two ways to make a parbox at a given point in the text: with the \parbox command and the minipage environment. They can be used to put one or more paragraphs of text inside a picture on in a table item.

\parbox and minipage share one mandatory argument (width of the parbox) and the optional argument (vertical alignment). (The second mandatory argument of \parbox "is the text to be put in the parbox" [p. 105].) Lamport recommends the use of minipages instead of parboxes in some cases (e.g. a parbox containing a tabbing or a list-making environment), but doesn't substantiate his advice (or at least I skipped that part). Finally, from Hendrik Vogt's comment to this answer, I gather that one reason to prefer minipages is that "[y]ou don't have to wait that long for the matching closing brace".

I'm aware that the \footnote command doesn't work with \parbox; by contrast, it "puts a footnote at the bottom of the parbox produced by the [minipage] environment" (Lamport, p. 105). Are there other differences in applicability between \parbox and the minipage environment?

P.S.: Kopka and Daily, A guide to LaTeX, state on p. 89:

The text in a \parbox may not contain any of the centering, list, or other environments described in Sections 4.2 through 4.5. These may, on the other hand, appear within a minipage environment.

However, I did some tests using center, itemize and tabbing environments within a \parbox, and LaTeX did not throw error messages. Are Kopka and Daly wrong, or did I miss something?

share|improve this question
1  
Perhaps I meant syntactic? –  Hendrik Vogt Dec 3 '10 at 17:16
    
@Hendrik: Perhaps I should only quote statements I get the hang of? (But I do grasp the concept of matching braces, I swear!) –  lockstep Dec 3 '10 at 17:24
    
I'm rather sure you fully got what I meant. I'm just not so sure which word would have been adequate where I wrote "semantically" ... –  Hendrik Vogt Dec 3 '10 at 18:17

3 Answers 3

up vote 21 down vote accepted

The main reason I see to use minipage over \parbox is to allow verbatim (\verb, verbatim, etc.) text inside the box (unless, of course, you also put the minipage inside a macro argument).

EDIT Here are other differences between minipage and \parbox (from the comments to Yiannis' answer and from looking at the source code of both these macros in source2e).

A first difference, as already mentioned by lockstep in his question, is in the footnote treatment: minipage handles them by putting them at the bottom of the box while footnotes are lost in a \parbox (to avoid this, you must resort to the \footnotemark/footnotetext trick):

alt text

\documentclass{article}
\begin{document}
\parbox[t]{3cm}{text\footnote{parbox footnote}}
\begin{minipage}[t]{3cm}text\footnote{minipage footnote}\end{minipage}
\end{document}

A second difference is in that minipage resets the \@listdepth counter, meaning that, inside a minipage, you don't have to worry about the list nesting level when using them. Here's an example which illustrates the point:

\documentclass{article}
\begin{document}
\begin{list}{}{}\item\begin{list}{}{}\item\begin{list}{}{}\item\begin{list}{}{}\item
    \begin{list}{}{}\item\begin{list}{}{}
  \item %\parbox{5cm}{\begin{list}{}{}\item \end{list}}% error
  \item %\begin{minipage}{5cm}\begin{list}{}{}\item \end{list}\end{minipage}% no error
\end{list}\end{list}\end{list}\end{list}\end{list}\end{list}
\end{document}

A third difference is that minipage sets the boolean \@minipagefalse which in turn deactivates \addvspace if it's the first thing to occur inside a minipage. This means that minipage will have better spacing and allow better alignment compared to \parbox in some cases like the following (left is minipage, right is \parbox):

alt text

\documentclass{article}
\begin{document}
Pros: \begin{minipage}[t]{3cm}\begin{itemize}\item first \item second%
    \end{itemize}\end{minipage}
Cons: \parbox[t]{3cm}{\begin{itemize}\item first \item second\end{itemize}}
\end{document}
share|improve this answer
2  
One can (apparently, I've never tried it) use the footnote package to get sane behavior with footnotes in both \parbox and minipage. –  TH. Dec 4 '10 at 22:23
1  
@TH: the footnote package does the right thing (or did 15 years ago when i tried it), but it's pretty old now and one might expect it to interact badly with other sophisticated packages. –  wasteofspace Jan 30 '12 at 19:51
    
@lockstep: I know it's not a common practice, but I did put those braces around environments on purpose (clearer distinction between commands and environments). Oh, and there's still one left (the line beginning with EDIT). –  Philippe Goutet Sep 22 '12 at 14:55
    
@PhilippeGoutet I corrected the one left. If you feel strongly about the braces, please use the "rollback" feature to revert to the former version of the post, and I will refrain from editing it again. –  lockstep Sep 22 '12 at 14:57
1  
@Christian: not really, no. An additional difference, though: the values of \textwidth and \columnwidth are untouched by \parbox but changed to the {minipage} width. –  Philippe Goutet Feb 27 '13 at 18:42

When your text you wish to enclose contains only a small piece of text then use \parbox. It should have nothing fancy inside such as any of the paragraph making environments. For larger pieces of text, such as those that do contain paragraph-making environments you should use a minipage environment.

There are also more subtle differences between the two such as the amount of space left on top etc. In general a minipage acts like a full page, whereas a parbox acts more like a fancy paragraph. Both of them offer very little semantic meaning - in my opinion. You can add semantic meaning by creating new environments with macro names that reflect their function in the document structure. For example you could define one of those boxes that one finds in manuals with a framed warning, a warning box using parbox and call it warning.

share|improve this answer
    
@Yannis: You're right that neither \parbox nor minipage offer semantic meaning. As for "\parbox[...] should have nothing fancy inside such as any of the paragraph making environments", I'd like to hear why this is so. –  lockstep Dec 3 '10 at 17:05
    
@lockstep It's not as if the fate of the earth depends on it, but if you do you will get all sorts of errors. If there is an answer to the why it can be found in ltboxes.dtx in the source2e (it beat me I don't really make heads or tails out of it!) but from what I can gather the parbox is just a box while the minipage is an environment based on parbox. To simplify my life, I mostly use minipage. –  Yiannis Lazarides Dec 3 '10 at 18:29
    
@Yannis: I'd like to see an example where \parbox results in an error but minipage doesn't. (That is, an example without using verbatim stuff.) –  lockstep Dec 3 '10 at 18:33
    
@Yannis: Thanks for pointing me to source2e. –  lockstep Dec 3 '10 at 18:44
3  
@lockstep: as you can see by looking at source2e, {minipage} resets \@listdepth whereas \parbox does not. So if you nest six \begin{list}{}{}\item...\end{list} inside each other and then use another one in a \parbox, there will be a too deeply nested error which would not appear if you had used {minipage}. –  Philippe Goutet Dec 3 '10 at 19:26

If you make a new environment, you must enclose the body of the environment using lrbox first, then use the saved box in \parbox. But if you use minipage instead of \parbox, lrbox is no longer needed.

share|improve this answer
    
depending on what you're doing, that's only partially true. For example, if you want to put the content of an environment inside a macro (let's say \fbox), you need the {lrbox} whether you use \parbox or {minipage}. –  Philippe Goutet Dec 3 '10 at 16:49
    
@Philippe: You can't use \parbox macro to collect the content of an environment in any case. It is true, that you need to box the content first to use it in a macro later, but that is not the fault of minipage. –  Martin Scharrer Jun 28 '11 at 13:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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