1

The tabu environment does not seem to center the text in cells with multiple lines correctly. At the same time, the spacing seems to be erroneous.

Does anybody know how to solve this problem? I have tried \makecell[tc]{sensor \ molecule} but this does seem to create other problems.

MWE:

\documentclass{article}
\usepackage{tabu}
\begin{document}
\begin{tabu} to \linewidth {*6{X[c]}}
    \tabucline{-}
    sensor\newline molecule & position & chemical~shift\newline reference & some &  other &info \\
    \tabucline{-}
    xyz & C$_1$ & aaa & 1.11 &  3.54 & 11.00 \\
    xyz & C$_5$ & bbb & 2.22 & 44.54 & 12.0 \\
    \tabucline{-}
\end{tabu}
\end{document}

Result:

table created with tabu which does not center text in cells with multiple lines correctly

Thank you in advance for any help or suggestion.

1
  • Welcome to TeX - LaTeX! Which package are you using to make the \makecell command available? Mar 10 '17 at 12:11
0

Is this better?

enter image description here

just add \tabulinesep=_3pt^3pt:

\documentclass{article}
\usepackage{geometry} % <-- added
\usepackage{tabu}
\tabulinesep=_3pt^3pt% <-- added

\begin{document}
\begin{tabu} to \linewidth {*6{X[c]}}
    \tabucline{-}
    sensor molecule & position & chemical shift reference & some &  other &info \\
    \tabucline{-}
    xyz & C$_1$ & aaa & 1.11 &  3.54 & 11.00 \\
    xyz & C$_5$ & bbb & 2.22 & 44.54 & 12.0 \\
    \tabucline{-}
\end{tabu}
\end{document}

Off topic: in your table is not need to manually break cell contents, this will done by column type X, if necessary.

Edit: Source of not centering third column header is to wide content. If you make \textwidth longer, for example with adding of package geometry, the content will become correctly centered.

Addendum: Less problems is with tabularx and use booktabs for table's rules. With siunitx you can align numbers at decimal points. For equal width of all columns is used trick with multicolumn environment for S column headers:

enter image description here

\documentclass{article}
\usepackage{geometry}
\usepackage{booktabs,tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\newcommand\mcx[1]{\multicolumn{1}{C}{#1}}
\usepackage{siunitx}

\begin{document}
\begin{tabularx}{\linewidth}{*{3}{C}
                             *{3}{S[table-format=2.2]}}
    \toprule
sensor molecule & position & chemical~shift reference 
    & \mcx{some} & \mcx{other} & \mcx{info} \\

    \midrule
    xyz & C$_1$ & aaa & 1.11 &  3.54 & 11.00 \\
    xyz & C$_5$ & bbb & 2.22 & 44.54 & 12.0 \\
    \bottomrule
\end{tabularx}
\end{document}
4
  • Thank you, this already looks better in the cell containing "sensor molecule". However, the cell containing "chemical shift reference" is still misaligned. Thank you for the off topic comment, you were off course right in this case. How do I solve the problem in the other cell and how is tabulinesep related to centering text in cells? Thanks in advance! Mar 10 '17 at 14:30
  • @user4834588, why you use tabu? This packae is not maintained and buggy ... less problems you will have for example with tabularx. from tabu documentation follows, that tabulinesep hadn't have influence to node aligns. See addendum to my answer.
    – Zarko
    Mar 10 '17 at 15:02
  • Thank you for the solution. I just now noticed that you are missing the line \newcommand\mcx[1]{\multicolumn{1}{C}{#1}}if I am not mistaken, otherwise, the comand mcxis not recognized. Mar 10 '17 at 17:28
  • Thank you for edit my answer! At loading code I accidentally erase wrong line of code or forgot to add it :( .
    – Zarko
    Mar 10 '17 at 18:05

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.