0

I am pretty new to using latex, and I need to create a rather complex table. The title basically tells what I want to do. I have the following issues I want to solve:

  • The table would continue for a bit longer, so I definitely need another page.
  • As you can see some of the line don't make a line break e.g. advanced augmentation, i even wonder why this happens since the other times the line breaks just works
  • The numbers in the multi rows are not vertically centered, e.g. the 5.2 should be a little below.

It's a bit frustrating, when i solve a issue on the one hand another part of the table breaks. Any good ideas?

Minimal running example:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tabularx}
\usepackage{multirow}
\usepackage{array}
\usepackage{longtable}
\usepackage{amsmath}
\usepackage{gensymb}
\begin{document}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{Y}{>{\centering\arraybackslash}X}

\begin{table}[h!]
    \centering
 \begin{tabularx}{\textwidth}{C{1.5cm}|C{2cm} C{2cm} Y}
    Chapter & Experiment & Hyperparameter & Range \\
    \hline
    5.1 & benchmark & None & Configuration as in Chapter 3.2 \\
    \hline
    \multirow{7}{*}{5.2} & learning rate                       & learning rate   & 0.00002, 0.00005, 0.0001, 0.00025 \\
    \cline{2-4}
                     & \multirow{6}{=}{basic augmentation} 
                     & aspect ratio      & $1\pm0.5$ times total height and width \\
                     & & cropping        & random $333\times333$ region \\
                     & & horizontal flip & probability of $50\%$    \\
                     & & rotation        & rotating up to $\pm 180\degree$ uniformly chosen\\
                     & & shearing        & random angle between $\pm 30\degree$ uniformly chosen    \\
                     & & scaling         & ratio between $0.5-2.0$ uniformly chosen \\
     \hline
     \multirow{16}{*}{5.2} & \multirow{2}{*}{brightness shift}                                                          & minimum brightness  &  X \\
                      & & maximum brightness &  X \\
                      \cline{2-4}
                      & \multirow{2}{*}{noise injection} & mean     & X \\
                      &                                  & variance & X \\
                      \cline{2-4}
                      & \multirow{2}{*}{patch shuffle}   & patch size  & X \\
                      &                                  & probability & X \\
                      \cline{2-4}
                      & \multirow{3}{*}{random erasing}   & maximum range & X \\
                      & & aspect ratio r\_2 & X \\
                      & & probability       & X \\
                      \cline{2-4}
                      & \multirow{7}{*}{advanced augmentation} & patch shuffle   & X  \\
                      & & scaling         & X  \\
                      & & horizontal flip & X  \\
                      & & vertical flip   & X  \\
                      & & \begin{tabular}[c]{@{}c@{}}brightness \\ shift\end{tabular}                            & X  \\
                      & \multicolumn{1}{l}{}      & aspect ratio    & X  \\
                      & \multicolumn{1}{l}{}      & shearing        & X  \\
      \hline
      5.3 & ablation study without augmentation & image cycle consistency loss weight & 0.1,0.2,0.5,1.0 \\
     
   \end{tabularx}
\caption{Searched hyperparameters \label{all_hyperparameter}}
\end{table}
\end{document}

This is how it looks so far:

Buggy-multi-page-multi-row-table

7
  • 1
    tabularx can not break across pages. If you want mid-table pagebreaks while keeping X (or derived) column types in your table, switch to xltabular. To vertically center "advanced augmentation" while allowing a linebreak between the words, use \multirow{9}{=}{advanced augmentation} instead.
    – leandriis
    Sep 12, 2020 at 12:50
  • okay with the {=} i could force the line break in advanced augmentation, but now it is left aligned, actually i want that centered as well.
    – madave
    Sep 12, 2020 at 12:57
  • Personally, I find your table quite hard to read, especially due to vertically centered contents in combination with contents spanning multiple lines. Also, why do you have chapter 5.2 twice in your table? Probably it would be better to remove the first column entirely (this would save quite a lot of space and thus helps avoiding linebreaks inside of the other columns). You could add the chapter number in a \multicolumn command right above the corresponding rows of your table.
    – leandriis
    Sep 12, 2020 at 12:59
  • @leandriis I agree that the table is hard to read. It is only part of the appendix and is only there to find a specific hyperparameter used for the experiments i did. I need to include the chapter numbers to make it easier to find the hyperparameter, so excluding them won't be an option. I think I will try your \multicolumn suggestion. To see if xltabular works i need to add some more entries.
    – madave
    Sep 12, 2020 at 13:04
  • What about something like this? i.stack.imgur.com/YLwPC.png
    – leandriis
    Sep 12, 2020 at 13:18

