在表格的列中添加行时出错

在表格的列中添加行时出错

我从这里的答案中得到了一个很好的答案,可以将标准表移植到 Springer 期刊中 Latex 表格缺少边框线 使用以下代码

\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{siunitx}

\begin{document}
    \begin{table*}[ht]
    \caption{Result}
\sisetup{table-format=2.1,
         detect-weight, % <--
         }
\begin{tblr}{hlines, vlines,
             colspec = {X[c] X[1.2,c] X[1.8,c] X[c, si]},
             cell{even}{2} = {r=2}{},
             cell{odd[3]}{Z} = {font=\bfseries},
             row{1} = {guard}
             } 
Users Set Size (USS)
    &   Range of Users Individual
        &   Index of scalar array for mapping
            &   Transfer Failure        \\
\SetCell[r=6]{c}    6
    & 6 & 10& 23                        \\
    &   & 4 & 18.3                      \\
    & 7 & 0 & 13.3                      \\
    &   & 4 & 33.3                      \\
    & 7 & 1 & 17                        \\
    &   & 2 & 66.6                      \\
\end{tblr}
   \end{table*}
\end{document}

(附上上述 latex 的图片)但我需要在第 3 列和第 4 列的每个单元格中添加一行。例如,在 4 & 18.3 下方添加一行,在 4 & 33.3 下方添加一行,在 2 & 66.6 下方添加一行。所以我无法理解我需要修改哪里,我改了,\SetCell[r=6]{c}\SetCell[r=9]{c}得到了奇怪的输出和错误。有人能告诉我需要修改这个 latex 代码中的什么吗在此处输入图片描述

答案1

作为@Clara 答案的补充(+1)......

  • 在您问题中使用的我的代码中,表格序言具有以下含义
\begin{tblr}{hlines, vlines,
     colspec = {X[c] X[1.2,c] X[1.8,c] X[c, si]}, % determine column types
     cell{even}{2} = {r=2}{}, % determine where multi row cells, which span 
                              % two successive rows start: at each even row 
                              % after second row
   cell{odd[3]}{Z} = {font=\bfseries}, % determine in which rows numbers in 
                              % the last columns are in the boldface shape
             row{1} = {guard} % protect text in the `S` columns in the first 
                              % row, that not interfere in S column formating
             }
  • 您没有提供信息,那些附加行中的内容是什么以及某些数字是否以粗体显示。
  • 假设预期结果类似于以下内容

在此处输入图片描述

那么您需要在问题所示的代码中做出以下更改:

\begin{tblr}{hlines, vlines,
     colspec = {X[c] X[1.2,c] X[1.8,c] X[c, si]},
     cell{2,5,8}{2} = {r=3}{},           % determine multi row cells in the second column
                                         % which span three successive adjacent rows
     cell{4,7,10}{Z} = {font=\bfseries}, % determine which cells in the last column are in boldface
     row{1} = {guard}
             }
  • 有关所用代码的更多详细信息,您应该阅读tabularray软件包文档或询问(在评论中),提供的建议中哪些内容对您来说不清楚。
  • 为了完整起见,上面显示的表格生成的完整 MWE 为:
\documentclass{sn-jnl}

\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{siunitx}

\begin{document}
    \begin{table*}[ht]
    \caption{Result}
\sisetup{table-format=2.1,
         detect-weight, % <--
         }
\begin{tblr}{hlines, vlines,
     colspec = {X[c] X[1.2,c] X[1.8,c] X[c, si]},
     cell{2,5,8}{2} = {r=3}{},           % determine multi row cells in the second column
                                         % which span three successive adjacent rows
     cell{4,7,10}{Z} = {font=\bfseries}, % determine which cells in the last column are in boldface
     row{1} = {guard}
             }
Users Set Size (USS)
    &   Range of Users Individual
        &   Index of scalar array for mapping
            &   Transfer Failure        \\
\SetCell[r=9]{c}    9    % multirow cell in the first column, spanning 9 rows
    & 6 & 10& 23                        \\
    &   & 7 & 20                        \\
    &   & 4 & 18.3                      \\
    & 7 & 0 & 13.3                      \\
    &   & 0 & 13.3                      \\
    &   & 4 & 33.3                      \\
    & 7 & 1 & 17                        \\
    &   & 3 & 11                        \\
    &   & 2 & 66.6                      \\
\end{tblr}
   \end{table*}
\end{document}

答案2

我不确定这是否是您想要的。我建议将风格和内容完全分开,而不是将它们混合在一起。

\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{siunitx}
\begin{document}
\begin{table}
\caption{Result}
\begin{tblr}
{
colspec        = {X[c,m]X[1.2,c,m]X[1.8,c,m]X[c,m,si={table-format=2.1,detect-weight}]},
cell{2}{1}     = {r=9}{},
cell{2,5,8}{2} = {r=3}{},
cell{3,6,9}{Z} = {font=\bfseries},
row{1}         = {guard},
hlines,vlines,
}
Users Set Size (USS) & Range of Users Individual & Index of scalar array for mapping & Transfer Failure \\
6                    & 6                         & 10                                & 23               \\
                     &                           & 4                                 & 18.3             \\
                     &                           & 4                                 & 18.3             \\
                     & 7                         & 0                                 & 13.3             \\
                     &                           & 4                                 & 33.3             \\
                     &                           & 4                                 & 33.3             \\
                     & 7                         & 1                                 & 17               \\
                     &                           & 2                                 & 66.6             \\
                     &                           & 2                                 & 66.6             \\
\end{tblr}
\end{table}
\end{document}

在此处输入图片描述

相关内容