大文本溢出到长表+多行中的下方单元格,并带有 Overfull \vbox

大文本溢出到长表+多行中的下方单元格,并带有 Overfull \vbox

我对 LaTeX 还很陌生,在用 LaTeX 编写包含一些大文本的表格时遇到了很大困难。

我的目标是绘制一个 7 列 17 行的表格。每行细分为 2 行多行,横跨第 2 列至第 4 列。第 5、6 和 7 列中的一些单元格横跨两行,以减少重复文本(见下图)。

由于表格太大,无法放在一页中,因此我使用长桌包,为了调整表格的外观,我还使用了景观(景观),大批多行用于调整表格外观和一些多列单元格排列的包。

问题是,一些包含大文本的单元格溢出到了下面的单元格,而不是拉伸其行高。不使用该命令时似乎不会发生此问题multirow{}{}{}

我在这个论坛和其他论坛上搜索了解决方案,也浏览了前面提到的软件包手册(以及表格等等),但在打开了比我愿意承认的更多的标签后,我放弃了。有人可能会建议改变表格的整体设计,甚至把它分成更小的列块,但我别无选择。从 Excel 导出后,表格在 PDF 中看起来还不错,所以我可以使用\includepdfpdf页面,但这只是最后的手段。

下面的图片是我表格的前几行在 Excel 中的样子:

我的表格的前几行是什么样子的

下面的 MWE 使用包利普萨姆间歇地生成一些虚拟的占位符文本(而不是原始文本):

\documentclass{article}
\usepackage{longtable}
\usepackage{array}
\usepackage{multirow}
\usepackage[left=2.00cm, right=2.00cm, top=2.00cm, bottom=2.00cm]{geometry}
\usepackage{lscape}
\usepackage{lipsum} % For dummy text
\begin{document}
\newcommand\columnA{0.2\textwidth}
\newcommand\columnB{0.11\textwidth}
\newcommand\columnC{0.13\textwidth}
\newcommand\columnD{0.13\textwidth}
\newcommand\columnE{0.13\textwidth}
\newcommand\columnF{0.3\textwidth}
\newcommand\columnG{0.13\textwidth}
\begin{landscape}
\begin{small}
\begin{longtable}[c]{@{\extracolsep{\fill}}
    >{\raggedright\arraybackslash}m{\columnA}
    >{\centering\arraybackslash}m{\columnB}
    >{\centering\arraybackslash}m{\columnC}
    >{\centering\arraybackslash}m{\columnD}
    >{\centering\arraybackslash}m{\columnE}
    >{\centering\arraybackslash}m{\columnF}
    >{\centering\arraybackslash}m{\columnG}
    @{}}
\caption{A very big ugly table.\label{table1}}\\

\multirow{2}{\columnA}{\textbf{Study design}} & \multicolumn{3}{c}{\textbf{Participants}} & \multirow{2}{\columnE}{\textbf{Device name (Control options)}} & \multirow{2}{\columnF}{\textbf{User-environment interaction}} & \multirow{2}{\columnG}{\textbf{Type of outcomes assessed}} \\ \cline{2-4}
& \textbf{N} & \textbf{Description*} & \textbf{Diagnosis} & & & \\ \hline
\multicolumn{7}{c}{\textbf{Some category here}} \\ \hline
\endfirsthead
% additional pages' table head rows go here
\endhead
% additional pages' table foot rows go here...
\endfoot
\hline
\multicolumn{7}{l}{Table foot row 1}\\
\multicolumn{7}{l}{* Another foot row 2 \lipsum[10][2] }\\
\endlastfoot

