[Tex/LaTex] ltablex – Multi-column problem

multicolumntables

I have a problem using a multicolumn command in an ltablex environment. When I insert a large amount of text into a multicolumn command the text (and the table) run off of the side of the page. I've included a MWE below to (hopefully) illustrate the problem including all the packages I am using to still get this problem and make the MWE work (my full thesis has many more packages but I went through taking each one out to see if the problem resolved…it didn't).

If the text in the multicolumn command is deleted or replaced by only a few words, everything is fine.

% ************ 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}

I'm using Texniccenter (allegedly) Stable Release 1.0 with Miktex 2.9 on a PC running XP SP3.

I've also asked this question over on the LaTeX Community forum. I'll be sure to update one or the other if I find a solution.

Best Answer

use it this way:

\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}} is the linewidth except the tabular border

Related Question