siunitx 与标题和分隔符居中对齐

siunitx 与标题和分隔符居中对齐

我有几个比较宽的表格,我觉得用word很难统一,也很难清晰的显示,所以我试着学习latex来做这个表格,但是遇到了不少问题。

Q1 加减号没有与列标题(湿或干)居中对齐。

Q2 列标题平均值 \pm SD\textsubscript{n}无法正确显示,并出现一些错误警告,并且与下面的数据对齐不正确

Q3 如何让所有 S 列具有相同的列宽,即使该列没有任何数据,例如F 区,季节干燥在这个例子中

\documentclass{article}

\usepackage{array}
\usepackage{tabularx}
\usepackage[singlelinecheck=false]{caption}
\usepackage{changepage}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\usepackage[a4paper,top=0.05cm,bottom=0.05cm,left=0.1cm,right=0.1cm,marginparwidth=0.1cm, landscape, total ={210mm,297mm}]{geometry}
\usepackage{rotating}
\usepackage{caption}
\usepackage{array}
\usepackage{booktabs}
\usepackage{pdflscape}
\usepackage{multirow}
\usepackage[separate-uncertainty=true]{siunitx}

\sisetup{
    table-number-alignment=center,
    separate-uncertainty=true,
    table-figures-integer = 2,
    table-figures-decimal = 2}

\begin{document}
    \begin{landscape}
        \begin{sidewaystable}
            \centering
            \caption{Test}
            \tiny
            \begin{tabular}{lc*{12}{S[separate-uncertainty,
                        table-figures-uncertainty=1]@{\hspace{1cm}}}}
                    \toprule
                    & Site  & \multicolumn{2}{c}{A} & \multicolumn{2}{c}{B} & \multicolumn{2}{c}{C} & \multicolumn{2}{c}{D} & \multicolumn{2}{c}{E} & \multicolumn{2}{c}{F} \\
                    \multicolumn{1}{c}{Species}      & Season &\multicolumn{1}{c}{Wet}   & \multicolumn{1}{c}{Dry}   & \multicolumn{1}{c}{Wet}   & \multicolumn{1}{c}{Dry}   & \multicolumn{1}{c}{Wet}   & \multicolumn{1}{c}{Dry}   & \multicolumn{1}{c}{Wet}   & \multicolumn{1}{c}{Dry}   & \multicolumn{1}{c}{Wet}   & \multicolumn{1}{c}{Dry}   & \multicolumn{1}{c}{Wet}   & \multicolumn{1}{c}{Dry} \\
                    \midrule
                    & Tracer & Mean \pm SD\textsubscript{n}
                    & & & & & & & & & & & \\
                    \midrule
                    \multirow{2}{*}{\shortstack{\textit{Genus A}\\ \textit{\indent{Species A}}}} & N     &       &       &       &       &       & 81.82\pm0.36\textsubscript{(4)} &       &       &93.83\pm0.99\textsubscript{(8)} &14.25\pm0.49\textsubscript{(2)} &54.6\pm0.23\textsubscript{(4)} &  \\
                    & C     &       &       &       &       &       & -19.73\pm0.29\textsubscript{(4)} &       &       &-26.62\pm0.27\textsubscript{(8)} &-57.3\pm0.14\textsubscript{(2)} &-36.65\pm0.31\textsubscript{(4)} &  \\

                    \multirow{2}{*}{\shortstack{\textit{Genus B}\\ \textit{\indent{Species B}}}}& N     &15.14\pm1.21\textsubscript{(16)} &13.1\pm1.2\textsubscript{(18)} &13.7\pm0.85\textsubscript{(16)} &12.55\pm0.84\textsubscript{(16)} & 12.32\pm0.64\textsubscript{(15)} & 12.27\pm0.47\textsubscript{(16)} & 12.28\pm0.59\textsubscript{(16)} & 12.61\pm0.29\textsubscript{(10)} &23.43\pm0.4\textsubscript{(16)} &14.06\pm0.28\textsubscript{(15)} &14\pm0.82\textsubscript{(5)} &  \\
                    & C     &-18.38\pm0.64\textsubscript{(16)} &-17.25\pm0.44\textsubscript{(18)} &-16.66\pm0.39\textsubscript{(16)} &-16.67\pm0.59\textsubscript{(16)} & -16.77\pm0.3\textsubscript{(15)} & -15.98\pm0.37\textsubscript{(16)} & -16.59\pm0.38\textsubscript{(16)} & -16.05\pm0.22\textsubscript{(10)} &-16.6\pm0.3\textsubscript{(16)} &-16.06\pm0.36\textsubscript{(15)} &-15.72\pm0.45\textsubscript{(5)} &  \\
                            \end{tabular}
                \end{sidewaystable}
            \end{landscape}
    \end{document}

我已经搜索了很长时间来解决这个问题,但仍然没有成功。任何帮助都将不胜感激。提前谢谢您!

答案1

\tabcolsep这里有两种可能性:如果你使用中的值,你可以将表格放在横向 A4 纸上,并使用你选择的最小边距,\footnotesize这会使其比 更具可读性\tiny。我还使用了更简单的语法来siunitx表示不确定性。

但是,我建议采用第二种解决方案,将样本大小放在单独的一行中。使用这种布局,我们可以获得更大的字体tabcolsep大小\small。下面,您可以比较结果。

\documentclass{article}

\usepackage{array}
\usepackage{tabularx}
\usepackage[singlelinecheck=false]{caption}
\usepackage{changepage}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\usepackage[a4paper, vmargin=0.05cm, hmargin=0.1cm, marginparwidth=0.1cm,total={210mm,297mm}, showframe]{geometry}
\usepackage{rotating}
\usepackage{caption}
\usepackage{array}
\usepackage{booktabs}
\usepackage{pdflscape}
\usepackage{multirow, makecell, xcolor}
\usepackage[separate-uncertainty=true]{siunitx}

\begin{document}

  %\begin{landscape}
    \begin{sidewaystable}
    % \begin{table}
            \centering
            \sisetup{
    table-number-alignment=center,
    separate-uncertainty=true,%
    table-format =-2.2,
    separate-uncertainty,
    table-figures-uncertainty=1, table-space-text-post=(16)}
            \caption{Test}
            \footnotesize
    \setlength{\tabcolsep}{2.3pt}
            \begin{tabular}{>{\itshape}l@{}c*{12}{S}@{}}%
                    \toprule
                    & \multirowcell{2}{Site\\ Season} & \multicolumn{2}{c}{A} & \multicolumn{2}{c}{B} & \multicolumn{2}{c}{C} & \multicolumn{2}{c}{D} & \multicolumn{2}{c}{E} & \multicolumn{2}{c}{F} \\
                    \multicolumn{1}{c}{\textrm{Species}} & & {Wet} &{Dry} & {Wet} & {Dry} & {Wet} & {Dry} & {Wet} & {Dry} & {Wet} & {Dry} & {Wet} & {Dry} \\
                    \midrule
                    & Tracer & {Mean $ ±$ SD\textsubscript{n}}
                    & & & & & & & & & & & \\
                    \midrule
                    \multirowcell{2}{Genus A \\ Species A} & N & & & & & & 81.82 (36)\textsubscript{(4)} & & &93.83(99)\textsubscript{(8)} &14.25\pm0.49\textsubscript{(2)} &54.6\pm0.23\textsubscript{(4)} & \\
                    & C & & & & & & -19.73(29)\textsubscript{(4)} & & &-26.62(27)\textsubscript{(8)} &-57.3(14)\textsubscript{(2)} &-36.65(31)\textsubscript{(4)} & \\
                    \addlinespace
                    \multirowcell{2}{Genus B \\ Species B}& N &15.14\pm1.21\textsubscript{(16)} &13.1\pm1.2\textsubscript{(18)} &13.70 (85)\textsubscript{(16)} &12.55(84)\textsubscript{(16)} & 12.32 (64)\textsubscript{(15)} & 12.27\pm0.47\textsubscript{(16)} & 12.28\pm0.59\textsubscript{(16)} & 12.61\pm0.29\textsubscript{(10)} &23.43(40)\textsubscript{(16)} &14.0 (28)\textsubscript{(15)} &14.00(82)\textsubscript{(5)} & \\
                    & C &-18.38 (64)\textsubscript{(16)} &-17.25 (44)\textsubscript{(18)} &-16.66 (39)\textsubscript{(16)} &-16.6 (59)\textsubscript{(16)} & -16.77 (30)\textsubscript{(15)} & -15.98 (37)\textsubscript{(16)} & -16.59 (38)\textsubscript{(16)} & -16.05 (22)\textsubscript{(10)} &-16.6 (3)\textsubscript{(16)} &-16.06 (36)\textsubscript{(15)} &-15.72 (45)\textsubscript{(5)} & \\
                            \end{tabular}
       %\end{table}
       \end{sidewaystable}
    % \end{landscape}

    \begin{sidewaystable}
    % \begin{table}
            \centering
            \sisetup{
    table-number-alignment=center,
    separate-uncertainty=true,%
    table-format =-2.2,
    separate-uncertainty,
    table-figures-uncertainty=1}
            \caption{Test}
            \small
    \setlength{\tabcolsep}{4pt}
            \begin{tabular}{>{\itshape}l@{}c*{12}{S}@{}}%
                    \toprule
                    & \multirowcell{2}{Site\\ Season} & \multicolumn{2}{c}{A} & \multicolumn{2}{c}{B} & \multicolumn{2}{c}{C} & \multicolumn{2}{c}{D} & \multicolumn{2}{c}{E} & \multicolumn{2}{c}{F} \\
                    \multicolumn{1}{c}{\textrm{Species}} & & {Wet} &{Dry} & {Wet} & {Dry} & {Wet} & {Dry} & {Wet} & {Dry} & {Wet} & {Dry} & {Wet} & {Dry} \\
                    \midrule
                    & Tracer & {Mean $ ±$ SD\textsubscript{n}}
                    & & & & & & & & & & & \\
                    \midrule
                    \multirowcell{3}{Genus A \\ \\Species A} & N & & & & & & 81.82 (36) & & &93.83(99) &14.25\pm0.49 &54.6\pm0.23 & \\
     & & & & & & &{ {(4)}} & & &{ (8)} & {(2)} & { {(4)}} \\
                        & C & & & & & & -19.73(29) & & &-26.62(27) &-57.3(14) &-36.65(31) & \\
     & & & & & & & { (4)} & & &{ (8)} & {(2)} & { {(4)}}\\
                        \addlinespace[2ex]
                        \multirowcell{3}{Genus B \\ \\Species B}& N &15.14\pm1.21 &13.1\pm1.2 &13.70 (85) &12.55(84) & 12.32 (64) & 12.27\pm0.47 & 12.28\pm0.59 & 12.61\pm0.29 & 23.43(40) &14.0 (28) &14.00(82) & \\
     & & {(16)} & {(18)} & {(16)} & {(16)} & {(15)} & {(16)} & {(16)} & {(10)} & {(16)} & {(15)} & {(5)} \\
    \ & C &-18.38 (64) & -17.25 (44)\ &-16.66 (39) &-16.6 (59) & -16.77 (30) & -15.98 (37) & -16.59 (38) & -16.05 (22) & -16.6 (3) & -16.06 (36) &-15.72 (45) & \\
     & & {(16)} & { (18)} & {(16)} & {(16)} &{(15)} & {(16)} & {(16)} & {(10)} & {(16)} &{(15)} & {(5)} \\
                                \end{tabular}
       %\end{table}
       \end{sidewaystable}

    \end{document}

