有人能用 siunitx 帮我解决多列多行表中的奇数间距问题吗?

有人能用 siunitx 帮我解决多列多行表中的奇数间距问题吗?

我想将我的数据放在多列多行的表中,同时按小数点对齐条目。为此,我使用了 siunitx 包。问题在于三个子列的格式:“位置 1”、“位置 2”和“位置 3”。我不介意条目是居中还是位于左侧,但目前它们不一样,我不明白为什么。除此之外,在“位置 1”列中,3 个 sf 值和 \plusminus 之间有空格,我曾尝试使用 ~ 将其消除,但无济于事。如果您能以任何方式提供帮助,我将不胜感激!非常感谢。

\documentclass[12pt, oneside]{article}   
\usepackage{geometry}                       
\geometry{a4paper}                                                  
\usepackage[parfill]{parskip}           
\usepackage{graphicx}               
\usepackage{amssymb}
\usepackage{titling}
\pagenumbering{arabic}                                  
\usepackage{wrapfig}
\usepackage[nottoc]{tocbibind}
\usepackage[round,authoryear]{natbib}
\usepackage{placeins}
\usepackage{gensymb}
\usepackage{array}
\usepackage{booktabs}
\usepackage{amsmath}
\graphicspath{ {paperfigures/} }
\usepackage{textcomp}
\usepackage[font={footnotesize}, margin=2cm]{caption}
\numberwithin{equation}{section}
\usepackage{tabularx}
\usepackage{siunitx}
\usepackage{floatrow}
\usepackage[font={scriptsize}, margin=0.5cm]{subfig}
\usepackage{multirow}

\begin{document}

\begin{table}[]
\scriptsize
\centering
\caption{Results for testing the directionality of the Light Diode, when detecting the light intensity at three locations in the room, at three different heights and four different orientations where 0\degree~indicates the diode is pointing directly upward, and each other degree value is taken from this.}
\label{tab:directional}
\sisetup{output-decimal-marker = {\cdot}}
\begin{tabular}{ll|S|S|S[table-format=-2.1]|}
\cline{3-5}
                                                      &                                            
&   \multicolumn{3}{c|}{\textbf{Mean Light Intensity at positions 
(mV)}}                                                            \\    
\hline
\multicolumn{1}{|l|}{\textbf{Vertical Position}}                   &     
\multicolumn{1}{c|}{\textbf{Orientation}} & \multicolumn{1}{c|}
{\textbf{Position 1}} & \multicolumn{1}{c|}{\textbf{Position 2}} & 
\multicolumn{1}{c|}{\textbf{Position 3}} \\ \hline
\multicolumn{1}{|l|}{\multirow{4}{*}{10 cm from ceiling}} & 0$\degree$                                
& 2.3 $\pm$ 2.0                       & 5.8 $\pm$ 2.0                       
& 8.2 $\pm$ 2.0                      \\ \cline{2-5} 
\multicolumn{1}{|l|}{}                                    & 45$\degree$                               
& 3.7 $\pm$ 2.0                       & 2.9 $\pm$ 2.0                       
& 26.1 $\pm$ 2.1                      \\ \cline{2-5} 
\multicolumn{1}{|l|}{}                                    & 90$\degree$                               
& 12.8 $\pm$ 2.0                      & 4.5 $\pm$ 2.0                          
& 13.6 $\pm$ 2.0                      \\ \cline{2-5} 
\multicolumn{1}{|l|}{}                                    & 
180$\degree$                              & 1.9 $\pm$ 2.0                       
& 4.0 $\pm$ 2.0                       & 3.0 $\pm$ 2.0                         
\\ \hline
\multicolumn{1}{|l|}{\multirow{4}{*}{Centre}}             & 0$\degree$                                
& 10.4 $\pm$ 2.0                      & 8.8 $\pm$ 2.0                          
& 11.4 $\pm$ 2.0                      \\ \cline{2-5} 
\multicolumn{1}{|l|}{}                                    & 45$\degree$                               
& 12.5 $\pm$ 2.0                      & 8.0 $\pm$ 2.0                       
& 7.2 $\pm$ 2.0                       \\ \cline{2-5} 
\multicolumn{1}{|l|}{}                                    & 90$\degree$                               
& 5.3 $\pm$ 2.0                       & 2.9 $\pm$ 2.0                       
& 5.1 $\pm$ 2.0                       \\ \cline{2-5} 
\multicolumn{1}{|l|}{}                                    & 
180$\degree$                              & 1.8 $\pm$ 2.0                         
& 1.4 $\pm$ 2.0                       & 1.2 $\pm$ 2.0                       
\\ \hline
\multicolumn{1}{|l|}{\multirow{4}{*}{10 cm from floor}}   & 0$\degree$                                
& 9.6 $\pm$ 2.0                       & 6.9 $\pm$ 2.0                       
& 11.0 $\pm$ 2.0                      \\ \cline{2-5} 
\multicolumn{1}{|l|}{}                                    & 45$\degree$                               
& 12.2 $\pm$ 2.0                      & 9.0 $\pm$ 2.0                       
& 3.5 $\pm$ 2.0                       \\ \cline{2-5} 
\multicolumn{1}{|l|}{}                                    & 90$\degree$                               
& 2.3 $\pm$ 2.0                       & 2.2 $\pm$ 2.0                       
& 1.5 $\pm$ 2.0                       \\ \cline{2-5} 
\multicolumn{1}{|l|}{}                                    & 
180$\degree$                              & 2.1 $\pm$ 2.0                       
& 1.6 $\pm$ 2.0                       & 0.9 $\pm$ 2.0                       
\\ \hline
\end{tabular}
\end{table}    
\end{document}  

