问题与 MWE

问题与 MWE

问题与 MWE

我想添加一个简单的表格(如所述背页)里面长表(由@CarLaTeX 提出/建立另一个 stack exchange 问题)。

如下面的 MWE 和相应的图所示,我添加了简单的表格(如所示背页)在我的长表,我们可以注意到:

  1. 黑线形成表格未显示,并且
  2. 长表不再居中。
% The original "longtblr" table was created by @CarLaTeX in 
% https://tex.stackexchange.com/questions/675559/how-to-draw-horizontal-rules-lines-beginning-in-column-i-and-ending-in-column-j

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[dvipsnames,table]{xcolor}
\definecolor{light-gray}{HTML}{FFFFFF}
\definecolor{light-blue}{HTML}{EBF5FB}
\usepackage{tabularray}

\title{}
\author{}

\begin{document}
    \maketitle
    
    \begin{longtblr}[
        caption = {This is a caption.},
        ]{
            colspec={m{1.2cm} m{0.5cm} m{1cm} m{1.5cm} m{1.5cm} m{4cm} m{1.5cm}},
            row{1}={font=\itshape},
            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}
        & % A\textsubscript{2}
        \begin{center}
            \begin{tabular}{ |c|c|c| } 
             \hline
             cell1 & cell2 & cell3 \\ 
             cell4 & cell5 & cell6 \\ 
             cell7 & cell8 & cell9 \\ 
             \hline
            \end{tabular}
        \end{center}
        & 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}
        & F\textsubscript{3}
        \\
        % -------------------------------------------------
    \end{longtblr}
    
\end{document}

在此处输入图片描述

问题

只需添加这个简单的表格,如图所示背页在我的长表,我们可以看到形成的黑线表格未显示。此外长表不再居中。

  1. 我怎样才能显示形成的黑线表格
  2. 我怎样才能重新居中整个长表

“longtblr”表内的“tabular”表的期望输出。

“表格”表应具有边框,如下所示:

在此处输入图片描述

第一次编辑,在@Jasper Habicht 回答之后

你好@Jasper Habicht,通过使用你的解决方案,我注意到,如果我在环境之前和之后添加一些文本tblr

\begin{tblr}{ |c|c|c| }
   \hline
   cell1 & cell2 & cell3 \\ 
   cell4 & cell5 & cell6 \\ 
   cell7 & cell8 & cell9 \\ 
   \hline
\end{tblr}

其他列(但在同一行)中的文本会上升到行的顶部,即不像以前那样垂直对齐。此外,在现在有表格的同一列中tblr,我可以看到行底部有一些空白空间,我的意思是在到达之前\hline,即在表格正下方的文本下方tblr...

请参见下面的 MWE 和相应的图表:

在此处输入图片描述

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

\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},
            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}
        & F\textsubscript{3}
        \\
        % -------------------------------------------------
    \end{longtblr}
    
\end{document}

第二次编辑

我只是复制粘贴

column{6}={preto={\begin{minipage}{3.5cm}}, appto={\end{minipage}}}

这里:

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

\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={\begin{minipage}{3.5cm}}, appto={\end{minipage}}}
            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}
        & F\textsubscript{3}
        \\
        % -------------------------------------------------
    \end{longtblr}
    
\end{document}

但我得到了这个:

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

第三次编辑

通过替换此命令

column{6}={preto={\begin{minipage}{3.5cm}}, appto={\end{minipage}}}

有了这个,

column{6}={preto={\minipage{3.5cm}}, appto={\endminipage}},

所有的警告都消失了!

非常感谢@Jasper Habicht!

答案1

如果您确实需要嵌套表格,则应将 a 放在tblra 内longtblr(或另一个 内tblr),而不是将tabulars 嵌套在里面。原因是tblr(和longtblr) 环境的排版与tabulars 完全不同,这可能是将后者嵌套在前者内时可能出现问题的原因。tabular用环境替换代码中的环境tblr可解决单元格边框的问题。

此外,您可能不应该在单元格center内使用环境tblr。相反,使用软件包的功能,通过选项将文本居中在特定单元格中。我没有在我的解决方案中展示这一点,因为我认为将嵌套表格居中是没有必要的。

至于为什么你的表格没有居中,答案很简单:它太宽了。在这方面我无法帮助你,但也许减少页边距或选择较小的字体可以帮助你。最后,你的表格不应该比\textwidth页面上文本主体的宽度更宽。

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

\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},
            hlines
        }
        & Day
        & Month
        & Hours
        & Feature 1 
        & Feature 2
        & Feature 3\\
        %-------------------------------------------------
        Friday
        & 5 
        & June
        & 
        & A\textsubscript{1}
        & % A\textsubscript{2}
        \begin{tblr}{ |c|c|c| }
            \hline
             cell1 & cell2 & cell3 \\ 
             cell4 & cell5 & cell6 \\ 
             cell7 & cell8 & cell9 \\ 
             \hline
        \end{tblr}
        & 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}
        & F\textsubscript{3}
        \\
        % -------------------------------------------------
    \end{longtblr}
    
\end{document}

在此处输入图片描述


我不确定您想在单元格中放置什么,但使用 来强化相关单元格可能是一个解决方案(尽管可能不是最好的解决方案)minipage,这样您就可以在里面放置任何您想要的东西。由于我认为第六列中的所有单元格都应该以相同的方式运行,因此我使用了合适的选项以使将来的编码更容易:

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

\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={\begin{minipage}{3.5cm}}, appto={\end{minipage}}},
            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}
        & F\textsubscript{3}
        \\
        % -------------------------------------------------
    \end{longtblr}
    
\end{document}

在此处输入图片描述


如果你的编辑器对语法有意见(事实上,如果你尝试编译代码,你会发现语法并没有错),你可以替换

column{6}={preto={\begin{minipage}{3.5cm}}, appto={\end{minipage}}},

经过

column{6}={preto={\minipage{3.5cm}}, appto={\endminipage}},

这应该可以缓和编辑器的语法验证机制。

相关内容