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

  • 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 Apr 27 '21 at 09: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 Apr 27 '21 at 09:05
  • Unrelated but don't use the tabu package, it is broken and unmaintained. See the readme here https://github.com/tabu-issues-for-future-maintainer/tabu – Ulrike Fischer Apr 27 '21 at 09:07

1 Answers1

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]\drawred--++(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

Ulrike Fischer
  • 327,261