Tabularx 有 m 列,但没有标题

Tabularx 有 m 列,但没有标题

我有以下表格,我想将每个单元格的内容水平和垂直居中。但是我不想将标题垂直居中,它们应该与标题单元格的底部对齐。我对第二列使用了 tabularx。

使用以下代码,标题不会全部对齐到底部。如何将所有标题对齐到底部,同时保持内容单元格对齐?用注释强调的行会导致此问题,但似乎也是使单元格垂直居中的唯一方法。2号线如果没有第 2 行,标题应该是这样的。

\documentclass[a4paper,twoside,notitlepage]{report}
\usepackage{a4wide}
\usepackage[utf8]{inputenc}
\usepackage{tabularx}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{graphicx}

\begin{document}

  \newcolumntype{C}{>{\centering}X}%
  \newcommand*\rot{\rotatebox{90}}

  %%% The line for vertical centering
  \def\tabularxcolumn#1{m{#1}}
  %%% ------

  \begin{table}[h!]
  \centering
  \caption{Table of results}
  \label{tbl:listexperiments}
  \rowcolors{2}{gray!18}{white}
  \begin{tabularx}{\textwidth}{cCcccccccccc}
  \rowcolor{gray!40}
  \rot{\emph{Experiment number}}
  & \rot{\emph{Time scales}}\
  & \rot{\emph{Hidden units}}
  & \rot{\emph{Prediction length (samples)}}
  & \rot{\emph{Sample length (minutes)}}
  & \rot{\emph{Input sequence length (samples)}}
  & \rot{\emph{Model training steps (1000s)}}
  & \rot{\emph{Training time (hours)}}
  & \rot{\emph{Loss value}}
  & \rot{\emph{Next Type Error}}
  & \rot{\emph{Next Switch MSE}}
  & \rot{\emph{Next Switch RMSE}}\\
  \#721
  & \footnotesize{[1, 32]}
  & 96
  & 14
  & 9
  & 1024
  & 80.1
  & 14.14
  & 0.751
  & 0.364
  & 1570.8
  & -9.043\\
  \#724
  & \footnotesize{[1, 8]}
  & 96
  & 14
  & 9
  & 1024
  & 10.1
  & 1.98
  & 0.818
  & 0.408
  & 1707.9
  & -8.212\\
  \#727
  & \footnotesize{[1]}
  & 96
  & 14
  & 9
  & 1024
  & 230.1
  & 39.51
  & 0.838
  & 0.346
  & 1853.8
  & -14.215\\
  \#730
  & \footnotesize{[1, 8]}
  & 96
  & 14
  & 9
  & 1024
  & 180.1
  & 33.88
  & 0.845
  & 0.405
  & 1753.2
  & -8.222\\
  \#742
  & \footnotesize{[1, 8]}
  & 48
  & 14
  & 9
  & 512
  & 5.1
  & 0.51
  & 0.864
  & 0.422
  & 1688.2
  & -5.685\\
  \#745
  & \footnotesize{[1, 8]}
  & 48
  & 14
  & 9
  & 512
  & 1.0
  & 0.13
  & 1.038
  & 0.414
  & 2069.8
  & -4.907\\
  \#748
  & \footnotesize{[1, 8]}
  & 48
  & 14
  & 9
  & 512
  & 22.6
  & 2.14
  & 0.841
  & 0.431
  & 1678.6
  & -6.614\\
  \#751
  & \footnotesize{[1, 8]}
  & 48
  & 14
  & 9
  & 512
  & 2.6
  & 0.29
  & 0.893
  & 0.433
  & 1844.3
  & -3.705\\
  \#754
  & \footnotesize{[1, 2, 4, 8, 16]}
  & 96
  & 14
  & 9
  & 1024
  & 0.1
  & 0.13
  & 1.254
  & 0.461
  & 2661.1
  & 5.821\\
  \#757
  & \footnotesize{[1, 2, 4, 8, 16]}
  & 96
  & 14
  & 9
  & 1024
  & 325.1
  & 93.51
  & 0.814
  & 0.381
  & 1736.5
  & -10.174\\
  \#760
  & \footnotesize{[1, 16]}
  & 96
  & 14
  & 9
  & 1024
  & 60.1
  & 11.30
  & 0.811
  & 0.387
  & 1657.5
  & -7.984\\
  \#763
  & \footnotesize{[1, 3, 9, 18, 36, 72]}
  & 96
  & 14
  & 9
  & 1080
  & 45.1
  & 11.50
  & 0.795
  & 0.377
  & 1751.9
  & -10.839\\
  \#768
  & \footnotesize{[1]}
  & 96
  & 5
  & 72
  & 128
  & 245.1
  & 8.02
  & 1.151
  & 0.529
  & 26301.8
  & -38.075\\
  \#769
  & \footnotesize{[1]}
  & 96
  & 5
  & 72
  & 128
  & 47.6
  & 1.58
  & 1.133
  & 0.530
  & 25688.5
  & -32.278\\
  \#770
  & \footnotesize{[1]}
  & 96
  & 14
  & 18
  & 512
  & 87.6
  & 8.32
  & 1.085
  & 0.528
  & 10844.1
  & -36.840\\
  \#771
  & \footnotesize{[1, 2, 4, 8, 16, 32]}
  & 96
  & 14
  & 9
  & 1024
  & 15.1
  & 4.47
  & 0.810
  & 0.397
  & 1737.2
  & -9.246\\
  \#772
  & \footnotesize{[1, 2, 4, 8, 16, 32, 64, 128]}
  & 96
  & 14
  & 9
  & 1024
  & 17.6
  & 5.27
  & 0.835
  & 0.400
  & 1720.5
  & -9.170\\
  \#773
  & \footnotesize{[1, 16]}
  & 96
  & 14
  & 9
  & 1024
  & 15.1
  & 2.84
  & 0.817
  & 0.400
  & 1658.7
  & -7.184\\
  \#774
  & \footnotesize{[1, 64]}
  & 96
  & 14
  & 9
  & 1024
  & 17.6
  & 3.23
  & 0.877
  & 0.393
  & 1724.9
  & -9.322\\
  \#775
  & \footnotesize{[1, 32]}
  & 96
  & 14
  & 9
  & 1024
  & 22.6
  & 4.15
  & 0.764
  & 0.365
  & 1630.3
  & -9.681\\
  \#776
  & \footnotesize{[1, 32]}
  & 48
  & 14
  & 9
  & 1024
  & 1.0
  & 0.23
  & 1.030
  & 0.445
  & 2013.5
  & -4.622\\
  \#777
  & \footnotesize{[1, 9, 36]}
  & 96
  & 14
  & 9
  & 1080
  & 35.1
  & 7.21
  & 0.802
  & 0.392
  & 1708.3
  & -8.549\\
  \#778
  & \footnotesize{[1, 16, 64]}
  & 96
  & 14
  & 9
  & 1024
  & 47.6
  & 8.94
  & 0.747
  & 0.385
  & 1632.0
  & -7.284\\
  \end{tabularx}