有问题的表格

答案1

您可能希望获得类似这样的东西:

在此处输入图片描述

您的问题是结果\multicolumn{3}{c|}{...}比它跨越的列宽更宽。因此,我使用新格式扩大了它们的宽度(参见代码)。除此之外,我还清理了您的代码(其中包含大量错误),删除了所有不必要的\multicolumns和错误的不确定性编码。

\documentclass[12pt, oneside]{article}
\usepackage{geometry}
\geometry{a4paper}
%\usepackage[parfill]{parskip}
%\usepackage{graphicx}
%\usepackage{amssymb}
%\usepackage{titling}
%\pagenumbering{arabic}
%\usepackage{wrapfig}
%\usepackage[nottoc]{tocbibind}
%\usepackage[round,authoryear]{natbib}
%\usepackage{placeins}
%\usepackage{gensymb}
%\usepackage{amsmath}
%\graphicspath{ {paperfigures/} }
%\usepackage{textcomp}
\usepackage[font={footnotesize}, margin=2cm]{caption}
%\numberwithin{equation}{section}
\usepackage{siunitx}
%\usepackage{floatrow}
%\usepackage[font={scriptsize}, margin=0.5cm]{subfig}
\usepackage{array}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{tabularx}

\begin{document}

\begin{table}
    \scriptsize
    \centering
\caption{Results for testing the directionality of the Light Diode, when detecting the light intensity at three locations in the room, at three different heights and four different orientations where 0 indicates the diode is pointing directly upward, and each other degree value is taken from this.}
\label{tab:directional}
\sisetup{output-decimal-marker = {\cdot}}
\begin{tabular}{|l|S[table-format = 3]<{\si{\degree}}
             |*{3}{S[table-format = 4.1,
                     separate-uncertainty,
                     table-space-text-post={\quad},
                     table-figures-uncertainty=1]|}}
\cline{3-5}
\multicolumn{2}{c|}{} 
&   \multicolumn{3}{c|}{\textbf{Mean Light Intensity at positions
(mV)}}                                                            \\
\hline
\textbf{Vertical Position}
    &   \multicolumn{1}{c|}{\textbf{Orientation}}
        &   \textbf{Position 1}
            &   \textbf{Position 2}
                &   \textbf{Position 3}     \\ \hline
\multirow{4}{*}{10 cm from ceiling}
    & 0    & 2.3 \pm 2.0 & 5.8 \pm 2.0 & 8.2 \pm 2.0                   \\ \cline{2-5}
    & 45  & 3.7 \pm 2.0 & 2.9 \pm 2.0 & 26.1 \pm 2.1                      \\ \cline{2-5}
    & 90  & 12.8\pm 2.0 & 4.5 \pm 2.0 & 13.6 \pm 2.0                      \\ \cline{2-5}
    & 180 & 1.9 \pm 2.0 & 4.0 \pm 2.0 & 3.0 \pm 2.0 \\ \hline
\multirow{4}{*}{Centre}
    & 0   & 10.4\pm 2.0 & 8.8 \pm 2.0 & 11.4 \pm 2.0                      \\ \cline{2-5}
    & 45  & 12.5\pm 2.0 & 8.0 \pm 2.0 & 7.2 \pm 2.0                       \\ \cline{2-5}
    & 90  & 5.3 \pm 2.0 & 2.9 \pm 2.0 & 5.1 \pm 2.0                       \\ \cline{2-5}
    & 180 & 1.8 \pm 2.0 & 1.4 \pm 2.0 & 1.2 \pm 2.0 \\ \hline
