3

How can a tabular environment with a top line be aligned with the surrounding text, so that no space is inserted above the top line of the tabular?

\documentclass{standalone}

\begin{document}

LEFT
\begin{tabular}[t]{ll}
  First
  &
    \begin{tabular}[t]{|l|l|} \hline
      Line & 1 \\ \hline
      Line & 2 \\ \hline
    \end{tabular}

\end{tabular}
RIGHT

\end{document}

I want the top line of the tabular to be upper than what LaTeX is giving me. How can I get it aligned to the top of the surrounding text?

enter image description here

2 Answers 2

3

The first \hline command is causing the trouble. If you remove it, the table is aligned. If you want a horizontal line on top, use the array-package and the \firsthline command.

MWE:

\documentclass{standalone}

\usepackage{array}

\begin{document}

LEFT
\begin{tabular}[t]{ll}
First
&
    \begin{tabular}[t]{|l|l|} \firsthline
    Line & 1 \\ \hline
    Line & 2 \\ \hline
    \end{tabular}

\end{tabular}
RIGHT

\end{document}
1
  • Do you have a way to tweak the tabular environment to fix that hline bug for tabular[t]?
    – user21820
    Commented Oct 4, 2019 at 3:41
3

With {NiceTabular} of nicemtrix, you will have directly the expected output.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

LEFT
\begin{tabular}[t]{ll}
First
&
    \begin{NiceTabular}[t]{|l|l|} \hline
    Line & 1 \\ \hline
    Line & 2 \\ \hline
    \end{NiceTabular}

\end{tabular}
RIGHT

\end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).

Output of the above code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .