介绍

介绍

介绍

我有一个longtblr在表格单元格内的文本相对较短时效果很好的方法。查看这个 MWE:

\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage[dvipsnames,table]{xcolor}
\definecolor{light-gray}{HTML}{FFFFFF}
\definecolor{light-blue}{HTML}{EBF5FB}
\usepackage{tabularray}
\usepackage{lipsum}

\begin{document}

    {\centering Centered Text\par}
    
    \begin{longtblr}[
        caption = {This is a caption.},
        ]{
            colspec={m{1.2cm} m{0.5cm} m{1cm} m{1cm} m{1.5cm} m{3.5cm} m{1.5cm}},
            cells={font=\small},
            row{1}={font=\itshape\small},
            row{2,5-7}={bg=light-blue},
            row{3-4}={bg=light-gray},
            column{6}={preto={\minipage{3.5cm}}, appto={\endminipage}},
            hlines
        }
        & Day
        & Month
        & Hours
        & Feature 1 
        & Feature 2
        & Feature 3\\
        %-------------------------------------------------
        Friday
        & 5 
        & June
        & 
        & A\textsubscript{1}
        & This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. 
        \begin{tblr}{ |c|c|c| }
            \hline
             cell1 & cell2 & cell3 \\ 
             cell4 & cell5 & cell6 \\ 
             cell7 & cell8 & cell9 \\ 
             \hline
        \end{tblr}
        This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. 
        & A\textsubscript{3}
        \\
        %-------------------------------------------------
        \SetCell[r=2]{l} Saturday 
        & \SetCell[r=2]{l} 6 
        & \SetCell[r=2]{l} June
        & 14 -- 21
        & B\textsubscript{1}
        &
        & B\textsubscript{3}
        \\
        &  
        & 
        &
        & C\textsubscript{1}
        & C\textsubscript{2}
        & C\textsubscript{3}
        \\
        % -------------------------------------------------
        \SetCell[r=3]{l} Sunday
        & \SetCell[r=3]{l} 7
        & \SetCell[r=3]{l} June
        & 08 -- 10
        & D\textsubscript{1}
        & D\textsubscript{2} 
        & D\textsubscript{3}
        \\
        & 
        &
        & 10 -- 17
        & E\textsubscript{1}
        &
        & E\textsubscript{3}
        \\
        & 
        & 
        & 
        & F\textsubscript{1}
        & % F\textsubscript{2}
        This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. 
        & F\textsubscript{3}
        \\
        % -------------------------------------------------
    \end{longtblr}
    
\end{document}

在此处输入图片描述

问题

一旦我稍微增加了最后一个单元格中的文本长度,并且因此longtblr需要转到下一页,则对应于

\SetCell[r=3]{l} Sunday
& \SetCell[r=3]{l} 7
& \SetCell[r=3]{l} June

朝向页面的底部边缘,即超出表格边框。

我怎样才能将表格边界外的文本移回表格边界内,即正确的位置?

下面您将看到一个 MWE,它与前一个(美观的)表格完全相同,但文本较短,只是倒数第二个单元格中的文本比前一个(美观的)表格中略长。

\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage[dvipsnames,table]{xcolor}
\definecolor{light-gray}{HTML}{FFFFFF}
\definecolor{light-blue}{HTML}{EBF5FB}
\usepackage{tabularray}
\usepackage{lipsum}

\begin{document}

    {\centering Centered Text\par}
    
    \begin{longtblr}[
        caption = {This is a caption.},
        ]{
            colspec={m{1.2cm} m{0.5cm} m{1cm} m{1cm} m{1.5cm} m{3.5cm} m{1.5cm}},
            cells={font=\small},
            row{1}={font=\itshape\small},
            row{2,5-7}={bg=light-blue},
            row{3-4}={bg=light-gray},
            column{6}={preto={\minipage{3.5cm}}, appto={\endminipage}},
            hlines
        }
        & Day
        & Month
        & Hours
        & Feature 1 
        & Feature 2
        & Feature 3\\
        %-------------------------------------------------
        Friday
        & 5 
        & June
        & 
        & A\textsubscript{1}
        & This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. 
        \begin{tblr}{ |c|c|c| }
            \hline
             cell1 & cell2 & cell3 \\ 
             cell4 & cell5 & cell6 \\ 
             cell7 & cell8 & cell9 \\ 
             \hline
        \end{tblr}
        This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. 
        & A\textsubscript{3}
        \\
        %-------------------------------------------------
        \SetCell[r=2]{l} Saturday 
        & \SetCell[r=2]{l} 6 
        & \SetCell[r=2]{l} June
        & 14 -- 21
        & B\textsubscript{1}
        &
        & B\textsubscript{3}
        \\
        &  
        & 
        &
        & C\textsubscript{1}
        & C\textsubscript{2}
        & C\textsubscript{3}
        \\
        % -------------------------------------------------
        \SetCell[r=3]{l} Sunday
        & \SetCell[r=3]{l} 7
        & \SetCell[r=3]{l} June
        & 08 -- 10
        & D\textsubscript{1}
        & D\textsubscript{2} 
        & D\textsubscript{3}
        \\
        & 
        &
        & 10 -- 17
        & E\textsubscript{1}
        &
        & E\textsubscript{3}
        \\
        & 
        & 
        & 
        & F\textsubscript{1}
        & % F\textsubscript{2}
        This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. 
        & F\textsubscript{3}
        \\
        % -------------------------------------------------
    \end{longtblr}
    
\end{document}

在此处输入图片描述 在此处输入图片描述

根据 Zarko 的回复进行了编辑

(我在这里写是因为我想添加一些截图)

非常感谢 Zarko!

我只是复制并粘贴了你的代码,并在倒数第二个单元格中添加了几行文本,只是为了看看会发生什么:

在此处输入图片描述

\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage[dvipsnames,table]{xcolor}
\definecolor{light-gray}{HTML}{FFFFFF}
\definecolor{light-blue}{HTML}{EBF5FB}
\usepackage{tabularray}
\usepackage{lipsum}

\begin{document}

    {\centering Centered Text\par}

\begin{longtblr}[
    caption = {This is a caption.},
                ]{colspec = {llll 
                             l% Q[l, 4em] 
                             X[h, j] 
                             l% Q[l, 4em] 
                             },
%      colsep=4pt,
                  column{6}={preto={\minipage{\linewidth}}, appto={\endminipage}},
                  cells={font=\small},
                  row{1}={font=\itshape\small},
                  row{2,5-7}={bg=light-blue},
                  row{3-4}={bg=light-gray},
                    hlines
    }
    & Day
        & Month
            & Hours
                & Feature 1
                    & Feature 2
                        & Feature 3\\
        %-------------------------------------------------
Friday
    & 5 & June
            &
                & A\textsubscript{1}
                    & This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times.
                    \begin{center}
                        \begin{tblr}{ |c|c|c| }
                            \hline
                     cell1 & cell2 & cell3 \\
                     cell4 & cell5 & cell6 \\
                     cell7 & cell8 & cell9 \\
                             \hline
                        \end{tblr}\par
                    \end{center}
                    This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times.
                        & A\textsubscript{3}
        \\
%-------------------------------------------------
\SetCell[r=2]{l} Saturday
    & \SetCell[r=2]{l} 6
        & \SetCell[r=2]{l} June
            & 14 -- 21
                & B\textsubscript{1}
                    &
                        & B\textsubscript{3}
        \\
    &   &   &   & C\textsubscript{1}
                    & C\textsubscript{2}
                        & C\textsubscript{3}
        \\
%-------------------------------------------------
\SetCell[r=3]{l} Sunday
    & \SetCell[r=3]{l} 7
        & \SetCell[r=3]{l} June
            & 08 -- 10
                & D\textsubscript{1}
                    & D\textsubscript{2}
                        & D\textsubscript{3}
        \\
    &   &
            & 10 -- 17
                & E\textsubscript{1}
                    &
                        & E\textsubscript{3}
        \\
    &   &   &   & F\textsubscript{1}
                    & This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. 
                        & F\textsubscript{3}
        \\
%-------------------------------------------------
    \end{longtblr}

\end{document}

然后,通过添加\pagebreak您建议的内容,表格就可以正常工作并转到以下页面:

在此处输入图片描述

\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage[dvipsnames,table]{xcolor}
\definecolor{light-gray}{HTML}{FFFFFF}
\definecolor{light-blue}{HTML}{EBF5FB}
\usepackage{tabularray}
\usepackage{lipsum}

\begin{document}

    {\centering Centered Text\par}

\begin{longtblr}[
    caption = {This is a caption.},
                ]{colspec = {llll 
                             l% Q[l, 4em] 
                             X[h, j] 
                             l% Q[l, 4em] 
                             },
%      colsep=4pt,
                  column{6}={preto={\minipage{\linewidth}}, appto={\endminipage}},
                  cells={font=\small},
                  row{1}={font=\itshape\small},
                  row{2,5-7}={bg=light-blue},
                  row{3-4}={bg=light-gray},
                    hlines
    }
    & Day
        & Month
            & Hours
                & Feature 1
                    & Feature 2
                        & Feature 3\\
        %-------------------------------------------------
Friday
    & 5 & June
            &
                & A\textsubscript{1}
                    & This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times.
                    \begin{center}
                        \begin{tblr}{ |c|c|c| }
                            \hline
                     cell1 & cell2 & cell3 \\
                     cell4 & cell5 & cell6 \\
                     cell7 & cell8 & cell9 \\
                             \hline
                        \end{tblr}\par
                    \end{center}
                    This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times.
                        & A\textsubscript{3}
        \\
%-------------------------------------------------
\SetCell[r=2]{l} Saturday
    & \SetCell[r=2]{l} 6
        & \SetCell[r=2]{l} June
            & 14 -- 21
                & B\textsubscript{1}
                    &
                        & B\textsubscript{3}
        \\
    &   &   &   & C\textsubscript{1}
                    & C\textsubscript{2}
                        & C\textsubscript{3}
        \\