2 Answers 2

0

I propose this variant layout, which uses geometry, xcolor and xltabular (to break tabularx tables across pages):

\documentclass{article}
\usepackage{geometry}
\usepackage[table, svgnames]{xcolor}
\usepackage{multirow}
\usepackage{ xltabular, booktabs}
\usepackage{amsmath}
\usepackage{gensymb}

\begin{document}

{\centering\setlength{\extrarowheight}{2pt}\arrayrulecolor{SlateGrey}%
 \begin{xltabular}{\textwidth}{!{\quad}m{3.6cm}>{\raggedleft}m{3.5cm}X}%
\caption{Searched hyperparameters \label{all_hyperparameter}} \\
      Experiment & Hyperparameter & Range \\
\addlinespace
    \endfirsthead
\caption[]{Searched hyperparameters (\emph{continued})} \\
     Experiment & Hyperparameter & Range \\
    \addlinespace
    \endhead
\hline
\multicolumn{3}{r}{\small\emph{To be continued}}
\endfoot
\bottomrule
 \endlastfoot
\rowcolor{Gainsboro!50!Lavender} \multicolumn{3}{@{}l}{\textsc{Chapter 5.1}} \\[0.5ex]
  benchmark & None & Configuration as in Chapter 3.2 \\[2ex]%
\rowcolor{Gainsboro!60!Lavender}\multicolumn{3}{@{}l}{ \textsc{Chapter 5.2}}\\[0.5ex]
 learning rate & learning rate & 0.00002, 0.00005, 0.0001, 0.00025 \\
     \cmidrule(l{1em}){1-3}
                    {basic augmentation} &
                     aspect ratio & $1\pm0.5$ times total height and width \\
                     & cropping & random $333\times333$ region \\
                     & horizontal flip & probability of $50\%$ \\
                     & rotation & rotating up to $\pm 180\degree$ uniformly chosen\\
                     & shearing & random angle between $\pm 30\degree$ uniformly chosen \\
                     & scaling & ratio between $0.5-2.0$ uniformly chosen \\
     \cmidrule(l{1em}){1-3}
    \multirow{2}{*}{brightness shift} & minimum brightness & X \\
 & maximum brightness & X \\
    \cmidrule(l{1em}){1-3}
 \multirow{2}{*}{noise injection} & mean & X \\
 & variance & X \\
    \cmidrule(l{1em}){1-3}
 \multirow{2}{*}{patch shuffle} & patch size & X \\
 & probability & X \\
    \cmidrule(l{1em}){1-3}
 \multirow{3}{*}{random erasing} & maximum range & X \\
 & aspect ratio r\_2 & X \\
 & probability & X \\
    \cmidrule(l{1em}){1-3}
 advanced \rlap{augmentation} & patch shuffle & X \\
 & scaling & X \\
 & horizontal flip & X \\
 & vertical flip & X \\
 &brightness shift & X \\%
 & aspect ratio & X \\
 & shearing & X \\[2ex]
 \rowcolor{Gainsboro!60!Lavender}\multicolumn{3}{@{}l}{\textsc{Chapter} 5.3} \\[0.5ex]
 ablation study without augmentation & image cycle consistency loss weight & 0.1,0.2,0.5,1.0
   \end{xltabular}}

\end{document} 

enter image description here

4
  • Hi @Bernard, i ran into some problems when importing it from my example to the main document. I use the template, and i get some undefined control sequence error. I think the issue is related to arrayrulecolor and rowcolor since they are written just plain in the text now. I import the xcolor package and the required options, so this cannot be the issue.
    – madave
    Sep 12, 2020 at 20:53
  • What are the undefined control sequences?
    – Bernard
    Sep 12, 2020 at 21:17
  • I managed to change the error from undefined control sequence to undefined color for SlateGrey, Gainsboro and Lavender by importing the colortbl package. I am assuming right now that my latex either uses some lower tex version or something, but I have no clue how to fix that.
    – madave
    Sep 13, 2020 at 8:32
  • This is how it looks, if you scroll down you can see the error message.
    – madave
    Sep 13, 2020 at 8:37
0

Here are two versions with more or less horizontal lines:

enter image description here

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{xltabular}
\usepackage{multirow}
\usepackage{array}
\usepackage{amsmath}
\usepackage{gensymb}
\usepackage[english]{babel}
\usepackage{booktabs}
\begin{document}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{Y}{>{\centering\arraybackslash}X}


 \begin{xltabular}{\textwidth}{@{\quad\quad}>{\raggedright\arraybackslash}p{2.25cm} >{\raggedright\arraybackslash}p{2.5cm} X}
 \caption{Searched hyperparameters \label{all_hyperparameter}}\\
 \toprule
     Experiment            & Hyperparameter     & Range \\
    \midrule
    \endhead
    \multicolumn{3}{@{}l}{\itshape Chapter 5.1}\\ \addlinespace
     benchmark             & None               & Configuration as in Chapter 3.2 \\
    \midrule
    \multicolumn{3}{@{}l}{\itshape Chapter 5.2}\\
    \addlinespace
     learning rate         & learning rate      & 0.00002, 0.00005, 0.0001, 0.00025 \\
    \addlinespace
     \multirow{2}{=}{basic augmentation}    & aspect ratio      & $1\pm0.5$ times total height and width \\
                           & cropping           & random $333\times333$ region \\
                           & horizontal flip    & probability of $50\%$    \\
                           & rotation           & rotating up to $\pm 180\degree$ uniformly chosen\\
                           & shearing           & random angle between $\pm 30\degree$ uniformly chosen    \\
                           & scaling            & ratio between $0.5-2.0$ uniformly chosen \\
   \addlinespace
     brightness shift      & maximum brightness & X \\
    \addlinespace
     noise injection       & mean               & X \\
                           & variance           & X \\
    \addlinespace
     patch shuffle         & patch size         & X \\
                           & probability        & X \\
    \addlinespace
     \multirow{2}{=}{random erasing}        & maximum range      & X \\
                           & aspect ratio r\_2  & X \\
                           & probability        & X \\
    \addlinespace
     \multirow{2}{=}{advanced augmentation} & patch shuffle      & X  \\
                           & scaling            & X  \\
                           & horizontal flip    & X  \\
                           & vertical flip      & X  \\
                           & brightness  shift  & X  \\
                           & aspect ratio       & X  \\
                           & shearing           & X  \\
    \midrule
    \multicolumn{3}{@{}l}{\itshape Chapter 5.3}\\ \addlinespace
   ablation study without augmentation & image cycle consistency loss weight & 0.1,0.2,0.5,1.0 \\
     
   \end{xltabular}


 \begin{xltabular}{\textwidth}{@{\quad\quad}>{\raggedright\arraybackslash}p{2.25cm} >{\raggedright\arraybackslash}p{2.5cm} X}
 \caption{Searched hyperparameters \label{all_hyperparameter}}\\
 \toprule
     Experiment            & Hyperparameter     & Range \\
    \midrule
    \endhead
    \multicolumn{3}{@{}l}{\itshape Chapter 5.1}\\ \addlinespace
     benchmark             & None               & Configuration as in Chapter 3.2 \\
    \midrule
    \multicolumn{3}{@{}l}{\itshape Chapter 5.2}\\
    \addlinespace
     learning rate         & learning rate      & 0.00002, 0.00005, 0.0001, 0.00025 \\
    \midrule
     \multirow{2}{=}{basic augmentation}    & aspect ratio      & $1\pm0.5$ times total height and width \\
                           & cropping           & random $333\times333$ region \\
                           & horizontal flip    & probability of $50\%$    \\
                           & rotation           & rotating up to $\pm 180\degree$ uniformly chosen\\
                           & shearing           & random angle between $\pm 30\degree$ uniformly chosen    \\
                           & scaling            & ratio between $0.5-2.0$ uniformly chosen \\
   \midrule
     brightness shift      & maximum brightness & X \\
    \midrule
     noise injection       & mean               & X \\
                           & variance           & X \\
    \midrule
     patch shuffle         & patch size         & X \\
                           & probability        & X \\
    \midrule
     \multirow{2}{=}{random erasing}        & maximum range      & X \\
                           & aspect ratio r\_2  & X \\
                           & probability        & X \\
    \midrule
     \multirow{2}{=}{advanced augmentation} & patch shuffle      & X  \\
                           & scaling            & X  \\
                           & horizontal flip    & X  \\
                           & vertical flip      & X  \\
                           & brightness  shift  & X  \\
                           & aspect ratio       & X  \\
                           & shearing           & X  \\
    \midrule
    \multicolumn{3}{@{}l}{\itshape Chapter 5.3}\\ \addlinespace
   ablation study without augmentation & image cycle consistency loss weight & 0.1,0.2,0.5,1.0 \\
     
   \end{xltabular}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .