3

I have a large table fitted to the width of the page, using the tabularx environment, that makes use of multirow.

Following the example in table with tabularx and multirow, I used \multirow{n}{\hsize}{text} to get the text to wrap correctly, but in some occasions the text bleeds into the column below (in red in the picture below):

enter image description here

Something else that I would like to fix would be the text alignment, which is different from non-multirow cells (compare the last cell in the second row to the one in the third row, both in blue in the picture).

\documentclass[
a4paper, %size of paper
11pt, %font size
]{scrreprt}

\usepackage{booktabs,multirow,tabularx}
\def\tabularxcolumn#1{m{#1}}    %vertical alignment center for tabularx columns    

\begin{document}

\begin{table}[htbp]
\centering
\begin{tabularx}{\textwidth}{XccX}
    \toprule
    \multicolumn{1}{c}{\textbf{Reference}}  & \textbf{Rail pad material}    & \textbf{Ratio}    & \multicolumn{1}{c}{\textbf{Notes}} \\
    \midrule
    Nielsen and Oscarsson [2.13]    &   --- &   0.25    &   Suggested value, no material specified  \\
    \midrule
    \multirow{5}{\hsize}{Thompson and Verheij [2.15]}   &   Ribbed rubber   &   0.08    &   \multirow{5}{\hsize}{Experimental indirect method for measuring transfer stiffness} \\
                                &   Cork-rubber &   0.08    \\
                                &   EVA, Vossloh DF &   0.27    \\                                                                          &   Steel-rubber    &   0.43    \\                                                                          &   EVA, indirect fastener  &   0.49    \\  
    \midrule
    Thomson et al. [2.18]   & Studded rubber    &   0.29    &   Experimental indirect method for measuring transfer stiffness \\

    \midrule
    Wu and Thompson [2.19]  &   Studded rubber  &   0.22--0.32  &   Experimental indirect method for measuring transfer stiffness   \\
    \midrule
    Carrascal et al. [2.20] &   Thermoplastic polyester &   0.77    &   Experimental data   \\
    \midrule
    TCRP [2.21] &   --- &   0.25–-0.90  &   Study of 16 fastening systems, low frequency (1–20 Hz)  \\
    \midrule
    \multirow{2}{\hsize}{Kaewunruen and Remennikov [2.14]}  &   Studded rubber  &   0.50    &   \multirow{2}{\hsize}{State-dependent model fitted to experimental results}  \\
                                &   HDPE        &   0.61    \\
    \midrule
    \multirow{3}{\hsize}{DYNATRACK Survey [2.22]}   & Deutsche Bahn$^1$ &   0.29    & \multirow{3}{\hsize}{State-dependent model fitted to experimental results}    \\
                            &   Lupolen$^1$ &   0.46--0.68  \\                                                                      &   Polyurethane cork rubber    & 0.70  \\
    \midrule
    Maes and Guillaume [2.23]   &   Resin-bonded rubber &   0.38--0.60  &   State-dependent model fitted to experimental results    \\
    \midrule    
    Trackleast [2.24]       &   Various elastomers  &   0.35--0.55  &   Based on manufacturer report for five different rail pads   \\
    \midrule    
    \multirow{2}{\hsize}{Wirthwein AG [2.25]}   &   TPU &   0.57    &       \multirow{2}{\hsize}{Based on manufacturer report}  \\
                            &   EVA &   0.38--0.54  \\
    \midrule    
\multirow{3}{\hsize}{Pandrol [2.26]}    &   Fastclip FE system$^2$  &   0.63--0.75  &   \multirow{3}{\hsize}{Based on manufacturer report, rail pad material not defined (EVA or HDPE suggested)}   \\
                        &   Re system$^2$       &   0.88    \\                                                                      &   Fastclip FD system$^2$  &   0.90    \\
    \midrule    
\multicolumn{4}{l}{$^1$ Supplier or manufacturer, no material specified}    \\
    \multicolumn{4}{l}{$^2$ Fastening system designation, rail pad material not specified}  \\
    \bottomrule
