tabularx 环境中 \multirow 的高度和文本对齐问题

tabularx 环境中 \multirow 的高度和文本对齐问题

我有一个适合页面宽度的大表格,使用 tabularx 环境,利用多行。

按照以下示例带有 tabularx 和 multirow 的表格,我使用 \multirow{n}{\hsize}{text} 来使文本正确换行,但在某些情况下,文本会渗入下面的列(下图中红色部分):

在此处输入图片描述

我想要修复的另一件事是文本对齐,这与非多行单元格不同(比较第二行中的最后一个单元格与第三行中的单元格,图中均为蓝色)。

\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}

答案1

正如我在评论中提到的,最简单的解决方案是在第三列单元格中插入空行,其中多行单元格中的行数较大:

\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}

得出:

在此处输入图片描述

在包的帮助下,ragged2e我还改变了最后一列文本的对齐方式。

附录:替代解决方案,其中省略多行单元格并引入嵌套表。代码更复杂,结果取决于观察者的品味:

在此处输入图片描述

\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}

答案2

下面是一个更简单的代码,用两个中间列的命令替换环境multirow,这样可以在单元格中换行。我还加载了表格注释:\makecellthreeparttable

\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} 

笔记:可以看出,表格高度比 \textheight 稍大。可以将字体大小减小到 以10pt避免此问题,或者,如果表格 cll 出现在页面中间,则加载threeparttablexltablex包,它们允许在threeparttables 和 中进行分页tabularx

在此处输入图片描述

相关内容