
我使用以下程式碼建立了一個表:
\begin{tabular}{p{3cm}|p{3cm}|p{3cm}}
Symbol & Units & Quantity \\
\hline \hline
$A$ & m$^2$ & Area \\
$a$ & m^{2}/s & Acceleration \\
$F$ & N & Force \\
$l$ & m & Length \\
$u$ & m/s & Velocity
\end{tabular}
其輸出為:
可以看出,垂直線不是連續的,即,當垂直線與水平線相遇時存在間隙,並且在第二條水平線之後垂直線再次變得連續。
我不希望垂直線上有間隙。我想要如下圖的東西:
有人可以告訴我應該在程式碼中進行哪些更改才能達到預期的結果嗎?
答案1
要獲得所需的連續垂直線,您可以使用包裝\hhline{=|=|=}
中的hhline
產品。在下面的範例中,我還使用了siunitx
單位包。
在下面的內容中,我添加了該表的三個版本。在第一個中我剛剛添加了\hhline
和siunitx
。在這裡,指數接觸水平線。為了防止這種情況,我添加了第二個表,其中我還使用了cellspace
套件來填充單元格周圍的一些空白區域。然而,就我個人而言,我更喜歡一個更緊湊的桌子,沒有包裝的垂直線和水平線booktabs
。第三個表中顯示了一個範例:
\documentclass{article}
\usepackage{hhline}
\usepackage{siunitx}
\sisetup{per-mode=symbol}
\usepackage[column=0]{cellspace}
\setlength\cellspacetoplimit{3pt}
\setlength\cellspacebottomlimit{\cellspacetoplimit}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{p{3cm}|p{3cm}|p{3cm}}
Symbol & Units & Quantity \\
\hhline{=|=|=}
$A$ & \si{\m\squared} & Area \\
$a$ & \si{\m\squared\per\s} & Acceleration \\
$F$ & \si{\N} & Force \\
$l$ & \si{\m} & Length \\
$u$ & \si{\m\per\s} & Velocity
\end{tabular}
\bigskip
\begin{tabular}{0{p{3cm}}|0{p{3cm}}|0{p{3cm}}}
Symbol & Units & Quantity \\
\hhline{=|=|=}
$A$ & \si{\m\squared} & Area \\
$a$ & \si{\m\squared\per\s} & Acceleration \\
$F$ & \si{\N} & Force \\
$l$ & \si{\m} & Length \\
$u$ & \si{\m\per\s} & Velocity
\end{tabular}
\bigskip
\begin{tabular}{lll}
\toprule
Symbol & Units & Quantity \\
\midrule
$A$ & \si{\m\squared} & Area \\
$a$ & \si{\m\squared\per\s} & Acceleration \\
$F$ & \si{\N} & Force \\
$l$ & \si{\m} & Length \\
$u$ & \si{\m\per\s} & Velocity \\
\bottomrule
\end{tabular}
\end{document}
答案2
使用{NiceTabular}
of nicematrix
,您可以直接獲得預期的輸出(但是,使用 的表設計booktabs
可能會更好)。
\documentclass{article}
\usepackage{nicematrix}
\begin{document}
\begin{NiceTabular}{p{3cm}|p{3cm}|p{3cm}}[cell-space-top-limit=2pt]
Symbol & Units & Quantity \\
\hline \hline
$A$ & m$^2$ & Area \\
$a$ & m$^{2}$/s & Acceleration \\
$F$ & N & Force \\
$l$ & m & Length \\
$u$ & m/s & Velocity
\end{NiceTabular}
\end{document}
您需要多次編譯(因為nicematrix
在背景使用 PGF/Tikz 節點)。