1

I'm trying to understand the vertical aligment in a table, because i have to use it in a project. I tried multiple answers in different question but none seem to work for me (eg. here, here or here).

Latex seems to ignore all but the last aligment. Is it possible to align each column or just the whole table?

\documentclass{article}
\usepackage{tabu}
\usepackage{array}
\begin{document}

\begin{tabu}{|p{5em}|m{5em}|b{5em}|b{2em}|}
    \hline
    test & test & test & s s s s s s s s s s s s s s s \\
    \hline
\end{tabu}

\begin{tabular}{|>{\raggedright\arraybackslash}p{5em}|>{\centering\arraybackslash}m{5em}|>{\raggedleft\arraybackslash}b{5em}|p{2em}|}
    \hline
    test & test & test & s s s s s s s s s s s s s s s \\
    \hline
\end{tabular}

\end{document}

Picture of the two tables

3
  • 1
    Welcome to TeX.SE. Your tabular code makes it look like you're trying to influence both the horizontal (\raggedright, \centering, and \raggedleft) and the vertical placement (the p,m, and b column types) of the cells' contents. Please clarify.
    – Mico
    Commented Apr 27, 2021 at 9:03
  • I'm trying to influence the vertical placement in each column separate. With the second table i wanted to show that the horizontal aligment works for each column.
    – Vincent B
    Commented Apr 27, 2021 at 9:05
  • Unrelated but don't use the tabu package, it is broken and unmaintained. See the readme here github.com/tabu-issues-for-future-maintainer/tabu Commented Apr 27, 2021 at 9:07

1 Answer 1

1

The alignment doesn't describe the alignment between the columns but the alignment of a column in relation to the overall baseline of the row.

Columns with only one line are always on the baseline. If they have more then one line they are adjusted.

I removed the tabu package as it is currently broken and unmaintained and shouldn't be used with a current LaTeX.

\documentclass{article}

\usepackage{array}
\usepackage{tikz}
\begin{document}


\begin{tabular}{l|p{5ex}|m{5ex}|b{5ex}|p{2em}||m{2em}|b{2em}|}
    \hline
    \tikz[overlay]\draw[red](0,0)--++(20,0);baseline
     & test 
     & test 
     & test 
     & s s s s s s s s s s s s s s s 
     & s s s s s s s s s s s s s s s
     & s s s s s s s s s s s s s s s\\
    \hline
\end{tabular}

\end{document}

enter image description here

1
  • Ah thanks for the explanation :)
    – Vincent B
    Commented Apr 27, 2021 at 9:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .