# Alignment in inline math

I want to enclose a tabular environment with a bracket, inside an enumerate environment, and be aligned to top.

In the following example:

\documentclass[a4paper]{article}
\begin{document}
\begin{enumerate}
\item
$$\left.\begin{tabular}{l} First line\\ Second line\\ Third line \end{tabular}\right\}$$
Text
\end{enumerate}
\end{document}


I get everything centred, and not aligned to top:

If I ask tabular to be aligned at top, then still the inline math is not, so the following happens:

\documentclass[a4paper]{article}
\begin{document}
\begin{enumerate}
\item
$$\left.\begin{tabular}[t]{l} First line\\ Second line\\ Third line \end{tabular}\right\}$$
Text
\end{enumerate}
\end{document}


Is there any way to tell the inline math to also align to top?

-
why not put the aligned material plus the brace inside the \parbox, instead of the following text? –  barbara beeton Jan 24 at 16:00
Forget the parbox at the end (you can just put 'Text', I agree). If you enclose everything in a \parbox[t], it does not align at top for some reason. –  Alejandro Díaz-Caro Jan 24 at 16:05
Just removed the last parbox to make the question more understandable. –  Alejandro Díaz-Caro Jan 24 at 16:07

\raisebox will do. The height of the contents of \raisebox is available as \height. The tabular environment puts struts with factor \arraystretch in the rows. Since the first line of your tabular only contains normal text, the strut is very likely larger (and probably larger than the extend of the curly brace). Then the argument of \raisbox can be calculated the following way:

\documentclass[a4paper]{article}
\begin{document}
\begin{enumerate}
\item
\raisebox{%
\dimexpr
\arraystretch\dimexpr.7\baselineskip\relax
-\height
\relax
}{%
$$\left.\begin{tabular}{l} First line\\ Second line\\ Third line \end{tabular}\right\}$$
\parbox{0.5\linewidth}{Text}%
}%
\end{enumerate}
\end{document}


-
That is exactly what I was looking for. Thanks! It works really great. –  Alejandro Díaz-Caro Jan 24 at 16:15
I suggest putting a \relax after \dimexpr.7\baselineskip-\height. :-) –  azetina Jan 24 at 16:41
@azetina: One \relax is missing after \baselineskip, and \dimexpr...\relax is missing for the subtraction of \height. It matters if \arraystretch is not 1. –  Heiko Oberdiek Jan 24 at 22:30

I'd define a new environment and use adjustbox for this. The principle is the same as in Heiko's answer.

\documentclass[a4paper]{article}

\NewDocumentEnvironment{bracedrows}{m}
$\kern-\nulldelimiterspace\left. \begin{tabular}{@{}l@{}}} {\end{tabular}\right\rbrace \begin{varwidth}{.5\linewidth}#1\end{varwidth}$%

\begin{document}
\begin{enumerate}
\item \begin{bracedrows}{Text}
First line\\
Second line\\
Third line
\end{bracedrows}

\item \begin{bracedrows}{Text in \\ two lines}
One\\
Two\\
Three
\end{bracedrows}
\end{enumerate}
\end{document}


With varwidth you're sure your side text will occupy only the necessary width.

-
Nice one, specially if I need to use it more than once. –  Alejandro Díaz-Caro Jan 24 at 16:27
@AlejandroDíaz-Caro Defining an environment has other benefits; you can easily change the appearance of your construction in all places by simply redefining the environment. With the proposed syntax, in the document you only type the relevant material and no formatting instruction, which is A Good Thing. –  egreg Jan 24 at 16:43
Sure. In my case I only need it once, but I agree with you. –  Alejandro Díaz-Caro Jan 24 at 20:29
\documentclass[a4paper]{article}
\usepackage{multirow,bigdelim}
\begin{document}
\begin{enumerate}
\item
\begin{tabular}[t]{ll}
First line & \rdelim{\}}{3}{2.5cm}[Text]\\
Second line\\
Third line
\end{tabular}
\item foo
\end{enumerate}
\end{document}


-

1) It replaced the \left. \right\} syntax with the \scaleleftright{.}{}{\}} syntax of the scalerel package (with a maximum width on the scaled brace of 1.5ex); and

2) To lower the \parbox the proper number of lines, it enclosed it in a \Longunderstack from the stackengine package, with the appropriate number of leading \\ marks to skip lines.

\documentclass[a4paper]{article}
\usepackage{scalerel}
\usepackage[usestackEOL]{stackengine}
\begin{document}
\begin{enumerate}
\item
\scaleleftright[1.5ex]{.}{\begin{tabular}[t]{l}
First line\\
Second line\\
Third line
\end{tabular}}{\}}
\Longunderstack{\\ \parbox[t]{0.5\linewidth}{Text}}
\end{enumerate}
\end{document}


EDIT: If you prefer the centered \parbox that egreg introduced, then this also works by changing the \parbox from [t] to [c]:

\documentclass[a4paper]{article}
\usepackage{scalerel}
\usepackage[usestackEOL]{stackengine}
\begin{document}
\begin{enumerate}
\item
\scaleleftright[1.5ex]{.}{\begin{tabular}[t]{l}
First line\\
Second line\\
Third line
\end{tabular}}{\}}
\Longunderstack{\\ \parbox[c]{0.5\linewidth}{Text \\in two lines}}
\end{enumerate}
\end{document}


-

Try using TikZ

\documentclass[a4paper]{article}
\pagestyle{empty}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\begin{enumerate}
\item
\begin{tikzpicture}[baseline=(X.base)]
\node[inner sep=0pt] (X) {
\begin{tabular}[t]{l}
First line\\
Second line\\
Third line
\end{tabular}
};
\draw[decorate,decoration=brace] (X.north east) -- node[right=0.3em] {Text} (X.south east);
\end{tikzpicture}

\large
\item
\begin{tikzpicture}[baseline=(X.base)]
\node[inner sep=0pt] (X) {
\begin{tabular}[t]{l}
First line\\
Second line\\
Third line
\end{tabular}
};
\draw[decorate,decoration=brace] (X.north east) -- node[right=0.3em] {Text} (X.south east);
\end{tikzpicture}

\Large
\item
\begin{tikzpicture}[baseline=(X.base)]
\node[inner sep=0pt] (X) {
\begin{tabular}[t]{l}
First line\\
Second line\\
Third line
\end{tabular}
};
\draw[decorate,decoration=brace] (X.north east) -- node[right=0.3em] {Text} (X.south east);
\end{tikzpicture}

\LARGE
\item
\begin{tikzpicture}[baseline=(X.base)]
\node[inner sep=0pt] (X) {
\begin{tabular}[t]{l}
First line\\
Second line\\
Third line
\end{tabular}
};
\draw[decorate,decoration=brace] (X.north east) -- node[right=0.3em] {Text} (X.south east);
\end{tikzpicture}
\end{enumerate}
\end{document}


-
Nice solution. I prefer the \raisebox solution just because it's simpler (without loading another package). –  Alejandro Díaz-Caro Jan 24 at 16:17