# How would I center text both vertically and horizontally in a cell in a table?

For some reason, my text doesn't center properly, and is instead offset by a small amount in the vertical direction.

This is the code for this table:

\documentclass{article}
\usepackage{makecell}
\usepackage{textcomp,gensymb}
\usepackage{siunitx}
\usepackage{multirow}
\usepackage{chemfig}
\usepackage{geometry}
\geometry{margin=120pt}
\begin{document}

\begin{center}
\begin{tabular}{| c | c | c | c | c | c | c | c | c | c | c |}
\hline
\multirow{3}{*}{\thead{Temperature \\ (\degree\si{C} $\pm$ 0.1 \degree\si{C})}} & \multicolumn{10}{ c |}{\thead{Volume of \chemfig{MgCl_2} solution added \\ (\si{cm^3} $\pm$ 0.05 \si{cm^3})}} \\ \cline{2-11}

\thead{20} & & & & & & & & & & \\ \hline
\thead{35} & & & & & & & & & & \\ \hline
\thead{50} & & & & & & & & & & \\ \hline
\thead{65} & & & & & & & & & & \\ \hline
\thead{80} & & & & & & & & & & \\ \hline

\end{tabular}
\end{center}
\end{document}


This code outputs this table:

As you can see, the first cell (Temperature (°C ± 0.1 °C)) is slightly off center in the vertical direction. I am making use of the makecell package to format the text. How should I change it so that it is properly centered?

• Welcome into the community of the users of TeX. Please, can you put a complete code adding the packages? It is very important and thank you very much. Nov 26 '20 at 12:55
• I have edited it so that now it compiles --- there was a typo (makecells instead of makecell) and missing begin/end document. Nov 26 '20 at 13:47

You need to shift multirow cell slightly down, for example with use decimal number of text lines in spanned rows:

\multirow{4.4}{*}{\thead{Temperature\\ ($\si{\celsius} \pm\SI{0.1}{\celsius}$)}}


Complete MWE:

\documentclass{article}
\usepackage{geometry}
\geometry{margin=120pt}

%\usepackage{textcomp,gensymb}
\usepackage{siunitx}
\usepackage{makecell, multirow}
\usepackage{chemfig}

\usepackage{xparse}
\NewExpandableDocumentCommand\mcc{O{1}m}
{\multicolumn{#1}{c |}{#2}}

\begin{document}
\begin{center}
\begin{tabular}{| c | c | c | c | c | c | c | c | c | c | c |}
\hline
\multirow{4.4}{*}{\thead{Temperature\\ ($\si{\celsius} \pm\SI{0.1}{\celsius}$)}}
&   \mcc[10]{%
($\si{\per\centi\metre\cubed} \pm\SI{0.05}{\per\centi\metre\cubed}$)}} \\
\cline{2-11}
\cline{2-11}
\hline

\thead{20} & & & & & & & & & & \\ \hline
\thead{35} & & & & & & & & & & \\ \hline
\thead{50} & & & & & & & & & & \\ \hline
\thead{65} & & & & & & & & & & \\ \hline
\thead{80} & & & & & & & & & & \\ \hline

\end{tabular}
\end{center}
\end{document}


Complete MWE, with more correct use of siunitx units and added new command for \multicolumn cells (bot are off-topic, of course :-) )

With \multirow, you have to provide the number of lines of text (which is not exactly the number of rows of the tabular).

With {NiceTabular} of nicematrix you have a command \Block and, for that command, you give in as argument the numbers of rows of the tabular and the content is drawn mathematically at the center of the rectangle of merged cells (\Block may be used to merge cells vertically but also horizontally).

In your case, the use of {NiceTabular} has also the avantage of providing a key hvlines which draws all the rules excepted in the blocks (created by \Block). That's what you want.

\documentclass{article}
\usepackage{textcomp,gensymb}
\usepackage{siunitx}
\usepackage{chemfig}
\usepackage{geometry}
\usepackage{nicematrix}
\geometry{margin=120pt}
\begin{document}

\begin{center}
\NiceMatrixOptions{cell-space-top-limit=3pt}
\begin{NiceTabular}{*{11}{c}}[hvlines]
\Block{3-1}{Temperature \\ (\degree\si{C} $\pm$ 0.1 \degree\si{C})} & \Block{1-10}{Volume of \chemfig{MgCl_2} solution added \\ (\si{cm^3} $\pm$ 0.05 \si{cm^3})} \\
& \Block{1-2}{Trial 1}&  & \Block{1-2}{Trial 2}&  & \Block{1-2}{Trial 3}& & \Block{1-2}{Trial 4}&  & \Block{1-2}{Trial 5} \\
& Start & End & Start & End & Start & End & Start & End & Start & End \\
20 \\
35 \\
50 \\
65 \\
80 \\
\end{NiceTabular}
\end{center}
\end{document}


You need several compilations (because nicematrix uses PGF/Tikz nodes).