\end{tabularx}
\end{table}
\end{document}
7
  • There are numerous problems with your MWE. We are missing a documentclass and at least one package (booktabs) to make this compilable. Please add enough code to make it compilable.
    – Runar
    Jun 17, 2016 at 13:16
  • Unfortunately I am using a pre-made template for my phd thesis, which comes with template .tex file and a .cls file. That makes it difficult to find what is indeed necessary to compile the code (I've been trying with no success so far). If I am able to do it I will add it to the question and reply to your comment to let you know. Thanks for the guidance, as you can guess, I'm just starting using latex. Jun 17, 2016 at 13:39
  • I believe it is working now (at least on my end it is). Jun 17, 2016 at 13:59
  • Your problem arise because multi row cell has more lines than it span. As solution can be introducing empty lines in second column where necessary.
    – Zarko
    Jun 17, 2016 at 14:11
  • @Zarko Thanks for the edits in the code. So, I increased the number of rows to 3 (in the first row where the problem happens) and added an empty line below (& & \), but this results in a actual blank row below the content, which does not look nice. Is there a more robust solution? Jun 17, 2016 at 14:22

2 Answers 2

1

As I mentioned in my comment, simpolest solution is insert empty lines in third column cels, where the number of line in multri row cell is bigger:

\documentclass[a4paper, 11pt]{scrreprt}

\usepackage{booktabs,multirow,tabularx}
\usepackage{ragged2e}% for smart ragged align in last column
\def\tabularxcolumn#1{m{#1}}    %vertical alignment center for tabularx columns

\begin{document}

\begin{table}[htbp]
\centering
\begin{tabularx}{\textwidth}{@{}
                             >{\RaggedRight\arraybackslash}Xcc
                             >{\RaggedRight\arraybackslash}X
                             @{}}

    \toprule
    \multicolumn{1}{c}{\textbf{Reference}}  & \textbf{Rail pad material}    & \textbf{Ratio}    & \multicolumn{1}{c}{\textbf{Notes}} \\
    \midrule
    Nielsen and Oscarsson [2.13]    &   --- &   0.25    &   Suggested value, no material specified  \\
    \midrule
    \multirow{5}{\hsize}{Thompson and Verheij [2.15]}   &   Ribbed rubber   &   0.08    &   \multirow{5}{\hsize}{Experimental indirect method for measuring transfer stiffness} \\
                                &   Cork-rubber &   0.08    \\
                                &   EVA, Vossloh DF &   0.27    \\                                                                          &   Steel-rubber    &   0.43    \\                                                                          &   EVA, indirect fastener  &   0.49    \\
    \midrule
    Thomson et al. [2.18]   & Studded rubber    &   0.29    &   Experimental indirect method for measuring transfer stiffness \\
    \midrule
    Wu and Thompson [2.19]  &   Studded rubber  &   0.22--0.32  &   Experimental indirect method for measuring transfer stiffness   \\
    \midrule
    Carrascal et al. [2.20] &   Thermoplastic polyester &   0.77    &   Experimental data   \\
    \midrule
    TCRP [2.21] &   --- &   0.25–-0.90  &   Study of 16 fastening systems, low frequency (1–20 Hz)  \\
    \midrule
    \multirow{3}{\hsize}{Kaewunruen and Remennikov [2.14]}  &   Studded rubber  &   0.50    &   \multirow{3}{\hsize}{State-dependent model fitted to experimental results}  \\
            &   &            \\
                                &   HDPE        &   0.61    \\
    \midrule
    \multirow{3}{\hsize}{DYNATRACK Survey [2.22]}   & Deutsche Bahn$^1$ &   0.29    & \multirow{3}{\hsize}{State-dependent model fitted to experimental results}    \\
                            &   Lupolen$^1$ &   0.46--0.68  \\                                                                      &   Polyurethane cork rubber    & 0.70  \\
    \midrule
    Maes and Guillaume [2.23]   &   Resin-bonded rubber &   0.38--0.60  &   State-dependent model fitted to experimental results    \\
    \midrule
    Trackleast [2.24]       &   Various elastomers  &   0.35--0.55  &   Based on manufacturer report for five different rail pads   \\
    \midrule
    \multirow{2}{\hsize}{Wirthwein AG [2.25]}   &   TPU &   0.57    &       \multirow{2}{\hsize}{Based on manufacturer report}  \\
                            &   EVA &   0.38--0.54  \\
    \midrule
\multirow{5}{\hsize}{Pandrol [2.26]}    &   Fastclip FE system$^2$  &   0.63--0.75  &   \multirow{5}{\hsize}{Based on manufacturer report, rail pad material not defined (EVA or HDPE suggested)}   \\
                        &   &            \\
                        &   Re system$^2$       &   0.88    \\  
                        &   &            \\
                                                                    &   Fastclip FD system$^2$  &   0.90    \\
    \midrule
\multicolumn{4}{l}{$^1$ Supplier or manufacturer, no material specified}    \\
    \multicolumn{4}{l}{$^2$ Fastening system designation, rail pad material not specified}  \\
    \bottomrule
\end{tabularx}
\end{table}
\end{document}

This gives:

enter image description here

With help of package ragged2e I also change align of text in the last column.

Addendum: Alternative solution, where multirow cells are omited and introduced nested tables. Code is more complicated, results is up to taste of observer:

enter image description here

\documentclass[a4paper,11pt]{scrreprt}    
\usepackage{booktabs,makecell,multirow,tabularx}
\renewcommand\theadfont{\bfseries\normalsize}
\def\tabularxcolumn#1{m{#1}}    %vertical alignment center for tabularx columns

\begin{document}
\begin{table}[htbp]
\centering
\begin{tabularx}{\textwidth}{@{}
                             >{\setlength\hsize{0.75\hsize}\raggedright\arraybackslash}X
                             >{\centering\arraybackslash}p{12em}
                             >{\centering\arraybackslash}p{5em}
                             >{\setlength\hsize{1.25\hsize}\raggedright\arraybackslash}X
                             @{}}
    \toprule
\thead{Reference}  
    &   \thead{Rail pad material}    
            &   \thead{Ratio}    
                    &   \thead{Notes}               \\
    \midrule
Nielsen and Oscarsson [2.13]    
    & --- &   0.25  &   Suggested value, no material specified  \\
    \midrule
Thompson and Verheij [2.15]   
    &   \multicolumn{2}{c}{
        \begin{tabular}{@{}>{\centering\arraybackslash}p{12em}>{\centering\arraybackslash}p{5em}@{}}
        Ribbed rubber               &   0.08    \\ 
        Cork-rubber                 &   0.08    \\
        EVA, Vossloh DF             &   0.27    \\                                                                          Steel-rubber                &   0.43    \\                                                                          EVA, indirect fastener      &   0.49    
        \end{tabular}}
            &   Experimental indirect method 
                for measuring transfer stiffness    \\
    \midrule
Thomson et al. [2.18]   
    &   Studded rubber              &   0.29    
            &   Experimental indirect method for measuring transfer stiffness \\

    \midrule
Wu and Thompson [2.19]  
    &   Studded rubber              &   0.22--0.32  
            &   Experimental indirect method for measuring transfer stiffness   \\
    \midrule
Carrascal et al. [2.20] 
    &   Thermoplastic polyester &   0.77    
            &   Experimental data   \\
    \midrule
TCRP [2.21] & ---                   &   0.25–-0.90  
            &   Study of 16 fastening systems, low frequency (1–20 Hz)  \\
    \midrule
Kaewunruen and Remennikov [2.14] 
    &   \multicolumn{2}{c}{
        \begin{tabular}{@{}>{\centering\arraybackslash}p{12em}>{\centering\arraybackslash}p{5em}@{}}
        Studded rubber              &   0.50    \\    
        HDPE                        &   0.61
        \end{tabular}}   
            &   State-dependent model fitted to experimental results   \\
    \midrule
DYNATRACK Survey [2.22] 
    &   \multicolumn{2}{c}{
        \begin{tabular}{@{}>{\centering\arraybackslash}p{12em}>{\centering\arraybackslash}p{5em}@{}}
        Deutsche Bahn$^1$           &   0.29        \\
        Lupolen$^1$                 &   0.46--0.68  \\   
        Polyurethane cork rubber    & 0.70
        \end{tabular}}
            &   State-dependent model fitted to experimental results       \\
    \midrule
Maes and Guillaume [2.23]   
    &   Resin-bonded rubber         &   0.38--0.60  
            &   State-dependent model fitted to experimental results        \\
    \midrule
Trackleast [2.24]       
    &   Various elastomers          &   0.35--0.55  
            &   Based on manufacturer report for five different rail pads   \\
    \midrule
Wirthwein AG [2.25]  
    &   \multicolumn{2}{c}{
        \begin{tabular}{@{}>{\centering\arraybackslash}p{12em}>{\centering\arraybackslash}p{5em}@{}}
        TPU                         &   0.57    \\
        EVA                         &   0.38--0.54 
        \end{tabular}}   
            &   Based on manufacturer report                        \\
    \midrule
Pandrol [2.26]   
    &   \multicolumn{2}{c}{
        \begin{tabular}{@{}>{\centering\arraybackslash}p{12em}>{\centering\arraybackslash}p{5em}@{}}
        Fastclip FE system$^2$      &   0.63--0.75  \\  
        Re system$^2$               &   0.88        \\
        Fastclip FD system$^2$      &   0.90   
        \end{tabular}}
            &   Based on manufacturer report, rail pad material not defined (EVA or HDPE suggested)   \\  
    \midrule
\multicolumn{4}{l}{$^1$ Supplier or manufacturer, no material specified}    \\
    \multicolumn{4}{l}{$^2$ Fastening system designation, rail pad material not specified}  \\
    \bottomrule
\end{tabularx}
\end{table}
\end{document}
3
  • See my alternative solution. Here I omit \multirow{...} and inserts sub tables in second and third column where necessary. Maybe you more like this solution. I also replace \RaggedRight` with \raggedright` (if you maybe more liked). Of course, you can left cells justified as you have in your MWE.
    – Zarko
    Jun 17, 2016 at 15:20
  • Thank you! It looks great, that's what I was looking for. Just a small question: are the vertical rules optional? I can't figure out from the code. Jun 17, 2016 at 16:20
  • Oh, I forgot to erase it. It serves me in determining of column width. I will replace image with correct one.
    – Zarko
    Jun 17, 2016 at 16:51
3

Here is a simpler code to do it, replacing the multirow environment with the \makecell command for the two middle columns, which allows line breaks in cells. I also load threeparttable for table notes:

\documentclass[a4paper, 11pt]{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{ragged2e}
 \usepackage{tabularx, multirow, booktabs, makecell}
 \usepackage[flushleft]{threeparttable}

\def\tabularxcolumn#1{ >{\RaggedRight}m{#1}} %vertical alignment center for tabularx columns

\begin{document}

\begin{table}[htbp]
\begin{threeparttable}
\caption{Static to dynamic vertical stiffness ratio in the literature.}
\label{tab:static_dynamic_ratio}
\centering
\begin{tabularx}{\linewidth}{XccX}
    \toprule
    \multicolumn{1}{c}{\textbf{Reference}} & \textbf{Rail pad material} & \textbf{Ratio} & \multicolumn{1}{c}{\textbf{Notes}} \\
    \midrule
    Nielsen and Oscarsson [2.13] & --- & 0.25 & Suggested value, no material specified \\
    \midrule
  Thompson and Verheij [2.15] & \makecell{Ribbed rubber\\ Cork-rubber\\ EVA, Vossloh DF \\ Steel-rubber\\ EVA, indirect fastener}
     & \makecell{0.08\\0.08\\ 0.27\\0.43\\0.49} & Experimental indirect method for measuring transfer stiffness \\
      \midrule
    Thomson et al. [2.18] & Studded rubber & 0.29 & Experimental indirect method for measuring transfer stiffness \\
    \midrule
    Wu and Thompson [2.19] & Studded rubber & 0.22--0.32 & Experimental indirect method for measuring transfer stiffness \\
    \midrule
    Carrascal et al. [2.20] & Thermoplastic polyester & 0.77 & Experimental data \\
    \midrule
    TCRP [2.21] & --- & 0.25–-0.90 & Study of 16 fastening systems, low frequency (1–20 Hz) \\
    \midrule
    Kaewunruen and \newline Remennikov [2.14] & \makecell{Studded rubber \\ HDPE} & \makecell{0.50\\ 0.61}
    & State-dependent model fitted to experimental results \\
    \midrule
    DYNATRACK Survey [2.22] & \makecell{Deutsche Bahnt\tnote{1} \\Lupolen\tnote{1} \\Polyurethane cork rubber}
    & \makecell{0.29 \\ 0.46--0.68 \\ 0.70} & State-dependent model fitted to experimental results \\
    \midrule
    Maes and Guillaume [2.23] & Resin-bonded rubber & 0.38--0.60 & State-dependent model fitted to experimental results \\
    \midrule
    Trackleast [2.24] & Various elastomers & 0.35--0.55 & Based on manufacturer report for five different rail pads \\
    \midrule
    Wirthwein AG [2.25] & \makecell{TPU \\ EVA} & \makecell{0.57\\ 0.38--0.54} & Based on manufacturer report \\
 \midrule
Pandrol [2.26] & \makecell{Fastclip FE system\tnote{2}\\ Re system\tnote{2}\\ Fastclip FD system\tnote{2}} &\makecell{0.63--0.75\\ 0.88\\ 0.90}
& Based on manufacturer report, rail pad material not defined (EVA or HDPE suggested) \\
    \midrule[\heavyrulewidth]
\end{tabularx}
\begin{tablenotes}
  \item[1] Supplier or manufacturer, no material specified.
  \item[2 ] Fastening system designation, rail pad material not specified.
\end{tablenotes}
\end{threeparttable}
\end{table}

\end{document} 

Note: As one can see, the table height is a little more than \textheight. One might reduce the font size to 10pt to circumvent this problem, or, if the table cll happens in the middle of a page, load the threeparttablex and ltablex packages, which allow for page breaks in threeparttables and in tabularx.

enter image description here

You must log in to answer this question.

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