1

I have been using minipage environment with displayed equation environments align* and gather*. The align* environment works fine with minipage but does not work well with varwidth.

Code1:

\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}    
\usepackage{varwidth}   

\begin{document}
\fcolorbox{blue}{white}{\begin{minipage}[t]{0.002\linewidth}
\begin{align*}          
4x(x-5)&=0\\
4x=0\text{ or }x-5&=0\\
x=0\text{ or }x&=5.
\end{align*}
\end{minipage}}

\end{document}

Output1:

enter image description here

Code2:

\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}    
\usepackage{varwidth}   

\begin{document}
\fcolorbox{blue}{white}{\begin{varwidth}[t]{0.002\linewidth}
\begin{align*}          
4x(x-5)&=0\\
4x=0\text{ or }x-5&=0\\
x=0\text{ or }x&=5.
\end{align*}
\end{varwidth}}

\end{document}

Output2:

enter image description here

Note that, this 0.002\linewidth is supposed to be the minimum width.

The same problem happens when using gather* with either varwidth or minipage. Besides, the centering of the equation lines is messed up.

Code3:

\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}    
\usepackage{varwidth}   

\begin{document}
\fcolorbox{blue}{white}{\begin{minipage}[t]{0.002\linewidth}
\begin{gather*}         
4x(x-5)=0\\
4x=0\text{ or }x-5=0\\
x=0\text{ or }x=5.
\end{gather*}
\end{minipage}}

\end{document}

Code4:

\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}    
\usepackage{varwidth}   

\begin{document}
\fcolorbox{blue}{white}{\begin{varwidth}[t]{0.002\linewidth}
\begin{gather*}         
4x(x-5)=0\\
4x=0\text{ or }x-5=0\\
x=0\text{ or }x=5.
\end{gather*}
\end{varwidth}}

\end{document}

Outputs 3 and 4:

enter image description here

I can use the minipage since it's working with the align* environment. But I'd still need to have the gather* environment fixed.

I'm using LuaLaTeX output mode.

Please advise. :)

6
  • 2
    Why do t you just use empheq? It has features build in to enable you to add frames around math, even allows eq numbers. Though, your question is interesting. – daleif Mar 26 '17 at 7:52
  • I tried using empheq, it works fine with both align* and gather*. But the package conflicts with other packages I'm using. – ένας Mar 26 '17 at 8:30
  • It would be great if there is a way to use empheq without loading mathtools with it. – ένας Mar 26 '17 at 8:43
  • 1
    I think you should probably change the title to say gather doesn't work with varwidth. I just looked at this (as current maintainer of amsmath) to see if there was a bug in gather, but it is working in minipage exactly as expected, centered in a box the size of the minipage (or overfull if that box is too small) – David Carlisle Mar 26 '17 at 9:00
  • 1
    Why don't you want to load mathtools? It's ‘only’ a very useful extension of amsmath. – Bernard Mar 26 '17 at 11:09
3

The way gather is implemented makes it it impossible for varwidth to correctly guess its “real” dimensions.

You can do by using the inline version, gathered, which doesn't even need varwidth:

\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}

\begin{document}

\fcolorbox{blue}{white}{%
  $\begin{gathered}
  4x(x-5)=0\\
  4x=0\text{ or }x-5=0\\
  x=0\text{ or }x=5.
  \end{gathered}$%
}

\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.