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 the following table:

\documentclass{article}
\usepackage{tabu, longtable}

\begin{document}
\begin{longtabu} to \textwidth {|l|l|l|lX|}

 1 & Column 2 & 3 & \multicolumn{2}{l|}{Description} \\ \hline
 1 & 2 & 3 & A: & Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer eget est id enim vehicula sodales et quis ipsum. \\ \hline

 & & & \multicolumn{2}{p{8cm}|}{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer eget est id enim vehicula sodales et quis ipsum.} \\ \hline

\end{longtabu} 
\end{document}

The last row uses a fixed width for the paragraph (8cm). This does not fit perfectly but shows how the result should look.

My question is: Is it possible to replace the fixed value by something else so Latex calculates the correct width of the last two columns for me?

share|improve this question
    
This is not a duplicate because here the column types are l and X while in the mentioned question both are X. Therefore 2\tabucolX won't work here. –  Severin Oct 10 '12 at 14:59
    
oops sorry I am sure that I have done the general case somewhere on site I think I picked the wrong question. I don't seem to be able to cancel my close vote. tabularx (and I presume tabu) does know all the column widths as it has to disasemble the table after each trial, it's just a bit less convenient to get the other widths, will post later. –  David Carlisle Oct 10 '12 at 15:19
add comment

1 Answer

up vote 1 down vote accepted

enter image description here

Actually what I said in comments wasn't quite right tabularx only really knows the widths of the X columns and the total table width. longtable on the other hand does know (and record in the aux file) all the column widths, tabu is using a mixture of the two so we can use the longtable data:

This could be wrapped up in a nicer interface but basically you need to do:

\documentclass{article}
\usepackage{tabu, longtable}

\begin{document}
\makeatletter
\newdimen\zzz
\ifx\LT@i\@undefined
\zzz=8cm
\else
\global\zzz\z@
\begingroup
\@tempcnta\z@
\def\LT@entry#1#2{%
\advance\@tempcnta\@ne
\ifnum\@tempcnta=4 \global\advance\zzz#2\relax\fi
\ifnum\@tempcnta=5 \global\advance\zzz#2\relax\fi
}
\LT@i
\endgroup
\advance\zzz-2\tabcolsep
\advance\zzz-\arrayrulewidth
\begin{longtabu} to \textwidth {|l|l|l|lX|}

 1 & Column 2 & 3 & \multicolumn{2}{l|}{Description} \\ \hline
 1 & 2 & 3 & A: & Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer eget est id enim vehicula sodales et quis ipsum. \\ \hline

 & & & \multicolumn{2}{l|}{%
\rlap{\parbox[t]{\zzz}{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer eget est id enim vehicula sodales et quis ipsum.}}}\\ \hline

\end{longtabu} 
\end{document}
share|improve this answer
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.