2

The content of the latex table does not align to the center of the multirow cell.

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath,amssymb}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage[document]{ragged2e}

\usepackage{array}

\usepackage{multirow}
\usepackage{float}
\usepackage{makecell}

\begin{document}

\begin{table}[hbt!]
\centering
\begin{tabular}{|c|c|c|c|c|c|}
\hline
er & \thead{erg\\eg\\ \text{[ff]}}  & \thead{egeg \\ \text{[fff]}}  & $ff_ef [-]$ &  \thead{wf\\wf} & \thead{wfwff\\wfw} \\ \hline
evev & 433 & 345 & 0.334 & evevev & evev \\ \hline
\multirow{3}{*}{\thead{multivitamin\\tea}} & egeg & \multirow{3}{*}{411} & eg & ege egeg & grteg \\ \cline{2-2}\cline{4-6}
 & ege & & eg & \thead{eg eg\\eg} & \thead{eg eg\\ege\\eg} \\ \cline{2-2}\cline{4-6}
 & egg & & egeg & eg eg  & egeg \\ \hline
\end{tabular}
\caption{title}\label{tab1}
\end{table}

\end{document}

The multivitamin tea and 411 does not align to the center of the cell.

enter image description here

2
  • 1
    Use \multirow{5} instead of \multirow{3}.
    – leandriis
    Mar 7, 2021 at 13:05
  • Text that takes up more than one line currently is smaller than text that takes up multiplw lines. Is this intentional? If not, wither replace \thead with \makecell or add \renemwcommand{\theadfont}{\normalsize} to your document.
    – leandriis
    Mar 7, 2021 at 13:06

2 Answers 2

4

It is not centred because the number-of-rows argument supposes one-lined cells in the rows. If you count the real number of lines in the three rows, you should use use \multirow{5}. Also note that, for fine-tuning, the number-of-rows can have a decimal part.

I simplified the code using \multirowcell{…} since you load makecell, and (unrelated), when in geometry, all margins have the same value, you can simply use as a parameter [margin = …].

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath,amssymb}
\usepackage[margin=2cm]{geometry}
\usepackage[document]{ragged2e}

\usepackage{array}

\usepackage{multirow}
\usepackage{float}
\usepackage{makecell}

\begin{document}

\begin{table}[hbt!]
\centering
\begin{tabular}{|c|c|c|c|c|c|}
\hline
er & \thead{erg\\eg\\ \text{[ff]}} & \thead{egeg \\ \text{[fff]}} & $ff_ef [-]$ & \thead{wf\\wf} & \thead{wfwff\\wfw} \\ \hline
evev & 433 & 345 & 0.334 & evevev & evev \\ \hline
\multirowcell{5}{multivitamin\\tea} & egeg & \multirow{3}{*}{411} & eg & ege egeg & grteg \\ \cline{2-2}\cline{4-6}
 & ege & & eg & \thead{eg eg\\eg} & \thead{eg eg\\ege\\eg} \\ \cline{2-2}\cline{4-6}
 & egg & & egeg & eg eg & egeg \\ \hline
\end{tabular}
\caption{title}\label{tab1}
\end{table}

\end{document} 

enter image description here

3

Here are three versions of your table. In the first version, I only corrected the wrong first argument of \multirow and kept the inconsistent font sizes. In the second table, I also changed the font sized to make sure, the smaller font is only used in the column headers. In the last table, I used nicematrix and its \Block command instead of \multirow and made sure, the font size is consistent throughout the whole table.

enter image description here

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath,amssymb}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage[document]{ragged2e}

\usepackage{array}

\usepackage{multirow}
\usepackage{float}
\usepackage{makecell}

\usepackage{nicematrix} % only needed for the last example.

\begin{document}

\begin{table}[hbt!]
\centering
\begin{tabular}{|c|c|c|c|c|c|}
\hline
er & \thead{erg\\eg\\ {[ff]}}  & \thead{egeg \\ {[fff]}}  & $ff_ef [-]$ &  \thead{wf\\wf} & \thead{wfwff\\wfw} \\ \hline
evev & 433 & 345 & 0.334 & evevev & evev \\ \hline
\multirow{5}{*}{\thead{multivitamin\\tea}} & egeg & \multirow{5}{*}{411} & eg & ege egeg & grteg \\ \cline{2-2}\cline{4-6}
 & ege & & eg & \thead{eg eg\\eg} & \thead{eg eg\\ege\\eg} \\ \cline{2-2}\cline{4-6}
 & egg & & egeg & eg eg  & egeg \\ \hline
\end{tabular}
\caption{corrected multirow option to vertically center contents}\label{tab1}
\end{table}

\begin{table}[hbt!]
\centering
\begin{tabular}{|c|c|c|c|c|c|}
\hline
\thead{er} & \thead{erg\\eg\\ {[ff]}}  & \thead{egeg \\ {[fff]}}  & \thead{$ff_ef [-]$} &  \thead{wf\\wf} & \thead{wfwff\\wfw} \\ \hline
evev & 433 & 345 & 0.334 & evevev & evev \\ \hline
\multirow{5}{*}{\makecell{multivitamin\\tea}} & egeg & \multirow{5}{*}{411} & eg & ege egeg & grteg \\ \cline{2-2}\cline{4-6}
 & ege & & eg & \makecell{eg eg\\eg} & \makecell{eg eg\\ege\\eg} \\ \cline{2-2}\cline{4-6}
 & egg & & egeg & eg eg  & egeg \\ \hline
\end{tabular}
\caption{corrected multirow option to vertically center contents + smaller font size in column headers only}\label{tab1}
\end{table}

\begin{table}[hbt!]
\centering
\begin{NiceTabular}{cccccc}[hvlines]
er & \makecell{erg\\eg\\ {[ff]}}  & \makecell{egeg \\ {[fff]}}  & $ff_ef [-]$ &  \makecell{wf\\wf} & \makecell{wfwff\\wfw} \\ 
evev & 433 & 345 & 0.334 & evevev & evev \\ 
\Block{3-1}{multivitamin\\tea} & egeg & \Block{3-1}{411} & eg & ege egeg & grteg \\
 & ege & & eg & \makecell{eg eg\\eg} & \makecell{eg eg\\ege\\eg} \\
 & egg & & egeg & eg eg  & egeg \\ \hline
\end{NiceTabular}
\caption{vertically centered content using nicematrix and its Block command + consistent font size throughout the table}\label{tab1}
\end{table}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .