代码之家  ›  专栏  ›  技术社区  ›  Mauro Gentile

表格单元格中的右边距与Latex中的右边距对齐

  •  2
  • Mauro Gentile  · 技术社区  · 7 年前

    我有下面的乳胶表 enter image description here

    使用此代码创建:

    \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表格中,我会将列向右对齐,然后在单元格中添加右边距。数字将朝着细胞中心移动,同时保持向右对齐。

    我用乳胶怎么做?如何在右侧添加边距?

    1 回复  |  直到 7 年前
        1
  •  4
  •   Werner RDyego    7 年前

    您可以尝试以下几种选择:

    • 原件:

      enter image description here

    • 多行标题:

      enter image description here

    • 使用手动对齐中心柱 \phantom s:

      enter image description here

    • 使用手动对齐中心柱 \eqmakebox es(来自 eqparbox ):

      enter image description here

    • 使用自动对齐居中柱 siunitx :

      enter image description here

    \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}