
テーブルを作成するために次のコードを使用しました。
\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}
出力は次のようになります。
ご覧のとおり、垂直線は連続していません。つまり、垂直線が水平線と交わる部分に隙間があり、2 番目の水平線以降は再び垂直線が連続します。
縦線に隙間がないようにしたいです。次の図のような形にしたいです。
望ましい結果を得るためにコードにどのような変更を加えるべきか教えていただけますか?
答え1
\hhline{=|=|=}
必要な連続した垂直線を取得するには、パッケージから を使用できますhhline
。次の例では、siunitx
単位にもパッケージを使用しています。
次の mwe では、表の 3 つのバージョンを追加しました。最初のバージョンでは、\hhline
とを追加しましたsiunitx
。ここでは、指数が水平線に触れています。これを防ぐために、cellspace
セルの周囲に空白を追加するためにパッケージを使用した 2 番目の表を追加しました。ただし、個人的には、パッケージの垂直線と水平線のない、よりコンパクトな表を好みますbooktabs
。その例を 3 番目の表に示します。
\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}
を使用すると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 ノードが使用されるため)。