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. :)

ένας
  • 321

1 Answers1

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

egreg
  • 1,121,712