TransWikia.com

Vertical alignment instructions are reversed with tabular

TeX - LaTeX Asked by Joseph Garnier on April 21, 2021

According to Overleaf documentation for tables, I have to use m{}, p{} or b{} to vertically align my text, but for some unknown reason, in a three-column test table, the instruction in the first column has an effect on the third column (here m{}), the second has an effect on the first, and the third has an effect on the second column.

Here is a minimal example from the overleaf documentation. I have the same effect on overleaf and on my local installation updated in October 2020.

documentclass{article}
usepackage[utf8]{inputenc}
usepackage{array}
setlength{arrayrulewidth}{1mm}
setlength{tabcolsep}{18pt}
renewcommand{arraystretch}{1.5}

begin{document}
begin{tabular}{|m{3cm}|b{3cm}|p{3cm}|}
  hline
  multicolumn{3}{|c|}{Country List} 
  hline
  Country Name or Area Name& ISO ALPHA 2 Code &ISO ALPHA 3 
  hline
  Afghanistan & AF &AFG 
  Aland Islands & AX   & ALA 
  Albania &AL & ALB 
  Algeria    &DZ & DZA 
  American Samoa & AS & ASM 
  Andorra & AD & AND   
  Angola & AO & AGO 
  hline
end{tabular}
end{document}

enter image description here

Would you know why? This is the first time I have this problem in 9 years of using Latex. Is it a bug in the last array package version?

One Answer

I'm not sure what you mean when you say that the columns influence each other. The output is precisely what it should be. The p-column is basically a top-aligned parbox, the b-column a bottom-aligned one, and the m column a center-aligned one. If I add the baselines in your tabular

documentclass{article}
usepackage[utf8]{inputenc}
usepackage{array}
setlength{arrayrulewidth}{1mm}
setlength{tabcolsep}{18pt}
renewcommand{arraystretch}{1.5}

deffoo{leavevmodehbox to 0pt{hss vrule width 5cm height .4pthss}}


begin{document}
begin{tabular}{|m{3cm}|b{3cm}|p{3cm}|}
  hline
  multicolumn{3}{|c|}{Country List} 
  hline
  foo Country Name or Area Name& ISO ALPHA 2 Codefoo & foo ISO ALPHA 3 
  hline
  Afghanistan & AF &AFG 
  Aland Islands & AX   & ALA 
  Albania &AL & ALB 
  Algeria    &DZ & DZA 
  American Samoa & AS & ASM 
  Andorra & AD & AND   
  Angola & AO & AGO 
  hline
end{tabular}
end{document}

enter image description here

you'll see that the bottom line of the second (b) column is correctly aligned with the top (and only) line of the third (p) column; the first column (m) is centered, so its top baseline is higher.

To make more clear what the alignment with respect to the baseline means, consider the following sequence of three parboxes

documentclass{article}
newcommand*{baseline}{rule{1cm}{.2pt}}
newcommand*{foo}[1]{{setlength{fboxsep}{-fboxrule}fbox{parbox[#1]{1cm}{raggedright Foo bar baz bar}}}}
begin{document}
baselinefoo{c}baselinefoo{b}baselinefoo{t}
end{document}

enter image description here

Correct answer by campa on April 21, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP