# Problem controlling vertical alignment of minipage containing only math

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

-
Welcome to TeX.sx! Do you want that the "0 blah" line is vertically aligned with "Beginning of line"? –  egreg Apr 19 '13 at 10:06
Yes, that's what I was hoping for. –  user27080 Apr 19 '13 at 10:16
Thanks a lot for the answer. I understand now. –  user27080 Apr 19 '13 at 10:54
Thanks egreg for the second answer. Cool. I know it looks weird - its going into a list on a presentation slide where I think it makes sense. –  user27080 Apr 19 '13 at 11:01

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

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

-

The top line of a cases environment is (almost) the center of the brace.

You can define a new environment:

\documentclass{article}
\usepackage{amsmath,calc,delarray}

\makeatletter
\newenvironment{topcases}[1][]
{\def\topc@lhs{#1}\m@th
$\let\@ifnextchar\new@ifnextchar \def\arraystretch{1.2}% \array[t]\{{@{}l@{\quad}l@{}}.} {\endarray$\end{lrbox}%
\ifx\topc@lhs\@empty\else
\sbox2{$\vcenter{\hbox{$\smash{\topc@lhs{}}\vphantom{=}$}}$}%
\raisebox{-.5\dp0+.5\height}{\box2}%
\fi
}
\makeatother

\begin{document}
Beginning of line
\begin{topcases}[x=] 0 & \text{blah} \\ 1 & \text{blah} \end{topcases}
rest of line.

Beginning of line
\begin{topcases}[x=] \dfrac{1}{2} & \text{blah} \\[2ex] 1 & \text{blah} \end{topcases}
rest of line.
\end{document}


The environment takes as optional argument the part before the brace that we must exclude from the computations.

The result doesn't seem that good, though. I'd much prefer to set the cases environment in a display.

-