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 two tables I am typesetting above each other as follows.

\documentclass[a4paper,11pt]{article}
\usepackage{tabularx}
\usepackage[left=2cm, right=2cm, bmargin=1.5cm]{geometry}

\begin{document}
\begin{tabularx}{\textwidth}{| X | X | l | l | l | l | l | l |}
\hline
   & Cost Category & Year 1 & Year 2 & Year 3 & Year 4 & Year 5 & Total (Y1-5) \\
\hline
\noalign{\vspace{0.5cm}}
\hline
\multicolumn{7}{|l|}{Some text that goes on and on and on and on and on and on and on and on and on and on} & $100\%$\\
\hline
\end{tabularx}
\end{document}

How can I get the text in the bottom table to word wrap rather than push the column over the right hand edge of the page? Basically, I would like it to take on whatever size the top table has already set for the first 7 columns.

share|improve this question
add comment

1 Answer 1

up vote 9 down vote accepted

the width of the first seven column is \textwidth minus the last column and the \tabcolsep/\fboxrule: \textwidth-4\tabcolsep-\widthof{Total (Y1-5)}-2\fboxrule}. Without tabularx the rules are not taken into account.

\documentclass[a4paper,11pt]{article}
\usepackage{tabularx,calc}
\usepackage[left=2cm, right=2cm, bmargin=1.5cm]{geometry}

\begin{document}
\begin{tabularx}{\textwidth}{| X | X | l | l | l | l | l | l |}
\hline
   & Cost Category & Year 1 & Year 2 & Year 3 & Year 4 & Year 5 & Total (Y1-5) \    \hline
\noalign{\vspace{0.5cm}}
\hline
\multicolumn{7}{|p{\textwidth-4\tabcolsep-\widthof{Total (Y1-5)}-2\fboxrule}|}{Some text that goes on and on and on and on and on and on and on and on and on and on} & $100\%$\    \hline
\end{tabularx}
\end{document}

Something like \multicolumn{7}{|X|}{ is possible but makes no sense. It uses the width of all 7 cells but not for the text itself.

share|improve this answer
    
Perfect, thanks. Is there a list of values such as \tabcolsep, \widthof, \fboxrule somewhere along with their descriptions? –  Raphael Oct 11 '11 at 13:53
    
Read any LaTeX book or LaTeX indrocduction. You can out the current values in your document with \the\tabcolsep –  Herbert Feb 9 at 10:38
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.