
他にも似たような質問がいくつかあり、それぞれ答えが異なりますが、私が求めている答えが見つかりませんでした。下の表では、数字の間隔が広すぎます。これを少し狭めるにはどうしたらよいでしょうか。
\newcommand{\testmode}[2] {
\begin{tabular}{c}
\textbf{#1} \\ \textbf{d=#2}
\end{tabular}
}
\begin{table}[ht]
\begin{tabular}{l | c c c | c c c |}
\cline{2-7}
& \multicolumn{3}{c|}{\textbf{Single}} & \multicolumn{3}{c|}{\textbf{Double}} \\
\cline{2-7}
& \testmode{Scalar}{1} & \testmode{SSE-4}{4} & \testmode{AVX-2}{8} & \testmode{Scalar}{1} & \testmode{SSE-4}{2} & \testmode{AVX-2}{4} \\
\hline
\multicolumn{1}{|c|}{\textbf{Eytzinger} } & 209.86 & 370.18 & 411.25 & 180.85 & 245.37 & 262.61 \\
\multicolumn{1}{|c|}{\textbf{Classic Offset} } & 213.28 & 363.35 & 476.10 & 209.04 & 247.02 & 208.63 \\
\hline
\end{tabular}
\caption{Throughput in millions of searches per second with vector $X$ of size 15}
\label{tab:results0}
\end{table}
答え1
tabular
この例では、 a の中にa を使用して列tabular
の区切りを 2 倍にしています。注意: LaTeX は各列の前後に距離を追加します\tabcolsep
。あなたの場合、内側の表の列の前後に の距離があり\testmode
、外側の表の列の前後に の距離があります。これを回避するには、@{}
内側の表の最初の列の前に を追加し、内側の表の最後の列の後に を追加する必要があります。
\documentclass{article}
\begin{document}
\newcommand{\testmode}[2] {%
\begin{tabular}{@{}c@{}}% Avoid doubling \tabcolsep
\textbf{#1} \\ \textbf{d=#2}
\end{tabular}%
}
\begin{table}[ht]
\begin{tabular}{l | c c c | c c c |}
\cline{2-7}
& \multicolumn{3}{c|}{\textbf{Single}} & \multicolumn{3}{c|}{\textbf{Double}} \\
\cline{2-7}
& \testmode{Scalar}{1} & \testmode{SSE-4}{4} & \testmode{AVX-2}{8} & \testmode{Scalar}{1} & \testmode{SSE-4}{2} & \testmode{AVX-2}{4} \\
\hline
\multicolumn{1}{|c|}{\textbf{Eytzinger} } & 209.86 & 370.18 & 411.25 & 180.85 & 245.37 & 262.61 \\
\multicolumn{1}{|c|}{\textbf{Classic Offset} } & 213.28 & 363.35 & 476.10 & 209.04 & 247.02 & 208.63 \\
\hline
\end{tabular}
\caption{Throughput in millions of searches per second with vector $X$ of size 15}
\label{tab:results0}
\end{table}
\end{document}
さらに詳しく説明すると、LaTeXはデフォルトで\hskip\tabcolsep
列の開始前と終了後に距離を追加します。つまり、\tabcolsep
最初の列の前と最後の列の後、および2つの列の間の距離がわかります。引数のコード2\tabcolsep
を使用すると、@{…}
@
距離の代わりに@{}
距離をなくすだけです。
追加メモ:表の縦線は避けることをお勧めします(マニュアルを参照してください)パッケージbooktabs
)を使用してパッケージsiunitx
数値列の場合。また、最初の表行の要素を中央揃えにせず、左揃えにします。また、d=…
表の見出しは数式のようなものなので、数式モードで設定する必要があります。この場合、太字にすることもしません (たとえば、 を使用\boldmath
)。これは、数式のフォント属性は主に意味を持つためです (たとえば、太字はベクトルやセットによく使用されます)。
答え2
これをどこで見つけたかは覚えていませんが (参照付きの編集は大歓迎です)、ステートメントの直前に次のコードを追加すると\begin{tabular}
、列間隔を指定した値で調整できるようになります。
\addtolength{\tabcolsep}{-0.4em}
ここでは任意の単位を使用できますが、上記の例ではem
、現在のフォント サイズを基準とする を使用しています。
答え3
5年後…
tabularray
列の分離を定義するためのオプションを定義するテーブル パッケージが利用可能になりましたcolsep
。「クラシック」テーブルと比較すると、コードは短くなり、セル内のテキストの垂直間隔が改善されます。
\documentclass{article}
\usepackage{tabularray}
\begin{document}
\begin{table}[ht]
\begin{tblr}{hline{4,Z} = {0.8pt}, vline{1} = {4-Z}{solid},
colsep = {4pt}, % <--- reduce tabcolsep from 6pt to 4pt
colspec = {Q[l, font=\bfseries] | *{3}{X[c]} | *{3}{X[c]} |},
row{1-3} = {font=\bfseries}
}
\cline[0.8pt]{2-Z}
& \SetCell[c=3]{c} Single
& & & \SetCell[c=3]{c} Double
& & \\
\cline{2-7}
& Scalar & SSE-4 & AVX-2 & Scalar & SSE-4 & AVX \\
& D=1 & D=4 & D=8 & D=1 & D=4 & D=8 \\
Eytzinger
&209.86 &370.18 &411.25 & 180.85 & 245.37 & 262.61 \\
Classic Offset
&213.28 &363.35 &476.10 & 209.04 & 247.02 & 208.63 \\
\end{tblr}
\caption{Throughput in millions of searches per second with vector $X$ of size 15}
\label{tab:results0}
\end{table}
\end{document}
答え4
{NiceTabular}
of を使用して表形式でそれを実行する方法は次のとおりですnicematrix
。
\documentclass{article}
\usepackage{nicematrix}
\begin{document}
\begin{table}[ht]
\setlength{\tabcolsep}{4pt}
\renewcommand{\arraystretch}{1.4}
\begin{NiceTabular}{>{\bfseries}l*{6}{X[c]}}[hvlines,corners=NW]
\RowStyle[bold,nb-rows=3]{}
& \Block{1-3}{Single}
& & & \Block{1-3}{Double} \\
& Scalar & SSE-4 & AVX-2 & Scalar & SSE-4 & AVX \\
& D=1 & D=4 & D=8 & D=1 & D=4 & D=8 \\
Eytzinger
&209.86 &370.18 &411.25 & 180.85 & 245.37 & 262.61 \\
Classic Offset
&213.28 &363.35 &476.10 & 209.04 & 247.02 & 208.63 \\
\end{NiceTabular}
\caption{Throughput in millions of searches per second with vector $X$ of size 15}
\label{tab:results0}
\end{table}
\end{document}
複数のコンパイルが必要です (nicematrix
内部で PGF/Tikz ノードが使用されるため)。