Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

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

share|improve this answer
    
Brilliant. Thank you so much for that. –  Jon Aug 30 '11 at 18:34
    
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? –  Faheem Mitha Dec 22 '11 at 15:39
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.