\multirow{4}{*}{10 cm from floor}
    & 0   & 9.6 \pm 2.0 & 6.9 \pm 2.0 & 11.0 \pm 2.0                       \\ \cline{2-5}
    & 45  & 12.2\pm 2.0 & 9.0 \pm 2.0 & 3.5 \pm 2.0                       \\ \cline{2-5}
    & 90  & 2.3 \pm 2.0 & 2.2 \pm 2.0 & 1.5 \pm 2.0                       \\ \cline{2-5}
    & 180 & 2.1 \pm 2.0 & 1.6 \pm 2.0 & 0.9 \pm 2.0 \\ \hline
\end{tabular}
\end{table}
\end{document}

我还评论了所有与该代码不相关的包。

答案2

我简化了您的代码,借助makecell软件包在行之间添加了一些填充,并提出了另一个更好看的解决方案代码,没有垂直线,使用booktabs

\documentclass[12pt, oneside]{article}
\usepackage{geometry}
\geometry{a4paper}
\usepackage{amssymb}
\usepackage{array}
\usepackage{booktabs}
\usepackage{amsmath}
\usepackage[font={footnotesize}, margin=2cm]{caption}
\usepackage{siunitx}
\usepackage{multirow, cellspace}
\setlength\cellspacetoplimit{3pt}
\setlength\cellspacebottomlimit{3pt}

\begin{document}

\begin{table}[!htb]
  \scriptsize
  \centering
  \caption{Results for testing the directionality of the Light Diode, when detecting the light intensity at three locations in the room, at three different heights and four different orientations where \SI{0}{\degree}~indicates the diode is pointing directly upward, and each other degree value is taken from this.}
  \label{tab:directional}
  \sisetup{ table-number-alignment=center, output-decimal-marker={ · },separate-uncertainty, table-format=2.1(2), mode=math}
  \begin{tabular}{|l|Cl|*{3}{S|}}
    \cline{3-5}
    \multicolumn{2}{c|}{}& \multicolumn{3}{Cc|}{\textbf{Mean Light Intensity at positions
    (mV)}} \\
    \hline
    {\textbf{Vertical Position}} &
    {\textbf{Orientation}} & {\textbf{Position 1}} & {\textbf{Position 2}} &{\textbf{Position 3}} \\%
    \hline
    \multirow{4}{*}[-2pt]{10 cm from ceiling} & \SI{0}{\degree} & 2.3 ±2 & 5.8 ±2 & 8.2 ±2 \\%
    \cline{2-5}
                                              & \SI{45}{\degree} & 3.7 ±2 & 2.9 ±2 & 26.1 ±2.1 \\%
    \cline{2-5}
                                              & \SI{90}{\degree} & 12.8 ±2 & 4.5 ±2 & 13.6 ±2 \\ %
    \cline{2-5}
                                              & \SI{180}{\degree} & 1.9 ±2 & 4.0 ±2 & 3.0 ±2 \\%
    \hline
    \multirow{4}{*}[-2pt]{Centre} & \SI{0}{\degree} & 10.4 ±2 & 8.8 ±2 & 11.4 \pm2 \\%
    \cline{2-5}
                                              & \SI{45}{\degree} & 12.5 ±2 & 8.0 ±2 & 7.2 ±2 \\%
    \cline{2-5}
                                              & \SI{90}{\degree} & 5.3 ±2 & 2.9 ±2 & 5.1 ±2 \\%
    \cline{2-5}
                                              & \SI{180}{\degree} & 1.8 ±2 & 1.4 ±2 & 1.2 ±2 \\%
    \hline
    \multirow{4}{*}[-2pt]{10 cm from floor} & \SI{0}{\degree}
    & 9.6 ±2 & 6.9 ±2 & 11.0 ±2 \\%
    \cline{2-5}
                                              & \SI{45}{\degree} & 12.2 ±2 & 9.0 ±2 & 3.5 ±2 \\%
    \cline{2-5}
                                              & \SI{90}{\degree} & 2.3 ±2 & 2.2 ±2 & 1.5 ±2 \\%
    \cline{2-5}
                                              & \SI{180}{\degree} & 2.1 ±2 & 1.6 ±2 & 0.9 ±2 \\%
    \hline
  \end{tabular} \end{table}

  \begin{table}[!htb]
    \scriptsize
    \centering
    \caption{Results for testing the directionality of the Light Diode, when detecting the light intensity at three locations in the room, at three different heights and four different orientations where \SI{0}{\degree}~indicates the diode is pointing directly upward, and each other degree value is taken from this.}
    \label{tab:directional}
    \sisetup{ table-number-alignment=center, output-decimal-marker={ · },separate-uncertainty, table-format=2.1(2), mode=math}
    \begin{tabular}{ll*{3}{S}}
      \multicolumn{2}{c}{}& \multicolumn{3}{c}{\textbf{Mean Light Intensity at positions (mV)}} \\
      \addlinespace[\aboverulesep]%
      \toprule
      \textbf{Vertical Position} & \textbf{Orientation} & {\textbf{Position 1}} & {\textbf{Position 2}} & {\textbf{Position 3}} \\%
      \midrule
      \multirow{4}{*}[-1.5\defaultaddspace]{10 cm from ceiling} & \SI{0}{\degree} & 2.3 ±2 & 5.8 ±2 & 8.2 ±2 \\%
      \addlinespace
                                                                & \SI{45}{\degree} & 3.7 ±2 & 2.9 ±2 & 26.1 ±2.1 \\%
      \addlinespace
                                                                & \SI{90}{\degree} & 12.8 ±2 & 4.5 ±2 & 13.6 ±2 \\ %
      \addlinespace
                                                                & \SI{180}{\degree} & 1.9 ±2 & 4.0 ±2 & 3.0 ±2 \\%
      \cmidrule(lr){1-5}
      \multirow{4}{*}[-1.5\defaultaddspace]{Centre} & \SI{0}{\degree} & 10.4 ±2 & 8.8 ±2 & 11.4 \pm2 \\%
      \addlinespace
                                                                & \SI{45}{\degree} & 12.5 ±2 & 8.0 ±2 & 7.2 ±2 \\%
      \addlinespace
                                                                & \SI{90}{\degree} & 5.3 ±2 & 2.9 ±2 & 5.1 ±2 \\%
      \addlinespace
                                                                & \SI{180}{\degree} & 1.8 ±2 & 1.4 ±2 & 1.2 ±2 \\%
      \cmidrule(lr){1-5}
      \multirow{4}{*}[-1.5\defaultaddspace]{10 cm from floor} & \SI{0}{\degree}
      & 9.6 ±2 & 6.9 ±2 & 11.0 ±2 \\%
      \addlinespace
                                                                & \SI{45}{\degree} & 12.2 ±2 & 9.0 ±2 & 3.5 ±2 \\%
      \addlinespace
                                                                & \SI{90}{\degree} & 2.3 ±2 & 2.2 ±2 & 1.5 ±2 \\%
      \addlinespace
                                                                & \SI{180}{\degree} & 2.1 ±2 & 1.6 ±2 & 0.9 ±2 \\%
      \bottomrule
    \end{tabular} \end{table}

