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 am getting information written by users in many lines, paragraphs, and I have to put those inside a table, I would like to know if it is possible to instruct LaTeX to accept paragraphs inside a column or maybe inside a multicolumn?

If I try to process this

\documentclass{article}

\usepackage[utf8]{inputenc} 
\usepackage{datetime}
\usepackage{array}
\usepackage{longtable}

\usepackage[table]{xcolor}
\usepackage{graphicx}

\usepackage[spanish]{babel}

\setlength{\parindent}{0pt}
\setlength{\parskip}{1em}
\setlength{\textwidth}{17cm}
\setlength{\textheight}{21cm}
\setlength{\columnsep}{1.5pc}


\newenvironment{rtinformation}{
  \begin{longtable}{|m{7cm}|c|m{7cm}|}
  }
  {
    \hline
  \end{longtable}
}

\newcommand{\rtsingle}[1]{
  \hline
  \multicolumn{3}{|p{15cm}|}{#1}\\
}

\newcommand{\rttitlesubsection}[1]{
  \hline
  \multicolumn{3}{c}{ \bf{#1} } \\
}

\newcommand{\rtrowinfo}[2]{
  \hline
  #1: & & #2 \\
}

\newcommand{\rttitlesection}[1]{
  \hline
  \multicolumn{3}{c}{} \\
  \hline
  \multicolumn{3}{|>{\columncolor[rgb]{0.8,0.8,0.8}}c|}{ #1 } \\
  %\multicolumn{3}{|c|}{ #1 } \\
}


\begin{document}
\begin{rtinformation}
  \rttitlesection{This is my section}
  \rtrowinfo{¿Ha realizado alguna gestión respecto de este predio, ante otra entidad?}{Sí}
  \rttitlesubsection{Descripción de gestión:}
  \rtsingle{
    There are 

    plenty

    of paragraphs, the guilty is [table]xcolor
  }

\end{rtinformation}
\end{document}

I get the error

! Paragraph ended before \multicolumn was complete.
<to be read again> 
               \par 

It looks like \usepackage[table]{xcolor} is getting in the middle, is there a replacement for xcolor to put some colored rows in a table? If I comment the inclusion of the package and the lines

\multicolumn{3}{|>{\columncolor[rgb]{0.8,0.8,0.8}}c|}{ #1 } \\
\rttitlesection{This is my section}

Then LaTeX is able to process many paragraphs. Is there a suitable replacement for xcolor?

share|improve this question
2  
Check your input; in your example there's a spurious closed brace after \\. It works for me after deleting it and adding some dummy rows. –  egreg Jan 3 '12 at 22:20
    
thank you, I'm revisiting the complete code, because I had a macro that used the multicolumn, I'm trying to identify the problem to repost –  ikks Jan 3 '12 at 22:36
    
Not the \\, but the brace after it! Moreover, recall that you can't use \\ inside the argument to \multicolumn, use \newline instead. –  egreg Jan 3 '12 at 22:40
    
I published the complete code and found the problem with xcolor, your comments made me debug it to find the real problem, but still to be solved :P –  ikks Jan 3 '12 at 23:13
add comment

1 Answer

up vote 10 down vote accepted

NOTE added February 15, 2012
Version 1.0a of colortbl.sty, released February 13, 2012, addresses and solves the problem, making the patch superfluous (albeit innocuous).


The problem is in colortbl that's loaded when you load xcolor with the option table. This package wrongly redefines \multicolumn without the \long prefix.

A patch is the following magic trick to be written in the preamble somewhere after loading xcolor (or colortbl):

\begingroup
\toks0=\expandafter{\multicolumn{#1}{#2}{#3}}
\edef\x{\endgroup
  \long\def\noexpand\multicolumn##1##2##3{\the\toks0 }}\x

It's clearly a bug of colortbl.

Explanation of the trick

While the simplest thing to do is to copy the definition of \multicolumn one finds on lines 121-144 of colortbl.sty and adding \long in front of \def, the above trick accomplishes the same thing and is shorter. Moreover it will work flawlessly even if colortbl.sty were modified not only to add \long.

We need to know that \multicolumn wants three arguments. So we open a group and inside it set the token register \toks0 to contain the replacement text of \multicolumn, by giving it dummy arguments. By the rules of TeX, the # symbols are doubled. Then we define \x to define \multicolumn with the requested \long prefix and the stored replacement text. The \endgroup will be executed only when \x is expanded so the net effect is exactly what we wanted. Before the trick \show\multicolumn would show

\multicolumn=macro:
#1#2#3->\multispan <...>

After it it would show

\multicolumn=\long macro:
#1#2#3->\multispan <...>

where <...> stands for the same token list in both cases.


Another similar (but more complicated) trick can be found in this other answer

\def\longpatch#1{\expandafter\getparts\meaning#1\longpatch
  \begingroup\edef#1{\long\def\noexpand#1\the\toks0 {\the\toks2}}%
  \scantokens\expandafter{\expandafter\endgroup#1}}
\def\getparts#1:#2->#3\longpatch{\toks0={#2}\toks2={#3}}
\makeatletter
\longpatch\multicolumn
\makeatother

(The \makeatletter-\makeatother pair is necessary as \multicolumn uses @-commnds in its replacement text.

share|improve this answer
    
@DavidCarlisle You probably are interested in this answer –  egreg Jan 10 '12 at 16:12
    
sorry I wasn't tracking this site when this was posted, I'll fix the package at source. –  David Carlisle Feb 12 '12 at 19:45
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.