# Table custom cell vertical alignment

I would like to create a table that has its cells' contents vertically aligned to the top, i.e. the default behaviour, but I would also like for some of the cells to have their contents vertically centered. Here's an example:

\begin{tabular}{p{4cm}p{5cm}p{5cm}p{5cm}}
\toprule
This cell is vertically centered. &
This cell is aligned to the top. It's also going to be a lot longer than the rest, defining the maximum height of the row. &
This cell is aligned to the top as well. &
This is another vertically centered cell. \\
\midrule
This cell should be vertically centered. &
This one too. &
This one has regular alignment, i.e. to the top. It's also the longest cell on the row. &
This one is regular too. \\
\bottomrule
\end{tabular}


How could I make the first and the last cells of the first row, as well as the first two cells of the second row, be vertically centered (i.e. in the middle)? The following doesn't seem to work:

\begin{tabular}{p{4cm}p{5cm}p{5cm}p{5cm}}
\toprule
\multicolumn{1}{m{4cm}}{This cell is vertically centered.} &
This cell is aligned to the top. It's also going to be a lot longer than the rest, defining the maximum height of the row. &
This cell is aligned to the top as well. &
\multicolumn{1}{m{4cm}}{This is another vertically centered cell.} \\
\midrule
\multicolumn{1}{m{5cm}}{This cell should be vertically centered.} &
\multicolumn{1}{m{5cm}}{This one too.} &
This one has regular alignment, i.e. to the top. It's also the longest cell on the row. &
This one is regular too. \\
\bottomrule
\end{tabular}


And here's roughly what I want to achieve (table made in Microsoft Word):

You can do that with multirow. Contrary to its name, the \multirow command requires counting the total number of lines, not the number of rows. You also may have to do a small adjustment to get a precise vertical alignment.

In the code below, I had to change the widths of the table columns to avoid overflowing into the right margin:

\documentclass{report}
\usepackage{geometry} %
\usepackage{array}
\usepackage[]{multirow, graphicx, hhline, rotating, makecell, booktabs}

\begin{document}

\noindent\begin{tabular}{@{}p{3cm}*{3}{p{4cm}}@{}}
\toprule
\multirow{5}{\linewidth}{This cell is vertically centered.} &
This cell is aligned to the top. It's also going to be a lot longer than the rest, defining the maximum height of the row. &
This cell is aligned to the top as well. &
\multirow{5}{\linewidth}{This is another vertically centered cell.} \\
\midrule
\multirow{4}{\linewidth}{This cell should be vertically centered.} &
\multirow{4}{\linewidth}{This one too.} &
This one has regular alignment, i.e. to the top. It's also the longest cell on the row. &
This one is regular too. \\
\bottomrule
\end{tabular}

\end{document}


• That does achieve what I want, but I need to manually specify the height (as a number of lines). Is there a way to automatically get the number of lines of the tallest cell in the row? – user113810 Sep 9 '16 at 14:23
• As far as I know, there's no automatic solution to calculate the height of adjacent cells. – Bernard Sep 9 '16 at 14:30