table 单元格的右边距在 Latex 中右对齐
Right margin in table cells aligned to the right in Latex
我在 Latex
中有以下 table
使用此代码创建:
\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}
我想让第三列百分比右对齐
同时列标签太大。如果我将列向右对齐,它看起来会很奇怪。
简而言之 table 我会将列右对齐,然后为单元格添加右边距。这些数字将向单元格中心移动,同时保持它们向右对齐。
我如何在 Latex 中做到这一点?如何在右侧添加边距?
您可以尝试多种选择:
原文:
Multi-row header:
使用 \phantom
s 手动居中列对齐:
使用 \eqmakebox
es(来自 eqparbox
)手动居中列对齐:
使用 siunitx
:
自动对齐列居中
\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}
我在 Latex
使用此代码创建:
\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}
我想让第三列百分比右对齐 同时列标签太大。如果我将列向右对齐,它看起来会很奇怪。
简而言之 table 我会将列右对齐,然后为单元格添加右边距。这些数字将向单元格中心移动,同时保持它们向右对齐。
我如何在 Latex 中做到这一点?如何在右侧添加边距?
您可以尝试多种选择:
原文:
Multi-row header:
使用
\phantom
s 手动居中列对齐:使用
\eqmakebox
es(来自eqparbox
)手动居中列对齐:使用
自动对齐列居中siunitx
:
\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}