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.

Occasionally, the width of a minipage environment seems to be ignored. I've not kept accurate records of when this has happened. But below is purely illustrative code that shows the issue.

\documentclass[12pt]{article}
\usepackage{amsmath,calc}
\usepackage{lipsum}
\pagestyle{empty}
\begin{document}

\noindent
The next two boxes came out as I expected them to.\\[\baselineskip]
%%
\noindent
\fbox{\begin{minipage}[t]{0.4\textwidth-2\fboxrule-2\fboxsep}
The contents of the next line are too long to fit within this box.
\begin{align}
    \arctan(x/a) &= \frac{1}{a} \int_0^\infty \sum_{n=0}^{\infty} \left(-t^2/a^2\right)\mathrm{d}t
\end{align}
I did not use \texttt{notag} and the width of the box has \textbf{NOT} been altered.
\end{minipage}}%
\fbox{\begin{minipage}[t]{0.6\textwidth-2\fboxrule-2\fboxsep}%
    \raggedright{}
    \lipsum[22]
\end{minipage}}%

\vspace{1cm}

\noindent
The first box below does not have the width I desired.\\[\baselineskip]
%%
\noindent
\fbox{\begin{minipage}[t]{0.4\textwidth-2\fboxrule-2\fboxsep}
The contents of the next line are too long to fit within this box.
\begin{align}
    \arctan(x/a) &= \frac{1}{a} \int_0^\infty \sum_{n=0}^{\infty} \left(-t^2/a^2\right)\mathrm{d}t
    \notag
\end{align}
I used \texttt{notag} and the width of the box has been altered.
\end{minipage}}%
\fbox{\begin{minipage}[t]{0.6\textwidth-2\fboxrule-2\fboxsep}%
    \raggedright{}
    \lipsum[23]

\end{minipage}}

\end{document}

enter image description here

Can someone please explain what's going on here? How can I force the first box of the second example to have the width I expect it to have?

share|improve this question
    
I'd have to dig through my code, but I seem to recall an occasion where this happened when I embedded an image within a minipage. I'll try to find that example to further illustrate. –  A.Ellett Nov 24 '12 at 17:56
    
It seems that align resets the \hsize inside the second minipage. –  egreg Nov 24 '12 at 18:04
    
@egreg Indeed. But why? Moreover, it only seems to be resetting it after it's typeset the rest of the text. And why is it not resetting box width in the first example. I guess a better question would be: how could I get the minipage to respect the specified width in the second example? –  A.Ellett Nov 24 '12 at 18:06
2  
The \hsize is not changed, actually. I believe that, when a number has to be placed under the equation, align boxes the equation at the correct width, while it doesn't bother to when no number is requested. When the \vbox connected to the minipage is wrapped up, it takes as its width the maximum width of the boxes inside (at the first level). –  egreg Nov 24 '12 at 18:09
    
@egreg, so how could I tell \vbox what width I actually want? Am I going to have to do something TeXy like \setbox0=...., and then manually set the box width with \wd0=.... I hope not because that just seems prone to a huge headache (particularly when the width of the box is calculated in some complex way). –  A.Ellett Nov 24 '12 at 18:33
add comment

2 Answers

up vote 5 down vote accepted

This is a minimal example:

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\showboxdepth=5 \showboxbreadth=100 
\sbox0{\vbox{\hsize=10pt
  \noindent\begin{align*}\hbox to 15pt{}\end{align*}}}
\showbox0

\sbox0{\vbox{\hsize=10pt
  \noindent\begin{align}\hbox to 15pt{}\end{align}}}
\showbox0

\end{document}

The log file shows

> \box0=
\hbox(29.0+0.0)x15.0
.\vbox(29.0+0.0)x15.0
..\penalty 10000
..\glue(\abovedisplayskip) 10.0 plus 2.0 minus 5.0
..\glue -3.0
..\glue 0.0
..\hbox(8.39996+3.60004)x15.0, display
...\glue(\tabskip) 0.0
...\hbox(8.39996+3.60004)x15.0
....\glue 0.0 plus 1.0fil
....\hbox(8.39996+3.60004)x0.0
.....\vbox(8.39996+3.60004)x0.0 []
....\hbox(0.0+0.0)x15.0
.....\mathon
.....\hbox(0.0+0.0)x15.0
.....\mathoff
...\glue(\tabskip) 0.0
...\hbox(8.39996+3.60004)x0.0
....\hbox(0.0+0.0)x0.0
.....\mathon
.....\hbox(0.0+0.0)x0.0
.....\mathoff
....\glue 0.0 plus 1.0fil
...\glue(\tabskip) 10.0
...etc.
..etc.

