1

I'm writing a paper and I'm not very familiar with Latex. I have chosen the tabularx environment as it allowed automatic alignment with the text. Although, in the last table that I made, it did a strange thing: the last column was not vertically centered. Can somebody help? I can't find anything working on the internet...thanks a lot!

%helmet
\newcolumntype{s}{>{\hsize=.35\hsize\centering\arraybackslash}X} \newcolumntype{b}{>{\hsize=.07\hsize\centering\arraybackslash}X}
\newcolumntype{c}{>{\hsize=.11\hsize\centering\arraybackslash}X}
\newcolumntype{d}{>{\hsize=.18\hsize\centering\arraybackslash}X}
\begin{table}[htbp] \label{table: valhelmet}
\renewcommand*{\tabularxcolumn}[1]{m{#1}}
\caption{Survey helmet Stanley}
    \centering
    \begin{tabularx}{\textwidth}{| s | b | b | b | b | b || c | d |}
        \hline
        \textbf{Rating:} & \textbf{1} & \textbf{2} & \textbf{3} & \textbf{4} & \textbf{5} & \textbf{Mean} & \textbf{Standard Deviation}   
        
        \\ \hline\hline
        
        \textbf{Comfort of the helmet}   &  1 & 0 & 2 & 0 & 0 & 2.33 & 1.15
        
        \\ \hline
        
        \textbf{Wight of the helmet}   &  0 & 1 & 1 & 1 & 0 & 3.00 & 1.00
        
        \\ \hline
        
        \textbf{Comparison between 0having the camera inside (1) and in front (5) of the helmet}   &  2 & 1 & 0 & 0 & 0 & 1.33 & 0.58
        
        \\ \hline
        
        \textbf{Communication quality}   &  0 & 1 & 1 & 0 & 1 & 3.33 & 1.53
        
        \\ \hline
        
        \textbf{Comparison between HMT-1 (1) and AVATOUR (5): communication}   &  1 & 1 & 0 & 0 & 0 & 1.50 & 0.71
        
        \\ \hline
        
         \textbf{Comparison between HMT-1 (1) and AVATOUR (5): overall}   &  0 & 0 & 1 & 1 & 0 & 3.50 & 0.71
        
        \\ \hline
        
    \end{tabularx}
\end{table}

Screenshot of the problem

3

2 Answers 2

3

There is no need for multiple columns derived from the X type. A single X type column and c for the remaining columns should be sufficient. I'd also abbreviatee "Standard Deviation".

In the following MWE, I also included a second example in which I removed all vertical and most horizontal lines, used no bold text and slightly rearranged/shortened the information in the first column:

enter image description here

\documentclass{article}
\usepackage{tabularx}

%%% only used in the second example:
\usepackage{makecell}
\renewcommand{\theadfont}{\normalsize}
\usepackage{booktabs}

\begin{document}

%helmet
\newcolumntype{s}{>{\hsize=.35\hsize\centering\arraybackslash}X} \newcolumntype{B}{>{\hsize=.07\hsize\centering\arraybackslash}X}
\newcolumntype{C}{>{\hsize=.11\hsize\centering\arraybackslash}X}
\newcolumntype{d}{>{\hsize=.19\hsize\centering\arraybackslash}X}
\begin{table}[htbp] 
\renewcommand*{\tabularxcolumn}[1]{m{#1}}
\caption{Survey helmet Stanley}
\label{table: valhelmet} % place this after the caption to prevent wrong cross referencing
    \centering
    \begin{tabularx}{\textwidth}{| >{\centering\arraybackslash}X | c | c | c | c | c || c | c |}
        \hline
        \textbf{Rating:} & \textbf{1} & \textbf{2} & \textbf{3} & \textbf{4} & \textbf{5} & \textbf{Mean} & \textbf{Std.\ Dev.}   
        
        \\ \hline\hline
        
        \textbf{Comfort of the helmet}   &  1 & 0 & 2 & 0 & 0 & 2.33 & 1.15
        
        \\ \hline
        
        \textbf{Wight of the helmet}   &  0 & 1 & 1 & 1 & 0 & 3.00 & 1.00
        
        \\ \hline
        
        \textbf{Comparison between 0having the camera inside (1) and in front (5) of the helmet}   &  2 & 1 & 0 & 0 & 0 & 1.33 & 0.58
        
        \\ \hline
        
        \textbf{Communication quality}   &  0 & 1 & 1 & 0 & 1 & 3.33 & 1.53
        
        \\ \hline
        
        \textbf{Comparison between HMT-1 (1) and AVATOUR (5): communication}   &  1 & 1 & 0 & 0 & 0 & 1.50 & 0.71
        
        \\ \hline
        
         \textbf{Comparison between HMT-1 (1) and AVATOUR (5): overall}   &  0 & 0 & 1 & 1 & 0 & 3.50 & 0.71
        
        \\ \hline
        
    \end{tabularx}
\end{table}



\begin{table}[htbp] 
\caption{Survey helmet Stanley}
\label{table: valhelmet}
    \begin{tabularx}{\textwidth}{X *{7}{c}}
        \toprule
        \thead[l]{Rating} & \thead{1} & \thead{2} & \thead{3} & \thead{4} & \thead{5} & \thead{Mean} & \thead{Std.\ Dev.}   \\ 
        \midrule
        Comfort of the helmet                     &  1 & 0 & 2 & 0 & 0 & 2.33 & 1.15 \\ \addlinespace
        Weight of the helmet                      &  0 & 1 & 1 & 1 & 0 & 3.00 & 1.00 \\ \addlinespace
        Camera position: inside (1) vs. front (5) &  2 & 1 & 0 & 0 & 0 & 1.33 & 0.58 \\\addlinespace
        Communication quality                     &  0 & 1 & 1 & 0 & 1 & 3.33 & 1.53 \\\addlinespace
        HMT-1 (1) vs. AVATOUR (5)                                                    \\
        \quad Communication                       &  1 & 1 & 0 & 0 & 0 & 1.50 & 0.71 \\ 
        \quad Overall                             &  0 & 0 & 1 & 1 & 0 & 3.50 & 0.71 \\ 
        \bottomrule
        
    \end{tabularx}
\end{table}

\end{document}
4
  • Thank you so much @leandriis! Jul 28, 2021 at 19:00
  • 1
    Std.\ Dev. or Std.\@ Dev. so the extended space after a period doesn't kick in. I spotted it as soon as I looked at the output.
    – egreg
    Jul 28, 2021 at 20:29
  • @egreg: Thanks for bringing this up. I have edited my answer accordingly.
    – leandriis
    Jul 29, 2021 at 20:09
  • Well, the same is with vs. where it's less evident.
    – egreg
    Jul 29, 2021 at 20:23
2

Edit: Now is considered talltblr table, available in the tabularray package version 2021M (2021-08-01) up (original answer has used longtblr). It is an alternative to threeparttable environment. It can't cross multiple pages, but it can be put inside table environment.:

\documentclass{article}
\usepackage{tabularray}

\begin{document}
    \begin{table}[htb] 
\begin{talltblr}[
    caption={Survey helmet Stanley},
    label={table: valhelmet},
    note{a} = {\textbf{SD}: \textbf{S}tandard \textbf{D}eviation}
                ]%
    {hlines, vlines,
     hline{1,2,8} =0.8pt,
     vline{7} = 0.8pt,
     colspec = {X[1,l,m] *{7}{c}  }, %*{7}{c}
     column{1} = {font=\bfseries},
     row{1} = {font=\bfseries},
     }
Rating: & 1 & 2 & 3 & 4 & 5 & Mean & SD\TblrNote{a}     \\  
Comfort of the helmet
        & 1 & 0 & 2 & 0 & 0 & 2.33 & 1.15   \\
Wight of the helmet
        & 0 & 1 & 1 & 1 & 0 & 3.00 & 1.00   \\
Comparison between 0 having the camera inside (1) and in front (5) of the helmet
        & 2 & 1 & 0 & 0 & 0 & 1.33 & 0.58   \\
Communication quality
        & 0 & 1 & 1 & 0 & 1 & 3.33 & 1.53   \\
Comparison between HMT-1 (1) and AVATOUR (5): communication  
        & 1 & 1 & 0 & 0 & 0 & 1.50 & 0.71   \\
Comparison between HMT-1 (1) and AVATOUR (5): overall
        & 0 & 0 & 1 & 1 & 0 & 3.50 & 0.71   \\
\end{talltblr}
    \end{table}
\end{document}

enter image description here

5
  • 1
    Good, but why longtblr? I don't think this needs to be split across pages.
    – egreg
    Jul 28, 2021 at 20:31
  • 1
    @egreg, I wonder to. So far only longtblr offer (according to my knowledge) features similar to ones provided by threeparttable. Hopefully one day it will be possible to write table notes also to tblr.
    – Zarko
    Jul 28, 2021 at 20:54
  • @egreg @Zarko I have submitted version 2021M of tabularray package to CTAN, which added a talltblr environment similar to threeparttable.
    – L.J.R.
    Aug 1, 2021 at 9:09
  • @L.J.R., thank you very much! I looking forward to test tis version of tblr.
    – Zarko
    Aug 1, 2021 at 11:18
  • @egreg, edited answer now consider talltblr, which is added to tabularray 2021M (2021-08-01).
    – Zarko
    Aug 6, 2021 at 10:21

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.