[Tex/LaTex] Vertical alignment (centering) of cells contents in longtable with “m”

longtabletables

I have a table which cells can have one or more lines of text. I want to center all cell contents vertically, while horizontally making text left aligned. So far I have come up with this code:

\documentclass[final,10pt]{book}
\usepackage{longtable,booktabs}
\usepackage{array} % needed for "m" in longtable
\usepackage[paperwidth=9in,paperheight=3in,right=0.5in,bottom=0in,left=0.2in]{geometry}
\begin{document}
\thispagestyle{empty}
\noindent\begin{longtable}{@{} m{.30\paperwidth} m{.30\paperwidth} m{.30\paperwidth}@{}}
\toprule\addlinespace
\textbf{Header 1} & \textbf{Header 2} & \textbf{Header 3}
\\\addlinespace
\toprule\endhead
1. Lorem ipsum dolor sit amet (c1, r1) & This is second column (c2, r1), line one\newline This is second column (c2, r1), line two & This is third column (c3, r1), line one\newline This is third column (c3, r1), line two
\\\addlinespace\hline
2. Lorem ipsum dolor sit amet (c1, r2) & This is second column (c2, r2), line one\newline This is second column (c2, r2), line two & This is third column (c3, r2), line one\newline This is third column (c3, r2), line two
\\\addlinespace\hline
3. Lorem ipsum dolor sit amet (c1, r3) & c2, r3 & c3, r3
\\\addlinespace\hline
4. Lorem ipsum dolor sit amet (c1, r4) & c2, r4, line one \newline c2, r4, line two & c3, r4, line one\newline c3, r4, line two
\\\addlinespace
\bottomrule
\end{longtable}
All text in the cells should be centered vertically and left aligned horizontally.
\end{document}

which produces this:

enter image description here

Only header row contents is properly centered vertically. All other cells are not centered vertically and they differ in how much padding is at the top of the cell.

Why are those cells not centered as intended? Isn't it what m (from array package) in longtable definition is supposed to do? How can I make sure that text in each cell is centered vertically, regardless of how many lines of text is in it?

Best Answer

Instead of manually inserting \addlinespace directives in lots of places, you may want to increase the values of \aboverulesep and \belowrulesep via \addtolength instructions. Separately, do consider using \midrule instead of \hline.

enter image description here

\documentclass[final,10pt]{book}
\usepackage{booktabs}
\addtolength\aboverulesep{0.15ex}  % extra spacing above and below rules
\addtolength\belowrulesep{0.35ex}

\usepackage{longtable, array} % "array" is needed for "m" in longtable

\usepackage[paperwidth=9in,paperheight=3in,right=0.5in,bottom=0in,left=0.2in]{geometry}

\begin{document}
\thispagestyle{empty}

\begin{longtable}{@{} *{3}{m{.30\paperwidth}} @{}}

\toprule
\textbf{Header 1} & \textbf{Header 2} & \textbf{Header 3} \\
\midrule[\heavyrulewidth] % make this rule as thick as \toprule
\endhead

\bottomrule
\endfoot

1. Lorem ipsum dolor sit amet (c1, r1) & This is second column (c2, r1), line one\newline This is second column (c2, r1), line two & This is third column (c3, r1), line one\newline This is third column (c3, r1), line two \\
\midrule
2. Lorem ipsum dolor sit amet (c1, r2) & This is second column (c2, r2), line one\newline This is second column (c2, r2), line two & This is third column (c3, r2), line one\newline This is third column (c3, r2), line two \\
\midrule
3. Lorem ipsum dolor sit amet (c1, r3) & c2, r3 & c3, r3 \\
\midrule
4. Lorem ipsum dolor sit amet (c1, r4) & c2, r4, line one \newline c2, r4, line two & c3, r4, line one\newline c3, r4, line two \\

\end{longtable}
\end{document}
Related Question