【问题标题】:Right margin in table cells aligned to the right in Latex表格单元格中的右边距在 Latex 中向右对齐
【发布时间】:2018-06-16 22:28:59
【问题描述】:

我在 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}

我想让第三列百分比右对齐 同时列标签过大。如果我将列向右对齐,它会在视觉上很奇怪。

在 Word 表格中,我会将列向右对齐,然后为单元格添加右边距。数字将向单元格中心移动,同时保持向右对齐。

我如何在 Latex 中做到这一点?如何在右侧添加边距?

【问题讨论】:

    标签: latex tabular


    【解决方案1】:

    您可以尝试多种选择:

    • 原文:

    • 多行标题:

    • 使用\phantoms 手动对齐居中列:

    • 使用\eqmakeboxes(来自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}
    

    【讨论】:

      猜你喜欢
      • 2013-12-08
      • 1970-01-01
      • 1970-01-01
      • 2019-06-09
      • 1970-01-01
      • 2015-01-03
      • 2019-02-04
      • 2018-04-19
      • 2014-09-20
      相关资源
      最近更新 更多