我有一张包含数字及其百分比的表格。由于数字和百分比的长度不同,因此它们变得不对齐。下图说明了这一点:
如表格所示,我希望数字对齐。请注意,此表比实际表小得多,只是为了显示问题。
脚本如下:
\documentclass[10pt]{llncs}
\usepackage{graphicx}
\usepackage{sistyle}
\SIthousandsep{,}
\usepackage{booktabs}
\usepackage{array, makecell}
\usepackage{adjustbox}
\begin{document}
\title{Test}
\maketitle
\begin{table*}[!tp]
\centering
\caption{Summary}
\label{tab:inspection}
\begin{adjustbox}{max width=\textwidth}
\begin{tabular}{lrrr}
\toprule
& \multicolumn{3}{c}{\thead{Row}} \\
\cline{2-4}
& \texttt{Col \#1} & \texttt{Col \#2} & \texttt{Col \#3} \\
\midrule
Feature \#1
& \num{55555} & \num{222222} & \num{1111111} \\
\midrule
\quad Feature \#2
& \num{44444} (22.11\%) & \num{222222} (11.11\%) & \num{1111111} (44.44\%) \\
\midrule
\quad \quad Feature \#3
& \num{44444} (55.55\%) & \num{222222} (33.33\%) & \num{1111111} (22.22\%)\\
\quad \quad \quad Feature \#4
& \num{33333} (55.55\%) & \num{66666} (22.22\%) & \num{1111111} (100\%) \\
\bottomrule
\end{tabular}
\end{adjustbox}
\vspace{-10pt}
\end{table*}
\end{document}
答案1
以下是使用该包的示例siunitx
。我将数字和相应的百分比值分成两列。(由于我没有您使用的 documentclass,因此我用 替换了它article
)。
\documentclass[10pt]{article}
\usepackage{geometry}
\usepackage{siunitx}
\sisetup{group-separator = {,}}
\usepackage{booktabs}
\begin{document}
\begin{table*}[!tp]
\centering
\caption{Summary}
\label{tab:inspection}
\begin{tabular}{l
S[table-format=5]
r
S[table-format=6]
r
S[table-format=7]
r}
\toprule
& \multicolumn{6}{c}{Row} \\
\cmidrule{2-7}
& \multicolumn{2}{c}{\texttt{Col \#1}} & \multicolumn{2}{c}{\texttt{Col \#2}} & \multicolumn{2}{c}{\texttt{Col \#3}} \\
\midrule
Feature \#1
& 55555& & 222222 & & 1111111 \\
\midrule
\quad Feature \#2
& 44444& (22.11\%) & 222222 &(11.11\%) &1111111& (44.44\%) \\
\midrule
\quad \quad Feature \#3
& 44444 &(55.55\%) & 222222 &(33.33\%) & 1111111& (22.22\%)\\
\quad \quad \quad Feature \#4
& 33333& (55.55\%) & 66666& (22.22\%) & 1111111 &(100\%) \\
\bottomrule
\end{tabular}
\end{table*}
\end{document}