使表格跨越多页 - 包交互阻止使用 longtable 作为直接替换

使表格跨越多页 - 包交互阻止使用 longtable 作为直接替换

我有一个表格,它依赖于许多包来实现所需的外观,具体来说:

  • 将文本缩放到特定(较小)尺寸
  • 强制换行而不是进一步缩小文本
  • 增加不同行之间的空间以区分包装物品
  • 禁用右对齐和连字符以获得更整洁的外观

我发现表格最终需要跨越多个页面,但在这种情况下 longtable 并不是 tabular 的替代品,而且我对所涉及的包数量感到困惑。我怎样才能实现所需的效果(表格跨越多个页面,同时保留所有其他可视元素,包括浮动标题)?第二个问题是,我写的内容可以以某种方式简化吗?

\documentclass{scrartcl}
\usepackage{booktabs,array,parskip,adjustbox,enumitem}
\usepackage[UKenglish]{babel}
\newcolumntype{x}[1]{>{\raggedright}p{#1}}
\begin{document}


\begin{table}
\begin{hyphenrules}{nohyphenation}
\renewcommand{\arraystretch}{1.5}
\caption{Example table}\label{tab:example}
\centering
\begin{adjustbox}{width=1\textwidth}
\begin{tabular}{x{.2\columnwidth}@{\hskip 6\tabcolsep}x{.4\columnwidth}@{\hskip 6\tabcolsep}x{.4\columnwidth}}
\toprule
{\textbf{Column One}} & {\textbf{Column Two}} & {\textbf{Column Three}}
\tabularnewline
\midrule

ABC &
\begin{itemize}[leftmargin=*]
\item This is an item in column two.
\item This is another item in column two.
\end{itemize} &
\begin{itemize}[leftmargin=*]
\item Here is something in column three:
  \begin{itemize}
  \item It
  \item consists
  \item of
  \item many
  \item different
  \item lines
  \end{itemize}
\end{itemize}
\tabularnewline

DEF &
\begin{itemize}[leftmargin=*]
\item Additional blah blah making for a long sentence spanning multiple lines.
\item Another item.
\item Continuing the theme of items in column two.
\end{itemize} &
\begin{itemize}[leftmargin=*]
\item Here we also have a rather long item that needs multiple lines to fit.
\item Yet another item.
\item Blah, blah:
  \begin{itemize}
  \item It's a very long example of a sub-item in this column, here
  \item Yet more
  \end{itemize}
\end{itemize} 
\tabularnewline

GHI &
\begin{itemize}[leftmargin=*]
\item Another long, long long long long long long long long long long long
block of text.
\item This particular one is medium-medium medium in lenght.
\item This sentence means nothing in particular, it's blah.
\end{itemize} &
\begin{itemize}[leftmargin=*]
\item Blah
\end{itemize} 
\tabularnewline

JKL &
\begin{itemize}[leftmargin=*]
\item Blah, blah, blah, blah, blah.
\item Putting in fake data gets tedious.
\item Reading it is probably more boring still.
\end{itemize} &
\begin{itemize}[leftmargin=*]
\item Blah
\end{itemize}
\tabularnewline

MNO &
\begin{itemize}[leftmargin=*]
\item This was also a really long item so I am going to type and type and
type until I run out of words.
\end{itemize} &
\begin{itemize}[leftmargin=*]
\item Blah
\item Can
\item we
\item span
\item multiple
\item pages
\item with
\item lots
\item of
\item text?
\item Becauase
\item this
\item really
\item needs
\item to
\item be
\item multipage.
\end{itemize}
\tabularnewline

\bottomrule
\end{tabular}
\end{adjustbox}
\renewcommand{\arraystretch}{1}
\end{hyphenrules}
\end{table}

\end{document}

LaTeX 示例的输出

答案1

第一页:

在此处输入图片描述

第二页:

在此处输入图片描述

MWE(在序言中仅被视为使用过的包):

\documentclass{scrartcl}

\usepackage{enumitem}
\usepackage{array, booktabs, longtable}
\newcolumntype{x}[1]{>{\raggedright}p{#1}}

\usepackage{etoolbox}
\AtBeginEnvironment{longtable}{%
    \setlist[itemize]{nosep,     % <-- new list setup
                      topsep     = 0pt       ,
                      partopsep  = 0pt       ,
                      leftmargin = *         ,
                      label      = $\bullet$ ,
                      before     = \vspace{-\baselineskip},
                      after      = \vspace{-0.5\baselineskip}
                        }
                           }% end of AtBeginEnvironment

%\usepackage{showframe}
\begin{document}
%\renewcommand{\arraystretch}{1.5}
\begin{longtable}{x{\dimexpr.2\columnwidth-2\tabcolsep}
                  x{\dimexpr.4\columnwidth-2\tabcolsep}
                  x{\dimexpr.4\columnwidth-2\tabcolsep}}
%\begin{hyphenrules}{nohyphenation}
    \caption{Example table}\label{tab:example}  \\
\toprule
{\textbf{Column One}} & {\textbf{Column Two}} & {\textbf{Column Three}}
\tabularnewline
\midrule
    \endfirsthead
%%%%
    \caption{Example table (cont.)}\label{tab:example}  \\
\toprule
{\textbf{Column One}} & {\textbf{Column Two}} & {\textbf{Column Three}}
\tabularnewline
\midrule
    \endhead
%%%%
\midrule[\heavyrulewidth]
\multicolumn{3}{r}{\footnotesize\itshape
                   Continue on the next page}
    \endfoot
%%%%
\bottomrule
    \endlastfoot
%%%%
ABC &
\begin{itemize}
\item This is an item in column two.
\item This is another item in column two.
\end{itemize} &
\begin{itemize}
\item Here is something in column three:
    \bigskip
  \begin{itemize}
  \item It
  \item consists
  \item of
  \item many
  \item different
  \item lines
  \end{itemize}
\end{itemize}
\tabularnewline\addlinespace

DEF &
\begin{itemize}
\item Additional blah blah making for a long sentence spanning multiple lines.
\item Another item.
\item Continuing the theme of items in column two.
\end{itemize} &
\begin{itemize}
\item Here we also have a rather long item that needs multiple lines to fit.
\item Yet another item.
\item Blah, blah:
    \bigskip
  \begin{itemize}
  \item It's a very long example of a sub-item in this column, here
  \item Yet more
  \end{itemize}
\end{itemize}
\tabularnewline\addlinespace

GHI &
\begin{itemize}
\item Another long, long long long long long long long long long long long
block of text.
\item This particular one is medium-medium medium in lenght.
\item This sentence means nothing in particular, it's blah.
\end{itemize} &
\begin{itemize}
\item Blah
\end{itemize}
\tabularnewline\addlinespace

JKL &
\begin{itemize}
\item Blah, blah, blah, blah, blah.
\item Putting in fake data gets tedious.
\item Reading it is probably more boring still.
\end{itemize} &
\begin{itemize}
\item Blah
\end{itemize}
\tabularnewline\addlinespace

MNO &
\begin{itemize}
\item This was also a really long item so I am going to type and type and
type until I run out of words.
\end{itemize} &
\begin{itemize}
\item Blah
\item Can
\item we
\item span
\item multiple
\item pages
\item with
\item lots
\item of
\item text?
\item Becauase
\item this
\item really
\item needs
\item to
\item be
\item multipage.
\end{itemize}
\tabularnewline
\end{longtable}

答案2

我会使用 来实现这一点,它将的ltablex功能带到,并用 adequate替换行与行之间的距离。 Bo不应该与表格一起使用。所以这里有一个建议:longtabletabularxarraystretch\addlinespaceadjustbox

\documentclass[UKenglish]{scrartcl}
\usepackage{booktabs,array,parskip, caption, enumitem, ltablex}
\usepackage{babel}
\captionsetup{labelfont = bf}
\keepXColumns

\begin{document}

\begin{hyphenrules}{nohyphenation}%
  \setlist[itemize, 1]{topsep=0pt, before=\vspace{-\baselineskip}\raggedright, after=\vspace{-\baselineskip}}
  \setlist[itemize]{leftmargin=*}
  \setlength\defaultaddspace{2.5ex}
  \begin{tabularx}{\textwidth}{>{\hsize=0.6\hsize}X@{\hskip 5\tabcolsep}>{\hsize=1.2\hsize}X@{\hskip 5\tabcolsep}>{\hsize=1.2\hsize}X}
    \caption{Example table}\label{tab:example} \\
    \addlinespace%[1.5ex]
    \toprule
    {\textbf{Column One}} & {\textbf{Column Two}} & {\textbf{Column Three}} \\
    \midrule
    \endfirsthead
    \multicolumn{3}{c}{Table \thetable{} (continued)} \\
    \addlinespace[1.5ex]
    \toprule
    {\textbf{Column One}} & {\textbf{Column Two}} & {\textbf{Column Three}} \\
    \midrule
    \endhead
    \\
    \midrule
    \multicolumn{3}{r}{\footnotesize To be continued}
    \endfoot
    \\
    \bottomrule
    \endlastfoot
    ABC &
    \begin{itemize}
      \item This is an item in column two.
      \item This is another item in column two.
    \end{itemize} &
    \begin{itemize}
      \item Here is something in column three:
            \begin{itemize}
              \item It
              \item consists
              \item of
              \item many
              \item different
              \item lines
            \end{itemize}
    \end{itemize}
    \\
    \addlinespace
    DEF &
    \begin{itemize}
      \item Additional blah blah making for a long sentence spanning multiple lines.
      \item Another item.
      \item Continuing the theme of items in column two.
    \end{itemize} &
    \begin{itemize}
      \item Here we also have a rather long item that needs multiple lines to fit.
      \item Yet another item.
      \item Blah, blah:
            \begin{itemize}
              \item It's a very long example of a sub-item in this column, here
              \item Yet more
            \end{itemize}
    \end{itemize}
    \\
    \addlinespace
    GHI &
    \begin{itemize}
      \item Another long, long long long long long long long long long long long
            block of text.
      \item This particular one is medium-medium medium in lenght.
      \item This sentence means nothing in particular, it's blah.
    \end{itemize} &
    \begin{itemize}[leftmargin=*]
      \item Blah
    \end{itemize}
    \\
    \addlinespace
    JKL &
    \begin{itemize}
      \item Blah, blah, blah, blah, blah.
      \item Putting in fake data gets tedious.
      \item Reading it is probably more boring still.
    \end{itemize} &
    \begin{itemize}[leftmargin=*]
      \item Blah
    \end{itemize}
    \\
    \addlinespace
    MNO &
    \begin{itemize}
      \item This was also a really long item so I am going to type and type and
            type until I run out of words.
    \end{itemize} &
    \begin{itemize}
      \item Blah
      \item Can
      \item we
      \item span
      \item multiple
      \item pages
      \item with
      \item lots
      \item of
      \item text?
      \item Because
      \item this
      \item really
      \item needs
      \item to
      \item be
      \item multipage.
    \end{itemize}
  \end{tabularx}
\end{hyphenrules}

\end{document}

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

相关内容