47

I wonder why p columns are aligned at the bottom and b columns aligned at the top? enter image description here

created with this code:

\begin{tabular}{|p{0.3\linewidth}|m{0.3\linewidth}|b{0.3\linewidth}|}
\hline
\centering header p &
\centering header m &   
\centering header b \tabularnewline
\hline
text which is considerably longer than the width of the column  & 
text which is considerably longer than the width of the column  & 
text which is considerably longer than the width of the column 
\tabularnewline
\hline
\end{tabular}
lockstep
  • 250,273

2 Answers2

61
  • p means normal cells, they are like parbox with alignment at the top line

  • b means alignment at the bottom, so the baseline is at the bottom line

  • m means alignment in the vertical center, i.e. the baseline is in the center.

So the position for alignment is meant. In your picture, the top line of the first text, the middle of the second and the bottom line of the last text are all in a line:

table cell alignment

Stefan Kottwitz
  • 231,401
  • 8
    Ok, I understand. My problem was that it is counter-intuitive. – Matthias Pospiech Nov 18 '11 at 14:57
  • 5
    So if I understand correctly, there is no (simple) way to have a column aligned at the bottom when the other columns are specified with r, l and c? In a table \begin{tabular}{p{1cm}b{1cm}rlc} the three last columns are aligned at the bottom. – Arthur Jan 08 '17 at 15:28
5

For some users who are familiar with word processors, these p and b columns in LaTeX tables are counter-intuitive. With tblr environment of LaTeX3 package tabularray, there are another two column types h and f, which will align cell text at row head and row foot, respectively:

\documentclass{article}
\usepackage{tabularray}
\begin{document}
\begin{tblr}{h{4em}t{4em}m{4em}b{4em}f{4em}}
\hline
{row\\head} & {top\\line} & {middle} & {line\\bottom} & {row\\foot} \\
\hline
{row\\head} & {top\\line} & {11\\22\\mid\\44\\55} & {line\\bottom} & {row\\foot} \\
\hline
\end{tblr}
\end{document}

enter image description here

L.J.R.
  • 10,932
  • How do h and b actually work or mean? Thankfully, you showed how they affect the alignment, but I still don't quite understand their actual meaning to link with their effects. – Diaa Jul 20 '21 at 11:35
  • h means put text in the head of the cell, f means put text in the foot of the cell. – L.J.R. Jul 20 '21 at 11:56
  • And what about the meaning of b and t? Is there a visual explanation of how they place the text? – Diaa Jul 20 '21 at 14:04
  • b means put bottom line in the middle, t means put top line in the middle. – L.J.R. Jul 20 '21 at 14:18