9

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.

11

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.

  • 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 – user2478 Feb 9 '14 at 10:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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