\multirow{2}{\columnA}{Row 1 \lipsum[1][1]} & \textbf{Cases: 4} & \lipsum[1][2] & \lipsum[1][3] & \multirow{2}{\columnE}{\lipsum[1][4]} & \multirow{2}{\columnF}{\lipsum[1][5]} & \multirow{2}{\columnG}{\lipsum[1][6]} \\
& \textbf{Controls: 4} & Not reported & Just three words & & & \\
\multirow{2}{0.2\textwidth}{Row 2 \lipsum[2][1-2]} & \textbf{Cases: 10} & \lipsum[2][2] & \lipsum[2][3] & \multirow{4}{\columnE}{Quite long multirow tex:t \lipsum[2][4]} & \multirow{4}{\columnF}{Super long text \lipsum[2][1-15]} & \multirow{2}{\columnG}{\lipsum[2][6]} \\
& \textbf{Controls: -} & - & - & & & \\
\multirow{2}{\columnA}{Row 3 \lipsum[3][1]} & \textbf{Cases: 1} & two words & some more & & & \multirow{2}{\columnE}{Not that many words here either} \\
& \textbf{Controls: -} & - & - & & & \\
\multirow{2}{\columnA}{Row 4 \lipsum[4][1]} & \textbf{Cases: 9} & \lipsum[4][5] & Good & \multirow{2}{\columnE}{Couple of words} & \multirow{4}{\columnF}{Another short phrase with few words} & \multirow{2}{\columnG}{Yet another short text \& Only two words} \\
& \textbf{Controls: 20} & \lipsum[4][7] & Two words again & & & \\
\multirow{2}{\columnA}{Row 5 \lipsum[5][1-3]} & \textbf{Cases: 4} & something short & Bad & \multirow{2}{\columnE}{Something relatively short but not tiny} & & \multirow{2}{\columnG}{Again, something not that long} \\
& \textbf{Controls: -} & - & - & & & \\
\multirow{2}{\columnA}{Row 6 \lipsum[6][1]} & \textbf{Cases: 3} & \lipsum[6][2] & \lipsum[6][3] & \multirow{2}{\columnE}{\lipsum[6][4]} & \multirow{2}{\columnF}{\lipsum[6][5-10]} & \multirow{2}{\columnG}{Learning skills} \\
& \textbf{Controls: 3} & Short text & A few words & & & \\
\end{longtable}
\end{small}
\end{landscape}
\end{document}

输出结果如下: 在此处输入图片描述

我尝试了这些以及许多其他类似问题的解决方案,但我无法重现任何可行的解决方案,或者我遇到了编译错误并且无法进一步深入这个兔子洞:

长表中带有文字换行列的多行

如何实现包含一些带有长文本的单元格的表格?

分页时将多行文本居中并放置在 longtabu 中的每一页上

我是新来的,所以欢迎对我写帖子的方式或问题本身提出任何批评,如果需要,我很乐意重新编辑它。提前谢谢!

