使用 exp.siunitx 在 tabularx 中进行对齐

使用 exp.siunitx 在 tabularx 中进行对齐

这是一个永无止境的故事 ->上一篇。简单来说,我只想对齐“pm”符号我的数字列。我已经尝试{l | l *{2}{>{\centering\arraybackslash}X}}用替换标题{l | l l l *{2}{>{\centering\arraybackslash}X},然后用 siunitx: 检查一列,{l | l S[table-align-uncertainty, separate-uncertainty=true] l l *{2}{>{\centering\arraybackslash}X}但它根本不起作用。

梅威瑟:

\documentclass{article}
\usepackage{float, enumitem, amsmath}
\usepackage{rotating}  
\usepackage{booktabs, makecell, multirow, tabularx, threeparttable}
\renewcommand\theadfont{\small\bfseries}
\renewcommand\theadgape{} 
\usepackage{colortbl, color} %I preffer that instead of xcolor because xcolor give me errors with beamer
\usepackage{caption}
\captionsetup{belowskip=-5pt}
\captionsetup[table]{justification=raggedright,singlelinecheck=off}

\begin{document}

   \begin{table} 
    \centering
    \settowidth\rotheadsize{\theadfont Description 3 }
    \renewcommand\arraystretch{1.1}
\caption{Simple caption.}
\label{tab:setTag}
\begin{tabularx}{\linewidth}{l | l *{2}{>{\centering\arraybackslash}X}}
    \Xhline{1pt}
    & \thead[l]{Results} 
        & \thead{Method 1} & \thead{Method 2}           \\
    \Xhline{0.7pt}
    &   & \multicolumn{2}{c}{First section}             \\ 
    \Xcline{3-4}{0.6pt}
\multirow{3}{*}{\rothead{Description 1}}
    &Very long name & $11,5 \pm 0,5$ & $444,34 \pm 71,9$ \\
    & Very long name & $109,2 \pm 75,3$ & $2,8 \pm 664,36$ \\
    & Very long name& $9438 \pm 8$ & $256,0 \pm 98,1$ \\
    & Very long name & $11,5 \pm 0,5$ & $444,34 \pm 71,9$ \\
    & Very long name & $109,2 \pm 75,3$ & $2,8 \pm 664,36$ \\
    & Very long name & $9438 \pm 8$ & $256,0 \pm 98,1$ \\
    \end{tabularx}
    \end{table}
\end{document}

在此处输入图片描述


我已将标题更改为\begin{tabularx}{\linewidth}{l | X S[table-align-uncertainty, separate-uncertainty=true] S[table-align-uncertainty, separate-uncertainty=true]*{2}{>{\centering\arraybackslash}}}并将数据从第一行更改为11,5(5) & 444,34(719并得到该结果(奇怪的方法标题):

在此处输入图片描述


我现在遇到了错误数组包‘>{}’处于错误位置。有人能告诉我哪一个是正确的吗?另一个‘对齐前言中缺少 # 插入’第三个‘缺少 $ 插入’但我不知道为什么,因为它显示带有\end{tabularx}

代码的新部分:

\begin{tabularx}{\linewidth}{l | X S[table-align-uncertainty, separate-uncertainty=true] S[table-align-uncertainty, separate-uncertainty=true]*{2}{>{\centering\arraybackslash}}}
    \Xhline{1pt}
    & \thead[l]{Results} 
        & {\thead{Method 1}} & {\thead{Method 2}}           \\
    \Xhline{0.7pt}
    &   & \multicolumn{2}{c}{First section}             \\ 
    \Xcline{3-4}{0.6pt}
\multirow{3}{*}{\rothead{Description 1}}
    &Very long name & $11,5(5)$ & $444,34(719)$ \\
    & Very long name & $109,2(753)$ & $2,8(63)$ \\
    & Very long name& $9438(8)$ & $256,0(981)$ \\
    &Very long name & $11,5(5)$ & $444,34(719)$ \\
    & Very long name & $109,2(753)$ & $2,8(63)$ \\
    & Very long name& $9438(8)$ & $256,0(981)$ \\
    \end{tabularx}

它显示(显然不对齐):

在此处输入图片描述


在此处输入图片描述

答案1

以下应该有效:

\documentclass{article}
\usepackage{float, enumitem, amsmath}
\usepackage{rotating}  
\usepackage{booktabs, makecell, multirow, tabularx, threeparttable}
\renewcommand\theadfont{\small\bfseries}
\renewcommand\theadgape{} 
\usepackage{colortbl, color} %I preffer that instead of xcolor because xcolor give me errors with beamer

\usepackage{caption}
\captionsetup{belowskip=-5pt}
\captionsetup[table]{justification=raggedright,singlelinecheck=off}

\usepackage{siunitx}
\begin{document}

\sisetup{table-align-uncertainty, separate-uncertainty=true}
\begin{tabularx}{\linewidth}{l | X S[table-format=4.1(3)] S[table-format=3.2(5)]}
    \Xhline{1pt}
    & \thead[l]{Results} 
        & {\thead{Method 1}} & {\thead{Method 2}}           \\
    \Xhline{0.7pt}
    &   & \multicolumn{2}{c}{First section}             \\ 
    \Xcline{3-4}{0.6pt}
\multirow{3}{*}{\rothead{Description 1}}
    & Very long name & 11,5(5)    & 444,34(7190) \\
    & Very long name & 109,2(753) & 2,80(66436)  \\
    & Very long name & 9438(8)    & 256,0(981)   \\
    & Very long name & 11,5(5)    & 444,34(7190) \\
    & Very long name & 109,2(753) & 2,80(66436)  \\
    & Very long name & 9438(8)    & 256,0(981)   \\
    \end{tabularx}
\end{document}

答案2

只是回答你在 leandriis 答案下的评论,你可以直接旋转文本,不需要多行,也正如我之前在聊天中评论的那样,我永远不会使用 tabularx 来制作这样的数据表,tabularx 是关于表格的文本以及列中的换行。

在此处输入图片描述

\documentclass{article}
\usepackage{float, enumitem, amsmath}
\usepackage{rotating}  
\usepackage{booktabs, makecell, multirow, tabularx, threeparttable}
\renewcommand\theadfont{\small\bfseries}
\renewcommand\theadgape{} 
\usepackage{colortbl, color} %I preffer that instead of xcolor because xcolor give me errors with beamer

\usepackage{caption}
\captionsetup{belowskip=-5pt}
\captionsetup[table]{justification=raggedright,singlelinecheck=off}

\usepackage{siunitx}
\begin{document}

\sisetup{table-align-uncertainty, separate-uncertainty=true}
\centering
\begin{tabular}{l | l S[table-format=4.1(3)] S[table-format=3.2(5)]}
    \Xhline{1pt}
    & \thead[l]{Results} 
        & {\thead{Method 1}} & {\thead{Method 2}}           \\
    \Xhline{0.7pt}
\smash{\rotatebox[origin=r]{90}{\bfseries Description 1}}
    &   & \multicolumn{2}{c}{First section}             \\ 
    \Xcline{3-4}{0.6pt}
    & Very long name & 11,5(5)    & 444,34(7190) \\
    & Very long name & 109,2(753) & 2,80(66436)  \\
    & Very long name & 9438(8)    & 256,0(981)   \\
    & Very long name & 11,5(5)    & 444,34(7190) \\
    & Very long name & 109,2(753) & 2,80(66436)  \\
    & Very long name & 9438(8)    & 256,0(981)   \\
    \end{tabular}
\end{document}

相关内容