[Tex/LaTex] Problem controlling vertical alignment of minipage containing only math

minipagevertical alignment

I would like to insert a large box containing maths into a line of text and align the box with the top of main line. Strangely, the argument "[t]" gets ignored in the first example below (the second works as expected):

Beginning of line
\begin{minipage}[t]{40mm}\raggedright
$x = \begin{cases} 0 & \text{blah} \\ 1 & \text{blah} \end{cases}$
\end{minipage}
rest of line.

Beginning of line
\begin{minipage}[t]{4cm}\raggedright
(things work fine as long as the content is text)
\end{minipage}
rest of line here

Best Answer

(Please always post complete documents showing packages used, not just fragments)

The [t] is not ignored it just doesn't work the way you wish. You would see the difference if you added further text inside the minipage so the minipage had more than one row. As it is, the minipage just has a single row so b and t are the same and align the reference point on the box with the baseline of the first row. In the case of the math expression the baseline of the expression is the baseline of the x.

Simplest is to put an (invisible) extra row at the top of the minipage so that the page aligns with that and then move the math up one baseline to compensate.

enter image description here

\documentclass{article}

\usepackage{amsmath}

\begin{document}

Beginning of line
\begin{minipage}[t]{40mm}\raggedright
\mbox{}\\[-\baselineskip]
$x = \begin{cases} 0 & \text{blah} \\ 1 & \text{blah} \end{cases}$
\end{minipage}
rest of line.

Beginning of line
\begin{minipage}[t]{4cm}\raggedright
(things work fine as long as the content is text)
\end{minipage}
rest of line here

\end{document}