2

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}
    & \multicolumn{2}{ c |}{\thead{Trial 1}}  & \multicolumn{2}{ c |}{\thead{Trial 2}}  & \multicolumn{2}{ c |}{\thead{Trial 3}} & \multicolumn{2}{ c |}{\thead{Trial 4}}  & \multicolumn{2}{ c |}{\thead{Trial 5}} \\ \cline{2-11}
    & \thead{Start} & \thead{End} & \thead{Start} & \thead{End} & \thead{Start} & \thead{End} & \thead{Start} & \thead{End} & \thead{Start} & \thead{End} \\ \hline

    \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: 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?

  • 3
    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. – Sebastiano Nov 26 '20 at 12:55
  • 1
    I have edited it so that now it compiles --- there was a typo (makecells instead of makecell) and missing begin/end document. – Rmano Nov 26 '20 at 13:47
2

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]{%
        \thead{Volume of \chemfig{MgCl_2} solution added \\ 
               ($\si{\per\centi\metre\cubed} \pm\SI{0.05}{\per\centi\metre\cubed}$)}} \\
    \cline{2-11}
    & \mcc[2]{\thead{Trial 1}}  
        & \mcc[2]{\thead{Trial 2}}  
            & \mcc[2]{\thead{Trial 3}} 
                & \mcc[2]{\thead{Trial 4}}  
                    & \mcc[2]{\thead{Trial 5}} \\ 
    \cline{2-11}
    & \thead{Start} & \thead{End} & \thead{Start} & \thead{End} & \thead{Start} & \thead{End} 
    & \thead{Start} & \thead{End} & \thead{Start} & \thead{End} \\
    \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 :-) )

enter image description here

1

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

Output of the above code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.