0

I have the following table for which I would like to center horizontally and vertically the contents of each cell. However I would like to not vertically center the headings, they should be aligned to the bottom of the heading cell. I'm using tabularx for the second column.

Using the following code, the headings are not all aligned to the bottom. How can I align all the headings to the bottom while keeping the content cells this way? The line emphasized with comments causes this problem, but also seems to be the only way to vertically center the cells. With line 2 Without line 2, this is how the headings should be.

\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}
  • please edit your example to be a complete document that produces the image so that people can see the issue and test answers, \rot is not defined... – David Carlisle Sep 15 '17 at 11:22
  • Sorry about that, I have added: \newcommand*\rot{\rotatebox{90}} – Jeroen van de Ven Sep 15 '17 at 11:24
1

A solution with the \rothead command from makecell, and a formatting of column heads defined in the preamble. I also suggest using the S column type, to align all numbers on the decimal dot. Note a4wideis deprecated and shouldn't be used any more, and the usenames option of xcolor is now the default.

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

enter image description here

  • good trick withuse of rowcolor ! (+1). i prepare almost the same solution, but had problems with coloring of the first row: \sisetup{group-minimum-digits=4} \caption{Table of results} \label{tbl:listexperiments}\rowcolors{2}{gray!18}{white}\begin{tabularx}{\textwidth}{c>{\footnotesize}C *{3}{S[table-format=2.0]} S[table-format=4.0] S[table-format=3.1] S[table-format=2.2] *{2}{S[table-format=1.3]} S[table-format=5.1] S[table-format=-2.3] } – Zarko Sep 15 '17 at 13:07
  • makecell seems to have problems with colours in tables. I don't know exactly what it does that generate this problem. Some times it can be solved with the optional arguments of columncolor/\rowcolor, sometimes it can't and we have to do without the package (a typical example, if I remember well, it that the gape commands do not work if we use colour in table). – Bernard Sep 15 '17 at 13:12
0

Just define \rot to specify the cell format as well:

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

enter image description here

  • Unfortunately in this case the headers don't nicely align centered with the data in the horizontal direction. – Jeroen van de Ven Sep 16 '17 at 10:37
  • @Jeroen I used l in the multi column you could use c instead – David Carlisle Sep 16 '17 at 10:50
  • That's better, I like that this achieves the desired result while changing only one line. The output looks like: !Output – Jeroen van de Ven Sep 16 '17 at 11:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.