在此处输入图片描述

在此处输入图片描述

答案2

你应该做表格:

\documentclass{article}

\usepackage{array}
\usepackage{tabularx}
\usepackage{caption}
\usepackage{changepage}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\usepackage[a4paper,top=0.05cm,bottom=0.05cm,left=0.1cm,right=0.1cm,marginparwidth=0.1cm, landscape, total ={210mm,297mm}]{geometry}
\usepackage{rotating}
\usepackage{caption}
\usepackage{array}
\usepackage{booktabs}
\usepackage{pdflscape}
\usepackage{multirow}
\usepackage[separate-uncertainty=true]{siunitx}

\newcommand{\ts}[1]{\textsubscript{#1}}

\begin{document}
\begin{table}
\caption{Test}
\centering
\begin{tabular}{
  lc*{6}{S[table-format=-2.2(2),table-space-text-post=\ts{(00)}]}
}
\toprule
& Site  & \multicolumn{2}{c}{A} & \multicolumn{2}{c}{B} & \multicolumn{2}{c}{C} \\
\cmidrule(lr){3-4} \cmidrule(lr){5-6} \cmidrule(lr){7-8}
\multicolumn{1}{c}{Species} & Season & {Wet} & {Dry} & {Wet} & {Dry} & {Wet} & {Dry} \\
\midrule
& Tracer & {Mean $\pm$ SD$_n$} \\
\midrule
\textit{Genus A}   & N &       &       &       &       &       & 81.82\pm0.36\ts{(4)} \\
\textit{Species A} & C &       &       &       &       &       & -19.73\pm0.29\ts{(4)} \\
\textit{Genus B}   & N &  15.14\pm1.21\ts{(16)} &  13.1 \pm1.2\ts{(18)} &13.7\pm0.85\ts{(16)} &12.55\pm0.84\ts{(16)} & 12.32\pm0.64\ts{(15)} & 12.27\pm0.47\ts{(16)} \\
\textit{Species B} & C & -18.38\pm0.64\ts{(16)} & -17.25\pm0.44\ts{(18)} &-16.66\pm0.39\ts{(16)} &-16.67\pm0.59\ts{(16)} & -16.77\pm0.3\ts{(15)} & -15.98\pm0.37\ts{(16)} \\
\midrule[\heavyrulewidth]
\end{tabular}
\begin{tabular}{
  lc*{6}{S[table-format=-2.2(2),table-space-text-post=\ts{(00)}]}
}
& Site  & \multicolumn{2}{c}{D} & \multicolumn{2}{c}{E} & \multicolumn{2}{c}{F} \\
\cmidrule(lr){3-4} \cmidrule(lr){5-6} \cmidrule(lr){7-8}
\multicolumn{1}{c}{Species} & Season & {Wet} & {Dry} & {Wet} & {Dry} & {Wet} & {Dry} \\
\midrule
& Tracer & {Mean $\pm$ SD$_n$} \\
\midrule
\textit{Genus A}   & N &       &       &93.83\pm0.99\ts{(8)} &14.25\pm0.49\ts{(2)} &54.6\pm0.23\ts{(4)} &  \\
\textit{Species A} & C &       &       &-26.62\pm0.27\ts{(8)} &-57.3\pm0.14\ts{(2)} &-36.65\pm0.31\ts{(4)} &  \\
\textit{Genus B}   & N & 12.28\pm0.59\ts{(16)} & 12.61\pm0.29\ts{(10)} &23.43\pm0.4\ts{(16)} &14.06\pm0.28\ts{(15)} &14\pm0.82\ts{(5)} &  \\
\textit{Species B} & C & -16.05\pm0.22\ts{(10)} &-16.6\pm0.3\ts{(16)} &-16.06\pm0.36\ts{(15)} &-15.72\pm0.45\ts{(5)} &  & -00.00\pm0.00\ts{(00)} \\
\bottomrule
\end{tabular}
\end{table}
\end{document}

在此处输入图片描述

相关内容