# Centre cell contents vertically

Consider this example:

\documentclass{article}
\begin{document}
\begin{tabular}{ p{0.1\textwidth}l }
gdgd asfsdf akku  & 5  \\
\end{tabular}
\end{document}


How can I centre the contents of cell 01 vertically?

• use m (array package) not p – David Carlisle Apr 21 at 12:02

Here are three different possible solutions:

\documentclass{article}
\usepackage{array}    % Only needed for the first example.
\usepackage{multirow} % Only needed for the third example.
\begin{document}

Using the vertically centered m type column:

\begin{tabular}{ m{0.1\textwidth}l }
gdgd asfsdf akku  & 5  \\
\end{tabular}

\bigskip

Using three different rows for the text in the first column:

\begin{tabular}{ p{0.1\textwidth}l }
gdgd\\
asfsdf   & 5\\
akku   \\
\end{tabular}

\bigskip

Using multirow:

\begin{tabular}{ p{0.1\textwidth}l }
gdgd asfsdf akku  & \multirow{3}{*}{5}  \\
\end{tabular}
\end{document}


You can use multirow with a single cell, but you have to count the number of lines in this cell, on order to vertically centre its contents. Note that you can use decimal numbers to fine-tune the placement.

Alternatively, use the m{...} column type for the left column (requires loading array):

\documentclass{article}
\usepackage{array}
\usepackage{multirow}

\begin{document}

\begin{tabular}{m{0.1\textwidth}l }
gdgd asfsdf akku & 5 \\
\end{tabular}
\begin{tabular}{p{0.1\textwidth}l }
gdgd asfsdf akku & \multirow{3}{*}{5}\\
\end{tabular}

\end{document}


A possible solution would be using the multirow package (But it requires you to split cell on the left into three cells and putting the text of the right cell into a multirow-cell that spans over three rows). A working example would be:

\documentclass{article}                                                                     \usepackage{multirow}
\begin{document}
\begin{tabular}{ p{0.1\textwidth}l }
gdgd & \multirow{3}{*}{5} \\
asfsdf \\
akku \\
\end{tabular}
\end{document}


A little explanation on the code:

gdgd & \multirow{3}{*}{5} \\


Inserts gdgd as the first entry of the first row and an multirow-cell that spans over three rows (the first parameter) inherits the width of the original column (second parameter set as *) and contains the text "5" (last parameter). \\ indicates the linebreak

asfsdf \\


Inserts asfsdf into the first entry of the second line. Another entry in this line is not necessary because of the multirow-cell above.