答案1

  • 提出的解决方案模仿excel图像(在这个复杂的结构化表中这有一定意义)
  • m{...}我建议使用p{...}类型而不是列类型
  • 由于某些单元格中文本较长且有多行,因此使用较小的字体大小是明智的,例如\small
  • 对于水平规则的使用XhlineXcline在 makecell 包中定义的规则
  • 为了在单元格内容周围留出更多垂直空间,使用了包\makegapedcells中定义的宏makecell
  • 而是定义列类型和宽度的命令,定义新的列类型,以便简单规定表格宽度的份额(在横向方向上假设等于\textheight
  • 在空单元格中插入定义其高度的规则(参见下面的 MWE)
  • 对于multirow细胞被认为是 sinax\multirow[t]{<number of spanned lines>}{=}{<content>}
  • 对于单元格\multicolumn{7}{|c|}{\textbf{Some category}}不清楚,它是否是表格标题的一部分,每个标题中都有固定的大小写,或者可以插入表格中的任何位置并带有适当的文本(在 MWE 中被视为前一种情况)

梅威瑟:

\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage{ragged2e}
\usepackage{array, longtable, 
            makecell,   % new
            multirow}
\renewcommand\theadfont{\footnotesize\bfseries}
\renewcommand\theadgape{}
\newcolumntype{L}[1]{>{\RaggedRight\hspace{0pt}}p{\dimexpr#1\linewidth-2\tabcolsep-\arrayrulewidth}}


\usepackage{pdflscape}
\usepackage{lipsum} % For dummy text

\begin{document}
    \begin{landscape}
    \vfil
\setcellgapes{3pt}
\makegapedcells
\small\linespread{0.84}\selectfont  % <---
\setlength\tabcolsep{2pt}
\begin{longtable}[c]{| 
                     L{0.13}| L{0.09} | L{0.09}| L{0.08}|  L{0.12}| L{0.36}| L{0.13}|
                     }
\caption{A very big ugly table.}
\label{table1}                                                                      \\
    \Xhline{1.2pt}
\multirow{2.8}{=}{\thead{Study\\ design}}
    &   \multicolumn{3}{c|}{\thead{Participants}}
                &   \multirow{2.8}{=}{\thead{Device name\\ (Control options)}}
                    &   \multirow{2.8}{=}{\thead{User-environment\\ interaction}}
                        &   \multirow{2.8}{=}{\thead{Type of outcomes\\ assessed}}  \\
    \Xcline{2-4}{0.6pt}
    &   \thead{N} 
        &   \thead{Description*} 
            &   \thead{Diagnosis} 
                &   &   &                                                           \\ 
    \Xhline{0.6pt}
\multicolumn{7}{c}{\textbf{Some category}}                                          \\
    \Xhline{0.6pt}
\endfirsthead
\caption[]{A very big ugly table.}                                                  \\
    \Xhline{1.2pt}
\multirow{2.8}{=}{\thead{Study\\ design}}
    &   \multicolumn{3}{c|}{\thead{Participants}}
                &   \multirow{2.8}{=}{\thead{Device name\\ (Control options)}}
                    &   \multirow{2.8}{=}{\thead{User-environment\\ interaction}}
                        &   \multirow{2.8}{=}{\thead{Type of outcomes\\ assessed}}  \\
    \Xcline{2-4}{0.6pt}
    &   \thead{N}
        &   \thead{Description*}
            &   \thead{Diagnosis}
                &   &   &                                                           \\
    \Xhline{0.6pt}
\multicolumn{7}{c}{\textbf{Some category}}                                          \\
    \Xhline{0.6pt}
\endhead
    \multicolumn{7}{r}{\footnotesize\itshape{Continue is on the next page}}         %?
\endfoot
    \Xhline{1.2pt}
\endlastfoot
% table body
\multirow[t]{5}{=}{Row 1 \lipsum[1][1]} 
    & \textbf{Cases: 4}
        &   \lipsum[1][2] 
            &   \lipsum[1][3] 
                &   \lipsum[1][4] 
                    & \lipsum[1][5] 
                        &   \multirow[t]{5}{=}{\lipsum[1][6]}                       \\
    \Xcline{2-4}{0.6pt}
    &   \textbf{Controls: 4} 
        &   Not reported 
            &   Just three words 
                &   &   &                                                           \\
    \Xhline{0.6pt}
\multirow[t]{8}{=}{Row 2 \lipsum[2][1-2]} 
    &   \textbf{Cases: 10}
        &   \lipsum[2][2]
            &   \lipsum[2][3]
                &   \multirow[t]{22}{=}{Quite long multi line text \lipsum[2][4]}
                    &   \multirow[t]{11}{=}{Super long text \lipsum*[2][1-15]}
                        &   \multirow[t]{7}{=}{\lipsum[2][6]}                       \\
    \Xcline{2-4}{0.6pt}
    &   \textbf{Controls: -}
        &   \hfil ---
            &   \hfil \centering ---
                &   &   &                                                           \\                                                         
    \Xcline{1-4}{0.6pt}
    \Xcline{7-7}{0.6pt}
\multirow[t]{2}{=}{Row 3 \lipsum[3][1]}
    & \textbf{Cases: 1}
        & two words
            & some more
                &   &   &   \multirow[t]{2}{=}{Not that many words here either}     \\
    \Xcline{2-4}{0.6pt}
    & \textbf{Controls: -}
        & \hfil ---
            & \hfil ---
                &   &   &                                                           \\
    \Xhline{0.6pt}
\multirow[t]{3}{=}{Row 4 \lipsum[4][1]}
    &   \textbf{Cases: 9}
        &   \lipsum[4][5]
            &   Good
                &   Couple of words
                    &   Another short phrase with few words
                        &   \multirow[t]{3}{=}{Yet another short
                                               text \& Only two words}               \\
    \Xcline{2-4}{0.6pt}
    &   \textbf{Controls: 20}
        &   \lipsum[4][7]
            &   Two words again
                &   &   &                                                           \\
    \Xhline{0.6pt}
\multirow[t]{8}{=}{Row 5 \lipsum[5][1-3]}
    &   \multirow{2}{=}{\textbf{Cases: 4}}
        &   \multirow{2}{=}{something short}
            &   \multirow{2}{=}{Bad}
                &   \multirow{2}{=}{Something relatively short but not tiny}
                    &   \rule[-5.5\baselineskip]{0pt}{-0pt}   % <--- define empty cell height
                        & \multirow{2}{=}{Again, something not that long}           \\
    \Xcline{2-4}{0.6pt}
    &   \textbf{Controls: -}
        & - & - &   &   &                                                           \\
    \Xhline{0.6pt}
\multirow[t]{7}{=}{Row 6 \lipsum[6][1]}
    &   \textbf{Cases: 3}
        &   \lipsum[6][2]
            &   \lipsum[6][3]
                &   \multirow[t]{7}{=}{\lipsum[6][4]}
                    &   \multirow[t]{7}{=}{\lipsum*[6][5-10]}
                        & \multirow[t]{7}{=}{Learning skills}                          \\
     \Xcline{2-4}{0.6pt}
    &   {\textbf{Controls: 3}}
        &   {Short text }
            &   {A few words }
                &   &   &                                                           \\
\end{longtable}
    \end{landscape}
\end{document}

在此处输入图片描述

对于表的最终形式,您需要根据longtable至少两次的特征编译 MWE。

附录:

  • 使用m{...}列类型的版本。它仍然使用makgapedcells宏,但添加了 Ulrike Fisher (修补),这使得它可以在m列类型上工作。

  • 由于行间空间减少,该解决方案需要大量的手动调整:

\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage{ragged2e}
\usepackage{array, longtable,
            makecell,   % new
            multirow}
\renewcommand\theadfont{\footnotesize\bfseries}
\makeatletter
\renewcommand\mcell@classz{\@classx
   \@tempcnta \count@
   \prepnext@tok
   \@addtopreamble{%\mcell@mstyle
      \ifcase\@chnum
         \hfil
         \mcell@agape{\d@llarbegin\insert@column\d@llarend}\hfil \or
         \hskip1sp
         \mcell@agape{\d@llarbegin\insert@column\d@llarend}\hfil \or
         \hfil\hskip1sp
         \mcell@agape{\d@llarbegin \insert@column\d@llarend}\or
         \mcell@agape{$\vcenter
         \@startpbox{\@nextchar}\insert@column\@endpbox$}\or
         \mcell@agape{\vtop
         \@startpbox{\@nextchar}\insert@column\@endpbox}\or
         \mcell@agape{\vbox
        \@startpbox{\@nextchar}\insert@column\@endpbox}%
      \fi
      \global\let\mcell@left\relax\global\let\mcell@right\relax
    }\prepnext@tok}
\makeatother
\renewcommand\theadgape{}

\newcolumntype{L}[1]{>{\RaggedRight\hspace{0pt}}m{\dimexpr#1\linewidth-2\tabcolsep-\arrayrulewidth}}


\usepackage{pdflscape}
\usepackage{lipsum} % For dummy text

\begin{document}
    \begin{landscape}
    \vfil
\setcellgapes{3pt}
\makegapedcells
\small\linespread{0.84}\selectfont  % <---
\setlength\tabcolsep{2pt}
\begin{longtable}[c]{|
                     L{0.13}| L{0.09} | L{0.09}| L{0.08}|  L{0.12}| L{0.36}| L{0.13}|
                     }
\caption{A very big ugly table.}
\label{table1}                                                                      \\
    \Xhline{1.2pt}
\multirow{2.8}{=}{\thead{Study\\ design}}
    &   \multicolumn{3}{c|}{\thead{Participants}}
                &   \multirow{2.8}{=}{\thead{Device name\\ (Control options)}}
                    &   \multirow{2.8}{=}{\thead{User-environment\\ interaction}}
                        &   \multirow{2.8}{=}{\thead{Type of outcomes\\ assessed}}  \\
    \Xcline{2-4}{0.6pt}
    &   \thead{N}
        &   \thead{Description*}
            &   \thead{Diagnosis}
                &   &   &                                                           \\
    \Xhline{0.6pt}
\multicolumn{7}{c}{\textbf{Some category}}                                          \\
    \Xhline{0.6pt}
\endfirsthead
\caption[]{A very big ugly table.}                                                  \\
    \Xhline{1.2pt}
\multirow{2.8}{=}{\thead{Study\\ design}}
    &   \multicolumn{3}{c|}{\thead{Participants}}
                &   \multirow{2.8}{=}{\thead{Device name\\ (Control options)}}
                    &   \multirow{2.8}{=}{\thead{User-environment\\ interaction}}
                        &   \multirow{2.8}{=}{\thead{Type of outcomes\\ assessed}}  \\
    \Xcline{2-4}{0.6pt}
    &   \thead{N}
        &   \thead{Description*}
            &   \thead{Diagnosis}
                &   &   &                                                           \\
    \Xhline{0.6pt}
\multicolumn{7}{c}{\textbf{Some category}}                                          \\
    \Xhline{0.6pt}
\endhead
    \multicolumn{7}{r}{\footnotesize\itshape{Continue is on the next page}}         %?
\endfoot
    \Xhline{1.2pt}
\endlastfoot
% table body
\multirow{4}{=}{Row 1 \lipsum[1][1]}
    & \textbf{Cases: 4}
        &   \lipsum[1][2]
            &   \lipsum[1][3]
                &   \multirow{4}{=}[1ex]{\lipsum[1][4]}
                    & \multirow{4}{=}{\lipsum[1][5]}
                        &   \multirow{-2}{=}{\lipsum[1][6]}                       \\
    \Xcline{2-4}{0.6pt}
    &   \textbf{Controls: 4}
        &   Not reported
            &   Just three words
                &   &   &                                                           \\
    \Xhline{0.6pt}
\multirow{-2}{=}[2ex]{Row 2 \lipsum[2][1-2]}
    &   \textbf{Cases: 10}
        &   \lipsum[2][2]
            &   \lipsum[2][3]
                &   \multirow{-2.4}{=}{Quite long multi line text \lipsum[2][4]}
                    &   \multirow{-3.3}{=}{Super long text \lipsum*[2][1-15]}
                        &   \multirow{3.3}{=}{\lipsum[2][6]}                       \\
    \Xcline{2-4}{0.6pt}
    &   \textbf{Controls: -}
        &   \hfil ---
            &   \hfil \centering ---
                &   &   &                                                           \\
    \Xcline{1-4}{0.6pt}
    \Xcline{7-7}{0.6pt}
\multirow{2}{=}{Row 3 \lipsum[3][1]}
    & \textbf{Cases: 1}
        & two words
            & some more
                &   &   &   \multirow{2}{=}{Not that many words here either}     \\
    \Xcline{2-4}{0.6pt}
    & \textbf{Controls: -}
        & \hfil ---
            & \hfil ---
                &   &   &                                                           \\
    \Xhline{0.6pt}
\multirow{3}{=}{Row 4 \lipsum[4][1]}
    &   \textbf{Cases: 9}
        &   \lipsum[4][5]
            &   Good
                &   \multirow{4}{=}{Couple of words}
                    &   \multirow{4}{=}{Another short phrase with few words}
                        &   \multirow{4}{=}{Yet another short
                                               text \& Only two words}               \\
    \Xcline{2-4}{0.6pt}
    &   \textbf{Controls: 20}
        &   \lipsum[4][7]
            &   Two words again
                &   &   &                                                           \\
    \Xhline{0.6pt}
\multirow{-3.4}{=}{Row 5 \lipsum[5][1-3]}
    &   \multirow{2}{=}{\textbf{Cases: 4}}
        &   \multirow{2}{=}{something short}
            &   \multirow{2}{=}{Bad}
                &   \multirow{2}{=}{Something relatively short but not tiny}
                    &   \rule[-5.5\baselineskip]{0pt}{-0pt}   % <--- define empty cell height
                        & \multirow{3}{=}{Again, something not that long}           \\
    \Xcline{2-4}{0.6pt}
    &   \textbf{Controls: -}
        & - & - &   &   &                                                           \\
    \Xhline{0.6pt}
\multirow{4}{=}{Row 6 \lipsum[6][1]}
    &   \textbf{Cases: 3}
        &   \lipsum[6][2]
            &   \lipsum[6][3]
                &   \multirow{4}{=}{\lipsum[6][4]}
                    &   \multirow{-2}{=}{\lipsum*[6][5-10]}
                        & \multirow{3}{=}{Learning skills}                          \\
     \Xcline{2-4}{0.6pt}
    &   {\textbf{Controls: 3}}
        &   {Short text }
            &   {A few words }
                &   &   &                                                           \\
\end{longtable}
    \end{landscape}
\end{document}

在此处输入图片描述

相关内容