tabularray 环境中的表格仅显示多列单元格后的第一列中的文本

tabularray 环境中的表格仅显示多列单元格后的第一列中的文本

我正在使用 tabularray 环境创建一个有 6 列的多页表 (longtblr)。我想在表中的每个条目后添加一行来汇总该条目。它按预期适用于第一个条目,但之后第一列只有文本。我正在使用 \makecell 命令在单元格中换行。我做错了什么?

\documentclass[12pt]{article}

\usepackage[T1]{fontenc}
\usepackage{float}
\usepackage{tabularray}
\usepackage{makecell}
\usepackage{booktabs}
\UseTblrLibrary{booktabs}

\begin{document}

\begin{longtblr}[
    caption = {This is the caption},
    label   = {tab:test}
    ]
    {
        colspec = {|c|c|c|c|c|c|},
        row{1} = {font=\bfseries},
        cell{3}{1,7} = {c=6}{l},
        cell{5}{1,7} = {c=6}{l},
    }
        \toprule
        Category 1 &    Category 2 &    Category 3 &    Category 4 & Category 5 & Category 6\\
        \midrule
        \makecell{Entry11 \\ Entry12} & \makecell{Entry21 \\ Entry22} & Entry 3 & Entry 4 & Entry 6 & Entry 7\\
        \midrule
        summary of the above entry & & & & & \\
        \midrule
        test1   &   test2   &   test3   &   test4  &   test5   &   test6\\
        \midrule
        summary of the above entry & & & & & \\
        \midrule
        test12  &   test 22 &   test 32 &   test 42 &   test 52 & test62\\
        \bottomrule
\end{longtblr}

\end{document}

在此处输入图片描述

答案1

通过使用,cell{3}{1,7} = {c=6}{l}您不仅可以使行中的第一个单元格成为多列单元格,还可以使行中的最后一个单元格跨越 6 列,这将影响下一行。

您也不需要\makecell使用 来换行tabularray。在单元格周围简单地{...}写上 即可使用换行符。

\documentclass[12pt]{article}

\usepackage[T1]{fontenc}
\usepackage{float}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\begin{document}

\begin{longtblr}[
    caption = {This is the caption},
    label   = {tab:test}
    ]
    {
        colspec = {|c|c|c|c|c|c|},
        row{1} = {font=\bfseries},
        cells = {valign=m},
        cell{3}{1} = {c=6}{l},
        cell{5}{1} = {c=6}{l},
    }
        \toprule
        Category 1 &    Category 2 &    Category 3 &    Category 4 & Category 5 & Category 6\\
        \midrule
        {Entry11 \\ Entry12} & {Entry21 \\ Entry22} & Entry 3 & Entry 4 & Entry 6 & Entry 7\\
        \midrule
        summary of the above entry & & & & & \\
        \midrule
        test1   &   test2   &   test3   &   test4  &   test5   &   test6\\
        \midrule
        summary of the above entry & & & & & \\
        \midrule
        test12  &   test 22 &   test 32 &   test 42 &   test 52 & test62\\
        \bottomrule
\end{longtblr}

\end{document}

在此处输入图片描述

答案2

编辑:

  • 您的多列单元格定义不正确。@samcarter_is_at_topanswers.xyz 的回答中给出了您表格的正确定义,下面的 MWE 中给出了可能的替代方案

离题了,但应该考虑:

  • 您的表格宽度大于\textwidth,因此它会溢出右侧文本块边框。
  • 解决这个问题的一种方法是定义列宽,较长的文本会强制分成几行,或者改为c使用列类型,X[c]或者在您的情况下,因为您希望在单元格中垂直居中文本X[c,m]。 后一种可能性在下面的 MWE 中得到利用。
  • booktabs你可以使用\hlines定义线宽的规则,就像在我的 MWE 中所做的那样
  • tabullaray包可以\makecell用构造来模拟{text \\ text}
  • 如果您确实需要长表格,那么添加表格选项是明智的rowhead=1。到目前为止,您似乎longtblr可以使用可以跨越几页的表格,可以talltblr将其插入table浮动或简单表格中tblr,如果您不使用表格注释TblrNote,则标题和标签会移到表格前面tblr
\documentclass[12pt]{article}
%--------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\usepackage[T1]{fontenc}

\usepackage{tabularray}

\begin{document}
    \begin{longtblr}[
caption = {This is the caption},
  label = {tab:test}
                    ]{hline{1,Z} = 1pt, hline{2-Y}=solid, vlines,
                      colspec = { *{6}{X[c,m]} },
                      row{1}  = {font=\bfseries},
                      rowhead = 1
                    }
Category 1  &  Category 2   & Category 3    & Category 4    & Category 5    & Category 6    \\
Entry11  Entry12    
            & {Entry21 \\ Entry22}   % if you wish, you can emulate "makecell" as shown here
                            & Entry 3       & Entry 4       & Entry 6       & Entry 7       \\
\SetCell[c=6]{l}
summary of the above entry & & & & & \\
test1       & test2         &   test3       &   test4       & test5         &   test6       \\
\SetCell[c=6]{l}
summary of the above entry & & & & & \\
test12      &   test 22     &   test 32     &   test 42     & test 52       & test62        \\
    \end{longtblr}
\end{document}

在此处输入图片描述

(红线表示笼式布局的部分)

相关内容