4

I am trying to make a table which has in total 4 rows (1 tittle + 3 data). In one column, which contains the same information for all 3 rows, I decided to use \multirow.

In this multicolumn I would like to write information and split it in 7 rows (i.e. more than the total rows of the table), using \makecell.

My code is

\documentclass[12pt,a4paper]{book}

%~~~~~~~~~~~~~~~ Fonts ~~~~~~~~~~~~~~~~~~~~
\usepackage{kpfonts}

%~~~~~~~~~~~~~~~ Tables ~~~~~~~~~~~~~~~~~~~~~
\usepackage{makecell,booktabs}
\usepackage{color, colortbl}
\definecolor{Gray}{gray}{0.9}
\usepackage{multirow}

%~~~~~~~~~~~~~~ Commands
\newcommand{\pu}{$^{240}Pu$ }

\begin{document}

\begin{table}
\centering
% table caption is above the table
\caption{This will be filled later!\label{tab:filters}}
% Give a unique label
% For LaTeX tables use
\begin{tabular}{ccccccc}
\toprule
\hline
\rowcolor{Gray}[6pt][40pt]
\makecell{Sample} & \makecell{Reference\\Number} & \makecell{Activity\\(MBq)} & \makecell{Mass\\(mg)} & \multicolumn{2}{c}{\makecell{Areal density\\(mg/cm$^2$) ($\times 10^{-4}$ atoms/b)}} & \makecell{Atomic\\abundances\\(mol/mol)}\\
\hline
{}    & {TP2010-011-01} & {6.016(23)} & {0.7163(28)} & {0.1017(4)} & {2.55(1)} & 
\multirow{3}{*}{ \makecell{$^{238}Pu$ :  $7.33(29) \cdot 10^{-4}$\\
          $^{239}Pu$ :  $1.44(18) \cdot 10^{-4}$\\
          $^{240}Pu$ :  $0.998915(18) \cdot 10^{-4}$\\
          $^{241}Pu$ :  $4.1(31) \cdot 10^{-6}$\\
          $^{242}Pu$ :  $2.027(41) \cdot 10^{-4}$\\
          $^{244}Pu$ :  $4.6(88) \cdot 10^{-7}$}}\\
{\pu} & {TP2010-011-03} & {6.793(26)} & {0.809(3)}   & {0.1148(5)} & {2.88(1)} & {}\\
{}    & {TP2010-011-04} & {6.410(25)} & {0.763(3)}   & {0.1083(5)} & {2.72(1)} & {}\\
\bottomrule
\hline
\end{tabular}
\end{table}

\end{document}

and my ugly output is

enter image description here

So here there are many issues.

  1. The last column overlaps with the other rows and the automatic spacing makes the data in the multirows to fall out of the table boarders.
  2. The table is much wider than the page. This was fixed by using \resizebox, though not the best option for tables...
  3. The \rowcolor command combined with \makecell results in white spaces when the maximum width of the column is smaller that the width of the colored row : This was solved by using [6pt][40pt] in the \rowcolor command!
  4. The table is ugly...

Any idea on how to solve these issues?

EDIT I tried to remove \multirow and use only \makecell but still the outcome is a bit strange.

enter image description here

The new version of the code is

 \documentclass[12pt,a4paper]{book}

%~~~~~~~~~~~~~~~ Fonts ~~~~~~~~~~~~~~~~~~~~
\usepackage{kpfonts}

%~~~~~~~~~~~~~~~ Tables ~~~~~~~~~~~~~~~~~~~~~
\usepackage{makecell,booktabs}
\usepackage{color, colortbl}
\definecolor{Gray}{gray}{0.9}
\usepackage{multirow}

%~~~~~~~~~~~~~~ Commands
\newcommand{\pu}{$^{240}Pu$ }

\begin{document}
\begin{table}
\centering
% table caption is above the table
\caption{This will be filled later!\label{tab:filters}}
% Give a unique label
% For LaTeX tables use
\begin{tabular}{ccccccc}
\toprule
\hline
\rowcolor{Gray}[6pt][40pt]
\makecell{Sample} & \makecell{Reference\\Number} & \makecell{Activity\\(MBq)} & \makecell{Mass\\(mg)} & \multicolumn{2}{c}{\makecell{Areal density\\(mg/cm$^2$) ($\times 10^{-4}$ atoms/b)}} & \makecell{Atomic\\abundances\\(mol/mol)}\\
\hline
{\pu}    & \makecell{TP2010-011-01\\TP2010-011-03\\TP2010-011-04} & \makecell{6.016(23)\\6.793(26)\\6.410(25)} & \makecell{0.7163(28)\\0.809(3)\\0.763(3)} & \makecell{0.1017(4)\\0.1148(5)\\0.1083(5)} & \makecell{2.55(1)\\2.88(1)\\2.72(1)} & 
\makecell{$^{238}Pu$ :  $7.33(29) \cdot 10^{-4}$\\
          $^{239}Pu$ :  $1.44(18) \cdot 10^{-4}$\\
          $^{240}Pu$ :  $0.998915(18) \cdot 10^{-4}$\\
          $^{241}Pu$ :  $4.1(31) \cdot 10^{-6}$\\
          $^{242}Pu$ :  $2.027(41) \cdot 10^{-4}$\\
          $^{244}Pu$ :  $4.6(88) \cdot 10^{-7}$}\\
\bottomrule
\hline
\end{tabular}
\end{table}

\end{document}
Thanos
  • 12,446
  • The issue regarding the missing color in table cells with the makecell command was already discussed here: How to color column heads determined width makecell and here: colortbl's \cellcolor not filling whole cell in combination with \makecell. Regarding the width of the table: As you can most likely not reduce the width by splitting contents over multiple lines, you might either consider redesigning the table (transposing...) or rotate the whole table e.g. with sidewaystable from rotating. – leandriis Jun 25 '18 at 15:43
  • Regarding the too long text in the multirow: why not use makecell also for the contents of the other columns in order to avoid the usage of multirow completely? – leandriis Jun 25 '18 at 15:48
  • @leandriis Thank you very much for your comments! Indeed the white-spaces got fixed with the optional arguments of \rowcolor. I also tried to remove \multicols but still...it's not pretty. As far as the width is concerned, this is only one third of the table, so I can't rotate it... – Thanos Jun 25 '18 at 16:10
  • Regarding the usage of \makecell: This is not what I meant with my comment. I would suggest, that you use a single row instead of three and use \makecell in every column (e.g: \makecell{TP2010-011-01 \\ TP2010-011-03 \\ TP2010-011-04}) Without any placement options, the contents of all columns will be vertically centered with this approach. – leandriis Jun 25 '18 at 16:17
  • 'this is only one third of the table' Do you mean, you have a total of three samples (more rows), or do you mean, you have more columns in your actual table? You might alos have to worry about the spacing after the \hrule below the colored row. This can for example be done as described here: How to add vertical space struts after hline? – leandriis Jun 25 '18 at 16:20
  • @leandriis Thanks again for your comments! Sorry for the misunderstanding! Indeed now it looks better, but still I think it needs something more. As far as the size is concerned, I have 2 more samples. – Thanos Jun 25 '18 at 16:31
  • Assuming that your other sample entries consist of a comparable amount of lines and assuming, that your caption is not extremely long, your table can be rotated and fit onto a single page. Regarding the alignment, you might consider using an l type column for the last column in order to align all :. Could you please also explain the desired alignment in the 'areal density' column(s)? Currently I am not able to understand which value has which meaning, as they share a heading. – leandriis Jun 25 '18 at 17:07
  • @leandriis Thank you very much for your comment once again! I want to avoid the rotation so I tried a resizebox and doesn't look that bad! As far as the areal density is concerned, I have different units for the same quantity. – Thanos Jun 26 '18 at 06:02
  • 1
    your table is to wide that can be fit in text width. you should consider to redesign table (for example left out the first column) and use \small font. – Zarko Jun 26 '18 at 07:13
  • @Thanos: I'd avoid the use of resizebox as it will lead to inconsistent font sizes. – leandriis Jun 26 '18 at 07:18

1 Answers1

2
  • makecell and colortbl doesn't work well together (see coments below question}
  • i wouldn't color columns header, rather consider presentation Wie Tabellen eigentlich aussehen sollten
  • your table is to wide that can be fir in text width
  • as solution i propose:

    • convert the first column to row
    • extend the table into space for margin notes:

       \documentclass[12pt,a4paper]{book}
      
      %~~~~~~~~~~~~~~~ Fonts ~~~~~~~~~~~~~~~~~~~~
      \usepackage{kpfonts}
      
      %~~~~~~~~~~~~~~~ Tables ~~~~~~~~~~~~~~~~~~~~~
      \usepackage{makecell,booktabs}
      \usepackage[table]{xcolor}
      \definecolor{Gray}{gray}{0.9}
      \usepackage[version=4]{mhchem}
      \usepackage[strict]{changepage}
      
      %-------------------------------------- only for show page layout
      \usepackage{showframe}
      \renewcommand\ShowFrameLinethickness{0.25pt}
      \renewcommand*\ShowFrameColor{\color{red}}
      %---------------------------------------------------------------%
      
      \begin{document}
      \begin{table}
      \begin{adjustwidth*}{}{-\dimexpr\marginparwidth+\marginparsep}
      \centering
      % table caption is above the table
      \caption{This will be filled later!}
      \label{tab:filters}
      \setlength\tabcolsep{0pt}
      \begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}
          l ccccc}
          \toprule
          &   &   & \multicolumn{2}{c}{Areal density} &                       \\
         \cmidrule{4-5}
      \makecell{Reference\\Number}
          &   \makecell{Activity\\(MBq)}
              &   \makecell{Mass\\(mg)}
                  &   (mg/cm$^2$)
                      &   \makecell[t]{($\times 10^{-4}$\\ atoms/b)}
                              &   \makecell{Atomic abundances\\(mol/mol)}     \\
          \midrule
      \multicolumn{6}{l}{ Samples for \ce{^240 Pu}:}                           \\
      \makecell[l]{TP2010-011-01\\TP2010-011-03\\TP2010-011-04}
          & \makecell[l]{6.016(23)\\6.793(26)\\6.410(25)}
              & \makecell[l]{0.7163(28)\\0.809(3)\\0.763(3)}
                  & \makecell[l]{0.1017(4)\\0.1148(5)\\0.1083(5)}
                      & \makecell[l]{2.55(1)\\2.88(1)\\2.72(1)} &
      \makecell[l]{\ce{^238 Pu} :  $7.33(29) \cdot 10^{-4}$\\
                \ce{^239 Pu} :  $1.44(18) \cdot 10^{-4}$\\
                \ce{^240 Pu} :  $0.998915(18) \cdot 10^{-4}$\\
                \ce{^241 Pu} :  $4.1(31) \cdot 10^{-6}$\\
                \ce{^242 Pu} :  $2.027(41) \cdot 10^{-4}$\\
                \ce{^244 Pu} :  $4.6(88) \cdot 10^{-7}$}\\
          \bottomrule
      \end{tabular*}
      \end{adjustwidth*}
      \end{table}
      
      \end{document}
      

    which gives;

enter image description here

(red lines indicate text and margin par margins)

  • another possibility is rote table by use of landscape environment (provided by package pdflscape or lscape or with use sidewaystable defined in rotating package
Zarko
  • 296,517