在 tabularx 环境中实现分页符

在 tabularx 环境中实现分页符

请考虑以下示例以便更好地理解。我希望 LaTex 在 tabularx 环境中使用分页符,这样内容的一部分\LongText将显示在第一页,其余部分将显示在第二页。也许有另一个有用的包用于长表格中的分页符,或者一个完整的其他包适合我的目的:正文中的词汇表。

\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage{tabularx}

\usepackage{lipsum}

\begin{document}

\newenvironment{foo}{\tabularx{\textwidth}{p{2cm}X}}{\endtabularx}

\newcommand{\LongText}{This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text.}

\lipsum[1-3]

\begin{foo}
Whatever & \LongText \\
Something else & \LongText \LongText
\end{foo}

\end{document}

答案1

最直接结合longtable和的包tabularx(与这两个包是同一作者)是ltxtable。但是它和都tabu不会在这里做你想做的事情,我认为就是拆分之内表格的行。这在 TeX 中很难实现,并且只能在非常受限的情况下才能实现。(考虑一个有许多列的一般表格,其中一些列可能有图像或嵌套表格),找到一个在同一位置拆分每列的地方通常非常困难。

如果你的真实的示例如图所示,两列表格,第一列只有一行条目,不要使用表格布局,而是使用列表LaTeX 列表可以轻松实现该布局,并自然地允许项目内分页。

\documentclass{article}
\usepackage[ngerman]{babel}


\usepackage{lipsum}

\begin{document}

\newenvironment{foo}{\tabularx{\textwidth}{p{2cm}X}}{\endtabularx}

\newcommand{\LongText}{This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text.}

\lipsum[1-3]
\newenvironment{mylist}[1]% #1 is widest label
     { \list{}%
           {\settowidth\labelwidth{{#1}}%
            \leftmargin\labelwidth
            \advance\leftmargin\labelsep}%
}{\endlist}



\begin{mylist}{Something else}
\item[Whatever]  \LongText 
\item[Something else] \LongText \LongText
\end{mylist}

\end{document}

在此处输入图片描述

答案2

您应该查看一下tabu提供longtabu所需环境的包(将表格拆分到多个页面上)。

然而正如 David 指出的那样,它不会跨页面拆分单元格。

或者,另一种解决方案是使用parallel包:

\documentclass[a4paper,12pt]{article}

\usepackage {lipsum}
\usepackage {calc}
\usepackage {parallel}

\begin{document}

\begin{Parallel}{2cm}{\textwidth-3cm}
   \ParallelLText{test 1}
   \ParallelRText{\lipsum[1-4]}
   \ParallelPar
   \ParallelLText{test 2}
   \ParallelRText{\lipsum[1-4]}
   \ParallelPar
   \ParallelLText{test 2}
   \ParallelRText{\lipsum[1-4]}
\end{Parallel}

\end{document}

在此处输入图片描述

答案3

对于其他答案中描述的表格类型,该enumitem包提供了一个优雅的解决方案:

\documentclass{article}
\usepackage{enumitem}
\usepackage {lipsum}
\begin{document}
\begin{description}[leftmargin=10em,style=nextline]
  \item[Whatever] \lipsum[1]
  \item[Something else] \lipsum[1]
\end{description}
\end{document}

相关内容