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:
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
.