\end{document} 

在此处输入图片描述

答案3

(这还不够完整——需要对行之间的小数进行对齐)

实际的答案相对简单,但是您的例子中包含了大量的内容,使得您(可能还有其他人)更难以隔离问题。

为了制作平均能量损失,首先复制一份文档。注释或删除章节、节、段落,, 和表格的部分或其他核心内容与您的问题无关的内容。如果您可以将它们注释掉,您就知道它们与问题无关,而文档仍然表现相同。

这样做之后,你的核心 MWE 仍然会显示你的问题是

\documentclass{article}
\usepackage{siunitx}

\begin{document}

\begin{table}[]
\begin{tabular}{llSSS[table-format=-2.1]}
label & 90 & 12.8 $\pm$ 2.0 & 4.5 $\pm$ 2.0 & 13.6 $\pm$ 2.0 \\
\end{tabular}
\end{table}
\end{document}

在此处输入图片描述

这样就更容易识别出[table-format=-2.1]应用于最后一列,该列没有错误。将相同格式应用于其他两列数据(即\begin{tabular}{llS[table-format=-2.1]S[table-format=-2.1]S[table-format=-2.1]})可得出

在此处输入图片描述

这解决了一个间距问题,但又引入了另一个问题(S列太窄)。添加标题{Heading 1} & {Heading 2} & {Heading 3} & {Heading 4} & {Heading 5}实际上并没有解决任何问题:

在此处输入图片描述

但如果你让 siunitx 使用它的\num宏(第 6 页当前文档) 及其separate-uncertainties选项 (第 29 页) 来打印您的值和不确定性,事情会变得更好,而且您的工作量也会减少:

\documentclass{article}
\usepackage{siunitx}

\begin{document}

\begin{table}
\sisetup{table-format=-2.1, separate-uncertainty}
\begin{tabular}{llSSS}
{Heading 1} & {Heading 2} & {Heading 3} & {Heading 4} & {Heading 5} \\
label & 90 & \num{12.8 +- 2} & \num{4.5 \pm 2.0} & \num{13.6 \pm 2.0} \\
\end{tabular}
\end{table}
\end{document}

在此处输入图片描述

相关内容