我有一個包含數字及其百分比的表格。由於數字和百分比長度不同,因此它們變得不對齊。下圖說明:
如表所示,我希望數字對齊。請注意,該表比實際表要小得多,只是為了顯示問題。
腳本是:
\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}