1

I am trying to complete the formatting of this table. I cannot get the text in the final column to wrap and remain in the cell.

The "stuff stuff stuff" text just keeps going off the edge of the page.

Also, I cannot get the heading separators to work.

Any thoughts greatly appreciated.

\usepackage{tabularx}
\usepackage{multirow}


\begin{table}
\centering
\small
\resizebox{\textwidth}{!}{

    \begin{tabularx}{\textwidth}{|X|X|X|X|X|}
\hline
\rowcolor[HTML]{C0C0C0}
Section & Sub-Section & Description & \multicolumn{2}{l|}{Key} \\ \hline
& Stage & The  & Stuff & \\ \cline{2-4} 
& Stuff  & The & Stuff & \\ \cline{2-4}
\multirow{-3}{*}{Stuff} & Stuff & The  & Cole & \multirow{-3}{*}{Stuff Stuff Stuff Stuff Stuff Stuff Stuff Stuff Stuff } \\ \hline
\end{tabularx}}
\end{table}
  • \resizebox{\textwidth}{!}{ scaling tables is (almost) always wrong, but scaling a table to \textwidth when its size is already forced to \textwidth in the tabularx argument is.. odd (also if you do use \scalebox you need a % and no blank line after the { ) – David Carlisle Oct 23 '14 at 12:05
  • Welcome to Tex.SX! You will have to give the multirow a width. \multirow{-3}{2.3cm}{ for example... (but the last cell is to small to fit all this "stuff" – LaRiFaRi Oct 23 '14 at 12:05
  • 2
    Also please next time make your example a complete document so that people can run it and see the problem. – David Carlisle Oct 23 '14 at 12:06
1

I changed from \small to \scriptsize in order to fit everything in your cells. You may reformat your table with differing width in each row. Or maybe the original text fits for your chosen fontsize.

The main trick was to give the multirow a certain width. As the X-column is stretchable, the multirow does not know the actual width. If you do not want to search this discrete value, you may use \hsize. \hsize works because it happens internally inside the X-column set up for the table and X (and p) sets \hsize so line breaking works correctly within the cell. So you can use \hsize here to tell multirow to use the size that tabularx decided to use.

% arara: pdflatex

\documentclass{article}
\usepackage{tabularx}
\usepackage{multirow}
\usepackage[table]{xcolor}
\usepackage{microtype} % handy in narrow cells with much text

\begin{document}
\begin{table}
    \centering
    \scriptsize       
    \begin{tabularx}{\textwidth}{|X|X|X|X|X|}
        \hline
        \rowcolor[HTML]{C0C0C0}
        Section & Sub-Section & Description & \multicolumn{2}{l|}{Key} \\ \hline
        & Stage & The  & Stuff & \\ \cline{2-4} 
        & Stuff  & The & Stuff & \\ \cline{2-4}
        \multirow{-3}{*}{Stuff} & Stuff & The  & Cole & \multirow{-3}{\hsize}{Stuff Stuff Stuff Stuff Stuff Stuff Stuff Stuff Stuff } \\ \hline
    \end{tabularx}
\end{table}
\end{document}

enter image description here

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.