11

I have a table that is quite long (less than a page, by the way) and quite narrow; to save space I wish to have it, let's say, on two columns. Referring to the following image, I wish to have the first 8 entries side by side with the entries 9-16 (note that the letter "A", "B", and so on are added for code readability purpose, in the original table the column "schema" contains a image that increase the rows height).

Example result

The code of the example is as follows:

\documentclass[a4paper]{report}

\usepackage{booktabs}
\usepackage{fullpage}
\usepackage{multirow}
\usepackage[table]{xcolor}
\usepackage{array}
\usepackage[pdftex]{graphicx}

\begin{document}

\begin{table}[htbp]
  \centering
    \begin{tabular}{llp{0.1cm}p{0.1cm}p{0.1cm}p{0.1cm}lp{3cm}}
    \toprule
& & \multicolumn{4}{c}{Parameter} & & \\
ID & Schema & F & E & P & N & \multicolumn{2}{l}{Cluster}\\
    \midrule
1 & A & H & H & H & H & 1 & High performer\\
2 & B & H & H & H & L & 2 & Cash provider\\
3 & C & H & H & L & H & 3 & Alternative means of financing\\
4 & D & H & H & L & L & 4 & Doubtful case\\
5 & E & H & L & H & H & 5 & Low performer\\
6 & F & H & L & H & L & 5 & Low performer\\
7 & G & H & L & L & H & 6 & Possible AMF\\
8 & H & H & L & L & L & 5 & Low performer\\
9 & I & L & H & H & H & 7 & Cash flow optimization\\
10 & L & L & H & H & L & 7 & Cash flow optimization\\
11 & M & L & H & L & H & 8 & SCF needy\\
12 & N & L & H & L & L & 7 & Cash flow optimization\\
13 & O & L & L & H & H & 4 & Doubtful case\\
14 & P & L & L & H & L & 9 & Potential cash provider\\
15 & Q & L & L & L & H & 5 & Low performer\\
16 & R & L & L & L & L & 5 & Low performer\\
    \bottomrule
    \end{tabular}%
  \caption{Cluster identification.}
  \label{clusteridentification}%
\end{table}%

\end{document}

Ok now I know that there are different solutions to this problem:

  • The first would be to "double" the table, with the header that would look like:

    \toprule
    & & \multicolumn{4}{c}{Parameter} & & & & \multicolumn{4}{c}{Parameter} & & \\
    ID & Schema & F & E & P & N & \multicolumn{2}{l}{Cluster} ID & Schema & F & E & P & N & \multicolumn{2}{l}{Cluster}\\
    \midrule

    Anyway, this solution is not very flexible, and won't be easy to manipulate the table in the future (and it's probable that I'll have to do it, and let's say it: it's ugly)

  • The twocolumn environment is out of discussion, because the rest of the page must be written as the rest of the document, on one column.

  • The minipage structure gives problems with the \table environment: I cannot compile the document!

  • 3
    You can automatically split the table in two if you use longtable: tex.stackexchange.com/questions/45980/… – David Carlisle Jul 23 '12 at 9:05
  • @DavidCarlisle thanks, I was convinced that a mulicolumns environment should be set for the whole page (like landscape), but actually with the flexibility of latex it does not make a lot of sense... – scannerdarkly Jul 23 '12 at 13:33
10

While I was writing my question, I came out with the solution. If I understood correctly, it is encouraged for user of this (rather awesome) website to answer their own question, therefore, even if I think that my question is quite trivial, here I go:

The minipage construct is the solution: it just needs to be within the table environment. The correct code to achieve what I wished is:

\begin{table}
\begin{minipage}[t]{0.5\linewidth}
    \begin{tabular}[t]{llp{0.1cm}p{0.1cm}p{0.1cm}p{0.1cm}lp{3cm}}
    \toprule
& & \multicolumn{4}{c}{Parameter} & & \\
ID & Schema & F & E & P & N & \multicolumn{2}{l}{Cluster}\\
    \midrule
1 & A & H & H & H & H & 1 & High performer\\
2 & B & H & H & H & L & 2 & Cash provider\\
3 & C & H & H & L & H & 3 & Alternative means of financing\\
4 & D & H & H & L & L & 4 & Doubtful case\\
5 & E & H & L & H & H & 5 & Low performer\\
6 & F & H & L & H & L & 5 & Low performer\\
7 & G & H & L & L & H & 6 & Possible AMF\\
8 & H & H & L & L & L & 5 & Low performer\\
    \bottomrule
    \end{tabular}%
\end{minipage}
\begin{minipage}[t]{0.5\linewidth}
    \begin{tabular}[t]{llp{0.1cm}p{0.1cm}p{0.1cm}p{0.1cm}lp{3cm}}
    \toprule
& & \multicolumn{4}{c}{Parameter} & & \\
ID & Schema & F & E & P & N & \multicolumn{2}{l}{Cluster}\\
    \midrule
9 & I & L & H & H & H & 7 & Cash flow optimization\\
10 & L & L & H & H & L & 7 & Cash flow optimization\\
11 & M & L & H & L & H & 8 & SCF needy\\
12 & N & L & H & L & L & 7 & Cash flow optimization\\
13 & O & L & L & H & H & 4 & Doubtful case\\
14 & P & L & L & H & L & 9 & Potential cash provider\\
15 & Q & L & L & L & H & 5 & Low performer\\
16 & R & L & L & L & L & 5 & Low performer\\
    \bottomrule
    \end{tabular}%
\end{minipage}
\caption{caption}
\end{table}

Of course small adjustments to properly fit the text are needed, but it works.

  • 1
    I suggest to change \begin{minipage}[c] to \begin{minipage}[t] and \begin{tabular}{...} to \begin{tabular}[t]{...} so that the two top rules will be aligned anyway. Try and get both tables the same height; if it's not possible, the longest one should be the on the left. – egreg Jul 23 '12 at 9:02
  • @egreg Added. It would have been my next question, actually :D – scannerdarkly Jul 23 '12 at 13:35
  • You wrote, "Of course small adjustments to properly fit the text are needed". Actually, depending on the page size at hand, the adjustments needed to make the material fit could be quite significant. For instance, there's currently no guarantee that the tabular environments will even fit inside the minipage environments! – Mico Jul 13 '17 at 8:52
1

The only column in which line breaks appear to make sense (and, indeed, appear to be required!) is the final column. Thus, instead of providing two side-by-side minipage environments, each one containing a tabular environment with several columns of type p, I suggest you use two, side-by-side tabularx environments, with seven columns of type l and one column -- the final one -- being of type X.

I would also provide more visual structure to the header material.

enter image description here

\documentclass[12pt]{article}
\usepackage{tabularx,booktabs,ragged2e}
\usepackage[a4paper,margin=2.5cm]{geometry} % <-- choose suitable text block parameters

\begin{document}
\begin{table}
\setlength{\tabcolsep}{3pt} % default value is 6pt
\begin{tabularx}{0.48\textwidth}[t]{@{}*{7}{l}>{\RaggedRight}X@{}}
\toprule
ID & Schema & \multicolumn{4}{c}{Parameter} & \multicolumn{2}{l}{Cluster}\\
\cmidrule{3-6}
& & F & E & P & N \\
\midrule
1 & A & H & H & H & H & 1 & High performer\\
2 & B & H & H & H & L & 2 & Cash provider\\
3 & C & H & H & L & H & 3 & Alternative means of financing\\
4 & D & H & H & L & L & 4 & Doubtful case\\
5 & E & H & L & H & H & 5 & Low performer\\
6 & F & H & L & H & L & 5 & Low performer\\
7 & G & H & L & L & H & 6 & Possible AMF\\
8 & H & H & L & L & L & 5 & Low performer\\
\bottomrule
\end{tabularx}%
\hspace*{\fill} % maximize separation between the tabulars
\begin{tabularx}{0.48\textwidth}[t]{@{}*{7}{l}>{\RaggedRight}X@{}}
\toprule
ID & Schema & \multicolumn{4}{c}{Parameter} & \multicolumn{2}{l}{Cluster}\\
\cmidrule{3-6}
& & F & E & P & N \\
\midrule
9 & I & L & H & H & H & 7 & Cash flow optimization\\
10 & L & L & H & H & L & 7 & Cash flow optimization\\
11 & M & L & H & L & H & 8 & SCF needy\\
12 & N & L & H & L & L & 7 & Cash flow optimization\\
13 & O & L & L & H & H & 4 & Doubtful case\\
14 & P & L & L & H & L & 9 & Potential cash provider\\
15 & Q & L & L & L & H & 5 & Low performer\\
16 & R & L & L & L & L & 5 & Low performer\\
\bottomrule
\end{tabularx}

\caption{caption}
\end{table}
\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.