2

Can someone help me understand why are the items in the first row off-centered vertically after I use \makecell in one of the lines and use a linebreak inside of it? Is this behavior default?

\begin{table}[htpb] \caption{One-way ANOVA test between all three groups.} \begin{tabular}{m{2.9cm}K{1.3cm}K{1.3cm}K{1.3cm}K{1.3cm}K{1.3cm}K{1.3cm}} \Xhline{3\arrayrulewidth} \makecell{Source of \\ variation} & \makecell{SS} & df & MS & F & \makecell{P \\ value} & F-crit \\ \Xhline{2\arrayrulewidth} \makecell[l]{Between groups} & 6.012 & 2 & 3.006 & 0.779 & 0.474 & 3.555 \\ \makecell[l]{Within groups} & \makecell{69.440} & \makecell{18} & \makecell{3.858} & & & \\ \\ \makecell[l]{Total} & \makecell{75.452} & \makecell{20} & & & & \\ \Xhline{3\arrayrulewidth} \end{tabular} \end{table} 

enter image description here

K: \newcolumntype{K}1{>{\centering\arraybackslash}m{#1}} (this problem happened before defining this shorthand too)

Edit1: I have read the documentation for the makecell package and, for instance, using \makecell*{} actually improves the vertical alignment a bit, but I can't help but think that this is not the optimal solution.

Edit2: I do realize that the use of Xhline pushes the thickness down towards the row below and makes it feel more out of place, but even not using anything or using \toprule, they still look slightly off-centered.

2
  • What's the reason for using m type columns here? My guess would be that this is caused by the combination of \makecell with m columns. Commented Feb 11, 2024 at 10:34
  • I am using m to be able to set specific lengths for each column, and introduced make cell essentially to be able better linebreak cells with long text. Is this sort of usage not regular? Commented Feb 11, 2024 at 10:38

1 Answer 1

4

I see no reason for guessing the column widths, which TeX can do by itself.

\documentclass{article} \usepackage{booktabs,makecell} \usepackage{siunitx} \begin{document} \begin{table}[htpb] \centering \caption{One-way ANOVA test between all three groups.} \begin{tabular*}{\textwidth}{ @{\extracolsep{\fill}} l S[table-format=2.3] S[table-format=2.0] S[table-format=1.3] S[table-format=1.3] S[table-format=1.3] S[table-format=1.3] @{} } \toprule \makecell{Source of \\ variation} & {SS} & {df} & {MS} & {F} & {\makecell{P \\ value}} & {F-crit} \\ \midrule Between groups & 6.012 & 2 & 3.006 & 0.779 & 0.474 & 3.555 \\ Within groups & 69.440 & 18 & 3.858 & & & \\ \midrule Total & 75.452 & 20 & & & & \\ \bottomrule \end{tabular*} \end{table} \end{document} 

enter image description here

Depending on the text width you're allowed, you might also avoid splitting cells.

\documentclass{article} \usepackage{booktabs,makecell} \usepackage{siunitx} \begin{document} \begin{table}[htpb] \centering \caption{One-way ANOVA test between all three groups.} \begin{tabular*}{\textwidth}{ @{\extracolsep{\fill}} l S[table-format=2.3] S[table-format=2.0] S[table-format=1.3] S[table-format=1.3] S[table-format=1.3] S[table-format=1.3] @{} } \toprule Source of variation & {SS} & {df} & {MS} & {F} & {P value} & {F-crit} \\ \midrule Between groups & 6.012 & 2 & 3.006 & 0.779 & 0.474 & 3.555 \\ Within groups & 69.440 & 18 & 3.858 & & & \\ \midrule Total & 75.452 & 20 & & & & \\ \bottomrule \end{tabular*} \end{table} \end{document} 

enter image description here

2
  • Thanks for the answer. Changing the column type to S did fix it. Furthermore I had never realized that indeed aligning number on the criteria of decimal places makes them much easier to read. This was definitely helpful in that aspect too. I had precisely avoided automatically checking lengths in the past because padding was not spanning the whole textwidth, but the " @{\extracolsep{\fill}}" fixed it too. Thanks a lot. Commented Feb 11, 2024 at 11:03
  • @Fabz Spread tables to the text width only if the difference with the natural size is not big. And, please, in future questions make the code compilable, so we don't have to guess packages and so on. Commented Feb 11, 2024 at 11:11

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.