2

I'd like to know if there is a way to reproduce this table

Considerations | Possibilities
Crew size | 2 | 3 | 4 | 5 | 6
Cargo deployment | Pre-deployment | All-up

in the following manner:

  1. "Considerations", "Crew size" and "Cargo Deployment" must be centre aligned in their column;

  2. The remaining elements must be centre aligned and equally spaced in the remaining space (as if 2 | 3 | 4 | 5 | 6, or Pre-deployment | All-up was a single column)

So far, I've tried to use the following piece of code

\begin{table}[htb]
\renewcommand{\arraystretch}{1.2} % more space between rows
\centering
\begin{tabular}{cccccc}
Consideration & \multicolumn{5}{c}{Possibilities} \\
Crew size & 2 & 3 & 4 & 5 & 6 \\
Cargo deployment & \multicolumn{2}{c}{Pre-deployment} & \multicolumn{3}{c}{All-up} \\
\end{tabular}
\caption{What I have so far.}
\end{table}

which produced this:

Table generated by the code

Note how "Pre-deployment" joins the columns for 2 and 3 and "All-up" the columns for 4, 5 and 6. This leads to an unequal horizontal spacing in the crew size line, which is what I'm trying to avoid.

Ideally, I'd be able to input something like

Cargo deployment & \multicolumn{2.5}{c}{Pre-deployment} & \multicolumn{2.5}{c}{All-up} \\

but \multicolumn only accepts integers as an argument.

I'd also like the possibilities for "Cargo deployment" to share the available space between themselves instead of one occupying two columns, and the other one three columns.

Here is a hand-drawn version of what I'm looking for. I've also added red dashed lines to symbolise the separation between cells.

enter image description here

8
  • 1
    Like that? i.stack.imgur.com/qt1tU.png
    – leandriis
    May 22 '20 at 14:34
  • That indeed fixes the spacing in the crew size line, but I'd also pre-deployment and all-up to share the available space between themselves. Sorry, I've just noticed this wasn't on the original post.
    – Jak
    May 22 '20 at 14:40
  • isn't this just a two-column table with \hfill between the items in your second column to space them out? May 22 '20 at 15:01
  • @Jak: It would be great if you could mock up a drawing showing what you want the output to look like. You current description is insufficient...
    – Werner
    May 22 '20 at 15:14
  • @DavidCarlisle Although this might have solved the problem, I've only added the first two rows as an example. Some of them have big lines, which need to be wrapped, and I can't do that with only two columns. Would probably work for small texts though...
    – Jak
    May 22 '20 at 15:41
1

With thanks to this and this question, without need for fixed column widths, just adding \hspace*{\fill}s inside a multicolumn:

\documentclass{article}

\begin{document}

\begin{table}[htb]
\renewcommand{\arraystretch}{1.2} % more space between rows
\centering
\begin{tabular}{|c|c|c|c|c|c|}\hline
Consideration & \multicolumn{5}{c|}{Possibilities} \\ \hline
Crew size & \multicolumn{5}{@{}c@{}|}{\hspace*{\fill} 2 \hspace*{\fill}\vrule\hspace*{\fill} 3 \hspace*{\fill}\vrule\hspace*{\fill} 4 \hspace*{\fill}\vrule\hspace*{\fill} 5 \hspace*{\fill}\vrule\hspace*{\fill} 6 \hspace*{\fill}} \\ \hline
Cargo deployment & \multicolumn{2}{c|}{Pre-deployment} & \multicolumn{3}{c|}{All-up} \\ \hline
\end{tabular}
\caption{Hope this is it.}
\end{table}

\end{document}

screenshot

2
  • This is exactly what I was looking for, thank you very much. As a side note, could you explain me the second multicolumn argument in this line, "\multicolumn{5}{@{}c@{}|}{\hspace*{\fill} 2..."?
    – Jak
    May 22 '20 at 17:20
  • 1
    @Jak It's to remove the padding of the cell, so that there's no extra space to the left of 2 (first @{}) nor to the right of 6 (second @{}). Taken from this answer
    – steve
    May 22 '20 at 17:42
0

This uses David's suggestion of a two-column approach and spreading things out evenly via \hfill:

enter image description here

\documentclass{article}

\usepackage{array,lipsum,makecell}

\begin{document}

\begin{tabular}{c p{8cm} }
   Consideration   & \hfill Possibilities \hfill \mbox{} \\
     Crew size     & \hfill 2 \hfill 3 \hfill 4 \hfill 5 \hfill 6 \hfill \mbox{} \\
  Cargo deployment & \hfill Pre-deployment \hfill All-up \hfill \mbox{} \\
    Whatever else  & \lipsum*[1] \\
      This is      & \hfill \makecell[t]{Here \\ is yet \\ another option} \hfill to try \hfill \mbox{} \\
     Something     & \hfill \makecell{Here \\ is yet \\ another option} \hfill to try \hfill \mbox{} \\
  Very interesting & \hfill \makecell[b]{Here \\ is yet \\ another option} \hfill to try \hfill \mbox{}
\end{tabular}

\end{document}

Note that line wrapping and manual breaks are equally easy to insert within a fixed-width paragraph-style column.

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.