# Aligning top row of a table with the item label in a list

I have used the enumerate environment to create a list in which every item contains a table, created using the tabular environment. The first row of each table should be aligned with the item label, (a), (b), etc. This is not the the case if the table starts with an \hline. How can I fix the alignment in such a case?

\documentclass{article}
\usepackage{enumerate}
\begin{document}
\begin{enumerate}[(a)]
\item
\begin{tabular}[t]{|c|c|}
a & b \\  \hline c & d  \\ \hline
\end{tabular}
\item
\begin{tabular}[t]{|c|c|}
\hline e & f \\ \hline g & h \\ \hline
\end{tabular}
\end{enumerate}
\end{document}


I just had to solve this problem, and "The LaTeX Companion" (second edition) has the answer on page 280. The [t] option aligns the tabular to the \hline instead of the baseline of the text. The array package has the command \firsthline which corrects this:

\documentclass{article}
\usepackage{enumerate,array}
\begin{document}
\begin{enumerate}[(a)]
\item
\begin{tabular}[t]{|c|c|}
a & b \\  \hline c & d  \\ \hline
\end{tabular}
\item
\begin{tabular}[t]{|c|c|}
\firsthline e & f \\ \hline g & h \\ \hline
\end{tabular}
\end{enumerate}
\end{document}


This is the result:

i don't know what is the cause of your problem, however work around can be use \fbox instead top/bottom (and vertical outer lines too) table's \hline:

\documentclass{article}
\usepackage{enumerate}
\newcommand\tabbox[1]{\setlength\fboxsep{0pt}\fbox{#1}} % <-- new

\begin{document}
\begin{enumerate}[(a)]
\item
\begin{tabular}[t]{|c|c|}
a & b \\  \hline c & d  \\ \hline
\end{tabular}
\item
\tabbox{\begin{tabular}[t]{c|c} % <-- new
e & f \\ \hline g & h \\
\end{tabular}}
\end{enumerate}
\end{document}


• Elegant workaround, just what I needed! Thanks! Minor remark: since the \fbox creates the outer box, the vertical line specification for the tabular environement can be simplified from {|c|c|} to {c|c}, else the outer vertical lines are printed 'twice' and might look thicker than the other lines (at least on my monitor). – jvd Oct 19 '17 at 8:53
• you have right. better is delete the outer vertical lines. the answer is now corrected accordingly. – Zarko Oct 19 '17 at 9:45