顶部对齐tabular
将其第一行的基线与周围文本的基线对齐。但是,当使用booktabs
'时\toprule
,该规则被视为第一行,因此与此基线对齐。
\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}
我怎样才能将的第一个“真实”行tabular
与\toprule
周围的线对齐?
答案1
您可以{NiceTabular}
使用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}
您需要多次编译(因为nicematrix
在后台使用 PGF/Tikz 节点)。
答案2
booktabs
一种选择是使用 来伪造规则tcolorbox
。结果语法不如使用 好nicematrix
,如F. Pantigny 的回答,但只需编译一次即可。(当然可以编写包装器环境。)
\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}