使用以下代码创建:
\begin{table}[h]
\caption{aaaa}
\label{tab:treatments}
\centering
\scalebox{0.8}{
\begin{tabular}{l c c c}
\toprule
\tabhead{Por 1} & \tabhead{Por 3} & \tabhead{Quantificazione log-dim} & \tabhead{cintin\'a} \\
\midrule
A & M & 99.3\%& 5.4\\
B& A & 2.0\%& 4.6\\
C & N & 5.8\% & 4.6\\
D & N & 3.5\% & 4.26\\
E & K & 22.5\% & 3.7\\
\bottomrule\\
\end{tabular}
}
\end{table}
我希望第三列百分比与右边对齐 同时列标签太大。如果我将列向右对齐,它会在视觉上很奇怪。
在Word表格中,我会将列对齐,然后向单元格添加右边距。数字将向细胞中心移动,同时保持它们与右侧的对齐。
我如何在Latex中做到这一点?如何在右侧添加保证金?
答案 0 :(得分:3)
您可以尝试多种选择:
\documentclass{article}
\usepackage{booktabs,graphicx,makecell,siunitx,eqparbox}
\newcommand{\tabhead}{\textbf}
\begin{document}
Original:
\begin{tabular}{ l c c c }
\toprule
\tabhead{Por 1} & \tabhead{Por 3} & \tabhead{Quantificazione log-dim} & \tabhead{cintin\'a} \\
\midrule
A & M & 99.3\% & 5.4 \\
B & A & 2.0\% & 4.6 \\
C & N & 5.8\% & 4.6 \\
D & N & 3.5\% & 4.26 \\
E & K & 22.5\% & 3.7 \\
\bottomrule
\end{tabular}
\bigskip
Multi-row header:
\begin{tabular}{ l c c c }
\toprule
\tabhead{Por 1} & \tabhead{Por 3} & \tabhead{\makecell[b]{Quantificazione \\ log-dim}} & \tabhead{cintin\'a} \\
\midrule
A & M & 99.3\% & 5.4 \\
B & A & 2.0\% & 4.6 \\
C & N & 5.8\% & 4.6 \\
D & N & 3.5\% & 4.26 \\
E & K & 22.5\% & 3.7 \\
\bottomrule
\end{tabular}
\bigskip
Manual alignment of centred columns using \verb|\phantom|s:
\begin{tabular}{ l c c c }
\toprule
\tabhead{Por 1} & \tabhead{Por 3} & \tabhead{\makecell[b]{Quantificazione \\ log-dim}} & \tabhead{cintin\'a} \\
\midrule
A & M & 99.3\% & 5.4\phantom{0} \\
B & A & \phantom{0}2.0\% & 4.6\phantom{0} \\
C & N & \phantom{0}5.8\% & 4.6\phantom{0} \\
D & N & \phantom{0}3.5\% & 4.26 \\
E & K & 22.5\% & 3.7\phantom{0} \\
\bottomrule
\end{tabular}
\bigskip
Manual alignment of centred columns using \verb|\eqmakebox|es:
\begin{tabular}{ l c c c }
\toprule
\tabhead{Por 1} & \tabhead{Por 3} & \tabhead{\makecell[b]{Quantificazione \\ log-dim}} & \tabhead{cintin\'a} \\
\midrule
A & M & \eqmakebox[log][r]{99.3\%} & \eqmakebox[cint][l]{5.4} \\
B & A & \eqmakebox[log][r]{ 2.0\%} & \eqmakebox[cint][l]{4.6} \\
C & N & \eqmakebox[log][r]{ 5.8\%} & \eqmakebox[cint][l]{4.6} \\
D & N & \eqmakebox[log][r]{ 3.5\%} & \eqmakebox[cint][l]{4.26} \\
E & K & \eqmakebox[log][r]{22.5\%} & \eqmakebox[cint][l]{3.7} \\
\bottomrule
\end{tabular}
\newpage
Automated alignment of centred columns using \verb|siunitx|:
\begin{tabular}{ l c S[table-format = 2.1, table-space-text-post = \%] S[table-format = 1.2] }
\toprule
\tabhead{Por 1} & \tabhead{Por 3} & \tabhead{\makecell[b]{Quantificazione \\ log-dim}} & \tabhead{cintin\'a} \\
\midrule
A & M & 99.3\% & 5.4 \\
B & A & 2.0\% & 4.6 \\
C & N & 5.8\% & 4.6 \\
D & N & 3.5\% & 4.26 \\
E & K & 22.5\% & 3.7 \\
\bottomrule
\end{tabular}
\end{document}