1

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.

1 Answer 1

3

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

2
  • So, \tabcolsep is some fixed width which is the length of the border of the column, beyond which text is not written by default? Could I have a reference for \dimexpr? And why is the \relax necessary? Dec 22, 2011 at 15:39
  • When I want a multicolumn to spread over 2 out of 3 columns, and the other column is 4cm wide, this becomes: \multicolumn{2}{p{\dimexpr\linewidth-4\tabcolsep\relax-4cm}}{long content}, i.e., subtracting the first column from the \linewidth and adjusting the number of \tabcolsep.
    – Marie. P.
    Mar 18, 2020 at 9:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .