ltablex - 多列问题

ltablex - 多列问题

我在 ltablex 环境中使用多列命令时遇到问题。当我将大量文本插入多列命令时,文本(和表格)会超出页面的一侧。我在下面添加了一个 MWE 来(希望)说明问题,其中包括我使用的所有软件包,但仍然遇到此问题并使 MWE 正常工作(我的完整论文包含更多软件包,但我尝试将每个软件包都取出来看看问题是否解决...但并未解决)。

如果多列命令中的文本被删除或者仅用几个词替换,则一切都很好。

% ************ Preamble ****************
\documentclass[a4paper,12pt]{report}
\usepackage[top=2cm, bottom=2cm, left=3.5cm, right=2cm]{geometry} % sets margins
\usepackage{natbib} % for harvard style referencing
\usepackage[margin=10pt, labelfont=bf, format=hang, textfont={small,it}]{caption} %for more interesting captions
\captionsetup[subfigure]{style=default, margin=0pt, labelfont=bf, textfont={small,it}, singlelinecheck=true} % makes subfigure captions a bit more interesting.
\usepackage{multirow} % allows merging of rows in tables
\usepackage{ltablex} % Combines tabularx and longtable functionality
\usepackage{booktabs} % For professional looking tables

% *********** BEGIN! ******************
\begin{document}

\begin{center}
\begin{tabularx}{\textwidth}{p{4cm} p{2.5cm} X}
\caption{My table which I would like to be a summary of some MATLAB\textsuperscript{\textregistered} functions. The table will span a number of pages.}\\
    % First page header of table
    \toprule
    \textbf{Training function} &
    \textbf{MATLAB\textsuperscript{\textregistered} code} &
    \textbf{Description} \\
    \midrule 
\endfirsthead
    %subsequent page header of table
    \toprule
    \textbf{Training function} &
    \textbf{MATLAB\textsuperscript{\textregistered} code} &
    \textbf{Description} \\
    \midrule 
\endhead
    %footer for all but last page of table
    \multicolumn{3}{r}{\small\sl continued on next page\ldots}\\
    \bottomrule
\endfoot
    %footer for last page of table
    \bottomrule
\endlastfoot

% Table contents
Some text & \texttt{train} & null.\\
More text & \texttt{traingd} & null\\
A bit more text & \texttt{traingdm} & null\\
\multicolumn{3}{l}{Here is the text that is too long for the table. If I insert ``null'' instead of all this text, the table is fine. However, the text I would like to put in here is about 100 words long. Repeat: Here is the text that is too long for the table. If I insert ``null'' instead of all this text, the table is fine. However, the text I would like to put in here is about 100 words long. Repeat: Here is the text that is too long for the table. If I insert ``null'' instead of all this text, the table is fine. However, the text I would like to put in here is about 100 words long.}\\
\multirow{3}{*}{Multirow Text} & Text & Blah \\
& blah & blah \\
& more blah & blah \\
\label{label}
\end{tabularx}
\end{center}

\end{document}

我在运行 XP SP3 的 PC 上使用 Texniccenter(据称)稳定版本 1.0 和 Miktex 2.9。

我也在 LaTeX 社区论坛上问过这个问题。如果我找到解决方案,我一定会更新其中一个。

答案1

请按如下方式使用:

\multicolumn{3}{p{\dimexpr\textwidth-2\tabcolsep\relax}}{Here is the text that is too 
long for the table. If I insert ``null'' instead of all this text, the table is fine.
However, the text I would like to put in here is about 100 words long. Repeat: Here is the
text that is too long for the table. If I insert ``null'' instead of all this text, the 
table is fine. However, the text I would like to put in here is about 100 words long. Repeat:
Here is the text that is too long for the table. If I insert ``null'' instead of all this
text, the table is fine. However, the text I would like to put in here is about 100 words
long.}\\

p{\dimexpr\textwidth-2\tabcolsep\relax}}是除表格边框之外的线宽

相关内容