# Table inside enumeration: How to align vertically when using booktabs' \toprule?

I want to display a table inside an enumerate environment such that the first row aligns with the item label. My current code is the following:

\documentclass{article}
\usepackage{enumitem}
\usepackage{booktabs}

\setenumerate{listparindent=\parindent, parsep=0pt}

\begin{document}
\begin{enumerate}[align=left, label=\large\sffamily\bfseries \alph*)]
\item
\begin{tabular}[t]{cccc}
\toprule
$m$ & $P(R=a,M=m)$ & $P(R=b,M=m)$ & $P(R=c,M=m)$ \\
\midrule
1 & 0.1 & 0.2 & 0.3 \\
2 & 0.2 & 0.1 & 0.1 \\
\bottomrule
\end{tabular}

\item
$$\displaystyle P(0) = P(0|B) P(B) + P(0|G) P(G)$$
\end{enumerate}
\end{document}


Unfortunately (despite using the t option of the tabular environment), the alignment is not as expected due to the \toprule command. If I remove it, everthing is fine. How may I solve this?

Furthermore, how can I center the table horizontally within the current line? I tried to use a floating table by surrounding it with \begin{table}\end{table}, but this changed the vertical placement even more.

• The issue you're looking to fix isn't really specific to \toprule: It also occurs when the standard LaTeX \hline command is used.
– Mico
Nov 9, 2013 at 17:27

You need to forcefully adjust the first line to align with the label. Below I've introduced ttabular that inserts this vertical adjustment (comprised of a regular baseline skip plus all the rule widths that make up \toprule*). Horizontal centering is obtain using an \hfill<item>\hfill\null approach. You can also use a box of width \linewidth.

\documentclass{article}
\usepackage{enumitem,booktabs}% http://ctan.org/pkg/{enumitem,booktabs}

\setenumerate{listparindent=\parindent, parsep=0pt}

\newenvironment{ttabular}[2][c]
{\begin{tabular}[#1]{#2}
\\[\dimexpr-\normalbaselineskip-\abovetopsep-\belowrulesep-\heavyrulewidth]
}{\end{tabular}}

\begin{document}
\begin{enumerate}[align=left, label=\large\sffamily\bfseries \alph*)]
\item \hfill%
\begin{ttabular}[t]{cccc}
\toprule
$m$ & $P(R=a,M=m)$ & $P(R=b,M=m)$ & $P(R=c,M=m)$ \\
\midrule
1 & 0.1 & 0.2 & 0.3 \\
2 & 0.2 & 0.1 & 0.1 \\
\bottomrule
\end{ttabular}%
\hfill\null%

\item
$$\displaystyle P(0) = P(0|B) P(B) + P(0|G) P(G)$$
\end{enumerate}
\end{document}


Note that the vertical adjustment causes the tabular to rise quite high, which may overlap with contents above it. In that sense, you'll have to make adjustments to accommodate for that as well, if needed.

* One of these lengths \abovetopsep is actually set to 0pt by default.

You can emulate what array does with \firsthline; however, the tabular will most likely clash with the preceding material and you have to add some vertical space anyway:

\documentclass{article}
\usepackage{lipsum} % just for the example
\usepackage{enumitem}
\usepackage{booktabs}

\makeatletter
\newcommand{\firsttoprule}{%
\toprule}
\makeatother

\setlist[enumerate]{listparindent=\parindent, parsep=0pt}

\begin{document}
\lipsum*[2]
\begin{enumerate}[
align=left,
label=\large\sffamily\bfseries\alph*),
before=\vspace{1.5ex}
]
\item
\begin{tabular}[t]{cccc}
\firsttoprule
$m$ & $P(R=a,M=m)$ & $P(R=b,M=m)$ & $P(R=c,M=m)$ \\
\midrule
1 & 0.1 & 0.2 & 0.3 \\
2 & 0.2 & 0.1 & 0.1 \\
\bottomrule
\end{tabular}

\item
$$\displaystyle P(0) = P(0|B) P(B) + P(0|G) P(G)$$
\end{enumerate}
\lipsum[2]
\end{document}


Note that \setenumerate is a deprecated command.

You may also use the adjustbox package by adjusting the vertical alignment:

\documentclass{article}
\usepackage{enumitem}
\usepackage{booktabs}

\setlist[enumerate]{listparindent=\parindent, parsep=0pt} % edited as per @egreg comment

\begin{document}
\begin{enumerate}[align=left, label=\large\sffamily\bfseries \alph*)]
\item
\makebox[\linewidth]{       % Causes the centering
\begin{tabular}{cccc}
%\noalign{\vskip-.85ex}      % Uncomment to see the second output
\toprule
$m$ & $P(R=a,M=m)$ & $P(R=b,M=m)$ & $P(R=c,M=m)$ \\
\midrule
1 & 0.1 & 0.2 & 0.3 \\
2 & 0.2 & 0.1 & 0.1 \\
\bottomrule
\end{tabular}}
$$\displaystyle P(0) = P(0|B) P(B) + P(0|G) P(G)$$

• Thanks, I didn't know the adjustbox package before. I picked Werner's answer, though, because I wanted the text of the first row to be on the same baseline as the item label. Your answer might still be helpful in similar cases, so +1. ;) Nov 9, 2013 at 18:35