%-------------------------------------------------
\pagebreak
\SetCell[r=3]{l} Sunday
    & \SetCell[r=3]{l} 7
        & \SetCell[r=3]{l} June
            & 08 -- 10
                & D\textsubscript{1}
                    & D\textsubscript{2}
                        & D\textsubscript{3}
        \\
    &   &
            & 10 -- 17
                & E\textsubscript{1}
                    &
                        & E\textsubscript{3}
        \\
    &   &   &   & F\textsubscript{1}
                    & This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. 
                        & F\textsubscript{3}
        \\
%-------------------------------------------------
    \end{longtblr}

\end{document}

因此,据我理解,这\pagebreak将是解决这个问题的(唯一)方法。

回答您的问题,是的,我的表格很长,占据了 4-5 页,有时表格单元格内还会包含长文本。

非常感谢!

答案1

  • 如我所见,您使用除列规范之外的代码(已接受!),回答关于你之前的问题。
  • 现在我想知道,为什么你不采用他们提议的表格设计,它(至少在我看来)能提供更有吸引力的表格?
  • 通过使用我的答案中的列规范,使第六列中的文本高度大大降低,从而减少问题发生的可能性。
  • 从给定表格示例中的内容来看,不清楚为什么您规定了第五列和第七列的宽度。对于它们,我将使用l列类型定义的“自然”宽度。
  • 顺便问一下,你的表真的需要是长型的吗?

因此,考虑到上述评论,您的表格可以如下所示:

在此处输入图片描述

\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage[dvipsnames,table]{xcolor}
\definecolor{light-gray}{HTML}{FFFFFF}
\definecolor{light-blue}{HTML}{EBF5FB}
\usepackage{tabularray}
\usepackage{lipsum}

\begin{document}

    {\centering Centered Text\par}

\begin{longtblr}[
    caption = {This is a caption.},
                ]{colspec = {llll 
                             l% Q[l, 4em] 
                             X[h, j] 
                             l% Q[l, 4em] 
                             },
%      colsep=4pt,
                  column{6}={preto={\minipage{\linewidth}}, appto={\endminipage}},
                  cells={font=\small},
                  row{1}={font=\itshape\small},
                  row{2,5-7}={bg=light-blue},
                  row{3-4}={bg=light-gray},
                    hlines
    }
    & Day
        & Month
            & Hours
                & Feature 1
                    & Feature 2
                        & Feature 3\\
        %-------------------------------------------------
Friday
    & 5 & June
            &
                & A\textsubscript{1}
                    & This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times.
                    \begin{center}
                        \begin{tblr}{ |c|c|c| }
                            \hline
                     cell1 & cell2 & cell3 \\
                     cell4 & cell5 & cell6 \\
                     cell7 & cell8 & cell9 \\
                             \hline
                        \end{tblr}\par
                    \end{center}
                    This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times.
                        & A\textsubscript{3}
        \\
%-------------------------------------------------
\SetCell[r=2]{l} Saturday
    & \SetCell[r=2]{l} 6
        & \SetCell[r=2]{l} June
            & 14 -- 21
                & B\textsubscript{1}
                    &
                        & B\textsubscript{3}
        \\
    &   &   &   & C\textsubscript{1}
                    & C\textsubscript{2}
                        & C\textsubscript{3}
        \\
%-------------------------------------------------
\SetCell[r=3]{l} Sunday
    & \SetCell[r=3]{l} 7
        & \SetCell[r=3]{l} June
            & 08 -- 10
                & D\textsubscript{1}
                    & D\textsubscript{2}
                        & D\textsubscript{3}
        \\
    &   &
            & 10 -- 17
                & E\textsubscript{1}
                    &
                        & E\textsubscript{3}
        \\
    &   &   &   & F\textsubscript{1}
                    & This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times.
                        & F\textsubscript{3}
        \\
%-------------------------------------------------
    \end{longtblr}

\end{document}

笔记:

  • 正如你所看到的,第六列的设计有一点改变:插入表现在在center环境中
  • 你应该知道,长表不能在行中间分割
  • 由于表格的结构,您得到了第二个彩色行块奇怪的分裂:
    • 前两行在第一页,其中
    • 第三行被剪到下一页
    • 多行单元格跨越所有行,情况比较特殊。它位于第一页,但由于其高度(由第六列决定),它向下突出一页。
  • 作为发生这种情况的补救措施,可以 - 如果您不考虑我的上述建议并坚持您的表格设计 - 您需要\pagebreak在此行块之前插入命令

困境:该怎么办?

  • 不适合我。即使不知道你的表格背景,我也会坚持建议的解决方案,因为在我看来,这更有吸引力
  • 如果您提供表格行的示例,以证明您为何确定第五列和第七列的宽度以及您这样做的依据,那么困境就会消失,但无论如何,我强烈建议至少考虑l前四列的建议列规范()。
  • 我不知道如何帮助你,如果建议的解决方案你接受了,那就不要使用。所以我觉得我为准备这个答案所花的努力是徒劳的。

相关内容