\end{table}
\end{document}

答案1

\rothead使用中的命令makecell以及序言中定义的列标题格式的解决方案。我还建议使用S列类型,将所有数字对齐到小数点上。注意 a4wide已弃用,不应再使用,并且 选项usenames现在xcolor是默认选项。

\documentclass[a4paper,twoside,notitlepage]{report}
\usepackage[showframe]{geometry}%, left=2cm, right=3cm
\usepackage[utf8]{inputenc}
\usepackage{tabularx, makecell, caption}
\usepackage[dvipsnames,svgnames,table]{xcolor}
\usepackage{siunitx}
\usepackage{rotating, graphicx}
\renewcommand{\theadfont}{\normalsize\itshape}
\setlength{\rotheadsize}{3cm}

  \newcolumntype{C}{>{\centering}X}%

  %%% The line for vertical centering
  \def\tabularxcolumn#1{m{#1}}
  %%% ------
\begin{document}

  \begin{table}[h!]
  \centering\setlength{\tabcolsep}{3pt}
  \caption{Table of results}
  \label{tbl:listexperiments}
  \rowcolors{2}{gray!18}{white}
  \begin{tabularx}{\textwidth}{cCc*{2}{S[table-format=2.0]}S[table-format=4.0]S[table-format=3.1] S[table-format=2.2]ccS[table-format=5.1] S[table-format=-2.3]}
  \rowcolor{gray!40}[\tabcolsep][18.7pt]
  \rothead{Experiment number}
  & \rothead{Time scales}
  & \rothead{Hidden units}
  & {\rothead{Prediction length (samples)}}
  & {\rothead{Sample length (minutes)}}
  & {\rothead{Input sequence length (samples)}}
  &{ \rothead{Model training steps (1000s)}}
  & {\rothead{Training time (hours)}}
  & \rothead{Loss value}
  & \rothead{Next Type Error}
  & {\rothead{Next Switch MSE}}
  & {\rothead{Next Switch RMSE}}\\
  \#721
  & \footnotesize{[1, 32]} & 96 & 14 & 9 & 1024 & 80.1 & 14.14 & 0.751 & 0.364 & 1570.8 & -9.043\\
  \#724
  & \footnotesize{[1, 8]}
  & 96 & 14 & 9 & 1024 & 10.1 & 1.98 & 0.818 & 0.408 & 1707.9 & -8.212\\
  \#727
  & \footnotesize{[1]}
  & 96 & 14 & 9 & 1024 & 230.1 & 39.51 & 0.838 & 0.346 & 1853.8 & -14.215\\
  \#730
  & \footnotesize{[1, 8]}
  & 96 & 14 & 9 & 1024 & 180.1 & 33.88 & 0.845 & 0.405 & 1753.2 & -8.222\\
  \#742
  & \footnotesize{[1, 8]}
  & 48 & 14 & 9 & 512 & 5.1 & 0.51 & 0.864 & 0.422 & 1688.2 & -5.685\\
  \#745
  & \footnotesize{[1, 8]}
  & 48 & 14 & 9 & 512 & 1.0 & 0.13 & 1.038 & 0.414 & 2069.8 & -4.907\\
  \#748
  & \footnotesize{[1, 8]}
  & 48 & 14 & 9 & 512 & 22.6 & 2.14 & 0.841 & 0.431 & 1678.6 & -6.614\\
  \#751
  & \footnotesize{[1, 8]}
  & 48 & 14 & 9 & 512 & 2.6 & 0.29 & 0.893 & 0.433 & 1844.3
  & -3.705\\
  \#754
  & \footnotesize{[1, 2, 4, 8, 16]}
  & 96 & 14 & 9 & 1024 & 0.1 & 0.13 & 1.254 & 0.461 & 2661.1 & 5.821\\
  \#757
  & \footnotesize{[1, 2, 4, 8, 16]}
  & 96 & 14 & 9 & 1024 & 325.1 & 93.51 & 0.814 & 0.381 & 1736.5 & -10.174\\
  \#760
  & \footnotesize{[1, 16]}
  & 96 & 14 & 9 & 1024 & 60.1 & 11.30 & 0.811 & 0.387 & 1657.5 & -7.984\\
  \#763
  & \footnotesize{[1, 3, 9, 18, 36, 72]}
  & 96 & 14 & 9 & 1080 & 45.1 & 11.50 & 0.795 & 0.377 & 1751.9 & -10.839\\
  \#768
  & \footnotesize{[1]}
  & 96 & 5 & 72 & 128 & 245.1 & 8.02 & 1.151 & 0.529 & 26301.8 & -38.075\\
  \#769
  & \footnotesize{[1]}
  & 96 & 5 & 72 & 128 & 47.6 & 1.58 & 1.133 & 0.530 & 25688.5 & -32.278\\
  \#770
  & \footnotesize{[1]}
  & 96 & 14 & 18 & 512 & 87.6 & 8.32 & 1.085 & 0.528 & 10844.1 & -36.840\\
  \#771
  & \footnotesize{[1, 2, 4, 8, 16, 32]}
  & 96 & 14 & 9 & 1024 & 15.1 & 4.47 & 0.810 & 0.397 & 1737.2 & -9.246\\
  \#772
  & \footnotesize{[1, 2, 4, 8, 16, 32, 64, 128]}
  & 96 & 14 & 9 & 1024 & 17.6 & 5.27 & 0.835 & 0.400 & 1720.5 & -9.170\\
  \#773
  & \footnotesize{[1, 16]}
  & 96 & 14 & 9 & 1024 & 15.1 & 2.84 & 0.817 & 0.400 & 1658.7 & -7.184\\
  \#774
  & \footnotesize{[1, 64]}
  & 96 & 14 & 9 & 1024 & 17.6 & 3.23 & 0.877 & 0.393 & 1724.9 & -9.322\\
  \#775
  & \footnotesize{[1, 32]}
  & 96 & 14 & 9 & 1024 & 22.6 & 4.15 & 0.764 & 0.365 & 1630.3 & -9.681\\
  \#776
  & \footnotesize{[1, 32]}
  & 48 & 14 & 9 & 1024 & 1.0 & 0.23 & 1.030 & 0.445 & 2013.5 & -4.622\\
  \#777
  & \footnotesize{[1, 9, 36]}
  & 96 & 14 & 9 & 1080 & 35.1 & 7.21 & 0.802 & 0.392 & 1708.3 & -8.549\\
  \#778
  & \footnotesize{[1, 16, 64]}
  & 96 & 14 & 9 & 1024 & 47.6 & 8.94 & 0.747 & 0.385 & 1632.0 & -7.284\\
  \end{tabularx}
\end{table}

\end{document} 

在此处输入图片描述

答案2

只需定义\rot指定单元格格式即可:

  \newcommand*\rot[1]{\multicolumn{1}{@{}l@{}}{\rotatebox{90}{#1}}}

在此处输入图片描述

相关内容