0

I have a table which for the first N rows has 6 columns, and then at the end switches to 4 columns, with the left-most column staying unchanged. I am trying to accomplish this using multicolumn at the end.

However, I am having difficulties getting the multicolumn-part to space properly? I realize there are very many questions on here about similar issues, however none of the solutions seem to fix whatever it is I am breaking.

MWE:

 \begin{tabular*}{\textwidth}{r|@{\extracolsep{\fill}}ccccc}
 & A & B & C & D & E\\ 
\hline  
Much text, many words &   0\%    &  0\% (-20)   & 45\% (-10)    & 50\% (+25)    &  5\% ( +5)    \\ 
& \multicolumn{5}{c}{\begin{tabular*}{.6\linewidth}{@{\extracolsep{\fill}} c @{\extracolsep{\fill}} c @{\extracolsep{\fill}} c @{\extracolsep{\fill}}} F & G & H \end{tabular*}} \\ 
Other, quite different words & \multicolumn{5}{c}{\begin{tabular*}{.6\linewidth}{ @{\extracolsep{\fill}} c @{\extracolsep{\fill}} c @{\extracolsep{\fill}} c }  5\% ( +0)   & 70\% (-15)    & 25\% (+15)    \end{tabular*}} \\ 
\end{tabular*}

The above gives me this:

enter image description here I would like to both get the top columns to space evenly, as well as have the bottom columns (F-H) use the A-E space evenly.

I hope the question makes sense.

EDIT: Messing around in paint, this is approximately the arrangement I am going for:

enter image description here

  • 1
    To me the desired layout of the table is not (yet) very clear. Is there any connection between A and F ...? – leandriis May 21 at 8:19
  • Each line describes results from a questionnaire. The first column shows the question, A-E and F-H are the possible responses, the percentages inside the table show the distribution of answers. A-E and F-H are not completely compatible (so, just leaving the B and D columns empty in the bottom row would not be ideal, for instance). – Kaare May 21 at 8:23
3

The following MWE contains two possibilities on how you could present your data. The first one is close to the layout you want toa achieve. In the second, I have included a different type of table, that might help to present the data more clearly (in order to align the numbers, one could also use the siunitx package):

enter image description here

\documentclass{article}
\usepackage{tabularx}
\usepackage{geometry}
\usepackage{calc}
\usepackage{ragged2e}
\usepackage{booktabs}
\newcolumntype{C}{>{\Centering}X}

\begin{document}
\noindent
\begin{tabular}{>{\RaggedRight}p{4cm}|@{}p{\linewidth-4cm-2\tabcolsep-\arrayrulewidth}@{}}
Much text, many words  &    \begin{tabularx}{\linewidth}{CCCCC}
                             A & B & C & D & E \\
                             0\% & 0\% (-20) & 45\% (-10) & 50\% (+25) &  5\% ( +5)\\
                            \end{tabularx} \\
Other, quite different words & \begin{tabularx}{\linewidth}{CCC}
                                 F & G & H \\
                                 5\% ( +0) & 70\% (-15) & 25\% (+15)\\
                               \end{tabularx}\\
\end{tabular}


\bigskip

\begin{tabular}{llrr}
\toprule
Question & Answer & Chosen by & Change\\
\midrule
Much text, many words & A & 0\% \\
                      & B & 0\%  & -20 \\
                      & C & 45\% & -10 \\
                      & D & 50\% & +25 \\
                      & E & 5\%  &  +5 \\ \addlinespace
Other, quite different words & F & 5\%  &  +0 \\
                             & G & 70\% & -15 \\
                             & H & 25\% & +15 \\
\bottomrule
\end{tabular}

\end{document}
1

Whenever one presentation of information seems kludgy, one ought search for a different presentation of the same information that appears more elegant.

  • Perhaps you could use a two column table with the left column for A-H and the right column for your data. In a caption to your table you could then describe what makes A-E contextually unique from F-H.
  • Alternatively, you could separate your table into two distinct tables, placing the information for A-E in one and placing the information for F-H in another.
  • Etc.

If you absolutely want to stick to what you're doing, you could use this MWE to meet your specification. To do that, I calculated the LCM of the columns taken up by A-E and the columns taken up by F-H, then used the LCM to be the total number of individual columns. Then for each of the cells A-E and F-H I specified an appropriate divisor of the LCM. Since there are five multicolumns in the first two rows and three multicolumns in the second two rows, the LCM was 15 and so I made each cell for A-E a width of 15/5 = 3 columns and made each cell for F-H a width of 15/3 = 5 columns.

One problem with this MWE is that you might encounter overfull boxes and see your rows extend beyond your table lines depending on how much space you have in your document. When there is sufficient space, this MWE matches up with your mockup.

\documentclass[letterpaper]{article}

\begin{document}
\begin{tabular*}{\textwidth}{r|@{\extracolsep{\fill}}*{15}{c}}
& \multicolumn{3}{c}{A} & \multicolumn{3}{c}{B} & \multicolumn{3}{c}{C} & \multicolumn{3}{c}{D} & \multicolumn{3}{c}{E} \\
\hline
Much text, many words & \multicolumn{3}{c}{0\%} & \multicolumn{3}{c}{0\% (-20)} & \multicolumn{3}{c}{45\% (-10)} & \multicolumn{3}{c}{50\% (+25)} & \multicolumn{3}{c}{5\% (+5)} \\
& \multicolumn{5}{c}{F} & \multicolumn{5}{c}{G} & \multicolumn{5}{c}{H} \\
Other, quite different words & \multicolumn{5}{c}{5\% (+0)} & \multicolumn{5}{c}{70\% (-15)} & \multicolumn{5}{c}{25\% (+15)}
\end{tabular*}
\end{document}

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.