! OK.
l.8 \showbox0

> \box0=
\hbox(41.0+0.0)x10.0
.\vbox(41.0+0.0)x10.0
..\penalty 10000
..\glue(\abovedisplayskip) 10.0 plus 2.0 minus 5.0
..\glue -3.0
..\glue 0.0
..\hbox(8.39996+15.60004)x10.0, display
...\glue(\tabskip) 0.0
...\hbox(8.39996+15.60004)x15.0
....\glue 0.0 plus 1.0fil
....\hbox(8.39996+3.60004)x0.0
.....\vbox(8.39996+3.60004)x0.0 []
....\hbox(0.0+0.0)x15.0
.....\mathon
.....\hbox(0.0+0.0)x15.0
.....\mathoff
...\glue(\tabskip) 0.0
...\hbox(8.39996+15.60004)x0.0
....\hbox(0.0+0.0)x0.0
.....\mathon
.....\hbox(0.0+0.0)x0.0
.....\mathoff
....\glue 0.0 plus 1.0fil
...\glue(\tabskip) 10.0
...etc.
..etc.

! OK.
l.12 \showbox0

As you can see, the first box is 15pt wide, because at the outer level inside the \vbox there is

..\hbox(8.39996+3.60004)x15.0, display

while in the second one we find

..\hbox(8.39996+15.60004)x10.0, display

It seems that align boxes the equation to the overall \hsize when it has to place an equation number (shifted down), but doesn't bother to when no equation number is required.

This doesn't happen when equation/equation* or gather/gather* are used.

share|improve this answer
    
This is similar to what I just worked out based upon your comment above: I saved the width of the box to a dummy length, set \setbox0 equal to the the entire minipage. I called \copy0 and then manually reset the width of the box using \wd0=\dummy. I'm not too happy with this solution: I don't like mucking around in TeX for something which it seems should be do-able in LaTeX. But, it works and I still keep the desired overflow effect. –  A.Ellett Nov 24 '12 at 18:38
    
@A.Ellett Mine is not really an answer, in that it doesn't tell how to avoid the issue. :( I'm inclined to consider it a "feature" of amsmath. –  egreg Nov 24 '12 at 18:39
    
@egreg -- equation is handled differently from the multi-line structures in amsmath, but gather should behave in the same way as align. (it's my opinion that align shouldn't be used for one-line displays, though many people do.) i'll put this on the list to be researched. should the [amsmath] tag be added to the question? –  barbara beeton Nov 24 '12 at 19:29
    
@barbarabeeton I agree with you about using align in those cases; I used it here just as an example, of course. The problem shows also with more than one line. I confirm that with gather* it doesn't show. Quite strange indeed. –  egreg Nov 24 '12 at 20:21
    
@egreg and @barbarabeeton. While the examples with line numbers seem to work as expected, there something about having \notag anywhere in the box. In the first example add a very short line following the first and append it with \notag. Somehow the width of the numbered lines is what is seen by the outer box. –  A.Ellett Nov 24 '12 at 20:47
show 1 more comment

I tried nesting the culprit in its own minipage within the minipage. That seems to fix the problem. Whatever \vbox might be doing within the inner most box seem not to get inherited in the super-boxes.

\noindent
This seems to work.\\[\baselineskip]
%%
\noindent
\fbox{%
\begin{minipage}[t]{\dummy}
The contents of the next line are too long to fit within this box.\newline
\begin{minipage}{\textwidth}
\begin{align}
    \arctan(x/a) &= \frac{1}{a} \int_0^\infty \sum_{n=0}^{\infty} \left(-t^2/a^2\right)\mathrm{d}t
    \notag
\end{align}~
\end{minipage}\newline
I used \texttt{notag} and the width of the box has been altered.
\end{minipage}}%
\fbox{\begin{minipage}[t]{0.6\textwidth-2\fboxrule-2\fboxsep}%
    \raggedright{}
    \lipsum[23]
\end{minipage}}%

Thanks @egreg. I wouldn't have thought of this sort fix without your input.

share|improve this answer
add comment

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.