3

A top-aligned tabular aligns the baseline of its first row with the base line of the surrounding text. However, when using booktabs' \toprule, the rule is considered the first row and thus aligned with this baseline.

\documentclass{article}

\usepackage{booktabs}

\begin{document}

this is some text
\begin{tabular}[t]{l l}
  o & p \\
  q & r \\
\end{tabular}
this is some text

this is some text
\begin{tabular}[t]{l l}\toprule
  o & p \\
  q & r \\\bottomrule
\end{tabular}
this is some text

\end{document}

MWE output

How can I align the first "real" row of the tabular with a \toprule with the surrounding line?

2 Answers 2

3

You can use {NiceTabular} of nicematrix.

\documentclass{article}
\usepackage{nicematrix}
\usepackage{booktabs}

\begin{document}

this is some text
\begin{tabular}[t]{l l}
  o & p \\
  q & r \\
\end{tabular}
this is some text

this is some text
\begin{NiceTabular}[t]{l l}\toprule
  o & p \\
  q & r \\\bottomrule
\end{NiceTabular}
this is some text

\end{document}

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

Output of the above code

0

One option is to fake the booktabs rules using tcolorbox. The resulting syntax is not as nice as using nicematrix, as suggested in F. Pantigny's answer, but it works after compiling just once. (One could of course write a wrapper environment.)

\documentclass{article}

\usepackage{booktabs}
\usepackage{tcolorbox}

\newtcolorbox{fakebooktabsrules}{
  hbox,
  nobeforeafter,
  tcbox raise base,
  arc=0pt,
  boxrule=\heavyrulewidth,
  leftrule=0pt,
  rightrule=0pt,
  boxsep=0pt,
  top=\belowrulesep,
  bottom=\aboverulesep,
  left=0pt,
  right=0pt,
  colback=white,
  colframe=.,
}

\begin{document}

this is some text
\begin{tabular}[t]{l l}
  o & p \\
  q & r \\
\end{tabular}
this is some text

this is some text
\begin{tabular}[t]{l l}\toprule
  o & p \\
  q & r \\\bottomrule
\end{tabular}
this is some text

this is some text
\begin{fakebooktabsrules}
  \begin{tabular}[t]{l l}
    o & p \\
    q & r \\
  \end{tabular}
\end{fakebooktabsrules}
this is some text

\end{document}

MWE output

You must log in to answer this question.

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