# Cannot place center while using multirow

I cannot make "Beda Maju", "Beda Mundur", and "Beda Pusat" vertically centered. How do I do this?

If I change * in \multirow{2}{*} to \multirow{2}{2.5cm}, the problem is not fixed.

Here is my code.

\begin{table}[h]
\centering
\caption{Tabel Turunan Numerik Beda Hingga}
\label{tabelbedahingga}
\resizebox{\textwidth}{!}{
\begin{tabular}{|c|c|c|c|}
\hline
\rowcolor{green!10}
\multicolumn{2}{|c|}{Beda Hingga}&Rumus&Orde Kesalahan\\
\hline
\multirow{2}{*}{Beda Maju}&Turunan Pertama&$y'_i =\dfrac{y_{i+1}-y_{i}}{h}$&$O(h)$\\
\cline{2-3}
&Turunan Kedua&$y''_i =\dfrac{y_{i+2}-2y_{i+1}+y_i}{h^2}$&$O(h)$\\
\hline
\multirow{2}{*}{Beda Mundur}&Turunan Pertama&$y'_i=\dfrac{y_{i}-y_{i-1}}{h}$&$O(h)$\\
\cline{2-3}
&Turunan Kedua&$y''_i =\dfrac{y_{i}-2y_{i-1}+y_{i-2}}{h^2}$&$O(h)$\\
\hline
\multirow{3}{*}{Beda Pusat} &Turunan Pertama&$y'_i=\dfrac{y_{i+1}-y_{i-1}}{2h}$&$O(h^2)$\\
\cline{2-3}
&\multirow{2}{*}{Turunan Kedua}&$y''_i =\dfrac{y_{i+2}-2y_{i}+y_{i-2}}{4h^2}$&$O(h^2)$\\
\cline{3-3}
&&$y''_i =\dfrac{y_{i+1}-2y_{i}+y_{i-1}}{h^2}$&$O(h^2)$\\
\hline
\end{tabular}
}
\end{table}

• You want them to be vertically centred, if I understand well? Commented May 28, 2019 at 8:54
• Yes, vertically centered. Commented May 28, 2019 at 12:02

I suppose you want the multirows contents vertically centred, which can be done by trial and error using the vertical move optional argument.

I added some padding to the cells with the cellspace package, and a more sensible spacing between caption and table with the caption package.

\documentclass{article}
\usepackage{amsmath}
\usepackage{multirow, caption}
\usepackage{cellspace}
\setlength{\cellspacetoplimit}{4pt}
\setlength{\cellspacebottomlimit}{4pt}
\usepackage[table]{xcolor}

\begin{document}

\begin{table}[h]
\centering
\caption{Tabel Turunan Numerik Beda Hingga}
\label{tabelbedahingga}
\begin{tabular}{|c|c|Sc|Sc|}
\hline
\rowcolor{green!10}
\multicolumn{2}{|c|}{Beda Hingga}&Rumus&Orde Kesalahan\\
\hline
\multirow{2}{*}[-1.6ex]{Beda Maju}&Turunan Pertama&$y'_i =\dfrac{y_{i+1}-y_{i}}{h}$&$O(h)$\\
\cline{2-3}
&Turunan Kedua&$y''_i =\dfrac{y_{i+2}-2y_{i+1}+y_i}{h^2}$&$O(h)$\\
\hline
\multirow{2}{*}[-1.6ex]{Beda Mundur}&Turunan Pertama&$y'_i=\dfrac{y_{i}-y_{i-1}}{h}$&$O(h)$\\
\cline{2-3}
&Turunan Kedua&$y''_i =\dfrac{y_{i}-2y_{i-1}+y_{i-2}}{h^2}$&$O(h)$\\
\hline
\multirow{3}{*}[-3.5ex]{Beda Pusat} &Turunan Pertama&$y'_i=\dfrac{y_{i+1}-y_{i-1}}{2h}$&$O(h^2)$\\
\cline{2-3}
&\multirow{2}{*}[-1.7ex]{Turunan Kedua}&$y''_i =\dfrac{y_{i+2}-2y_{i}+y_{i-2}}{4h^2}$&$O(h^2)$\\
\cline{3-3}
&&$y''_i =\dfrac{y_{i+1}-2y_{i}+y_{i-1}}{h^2}$&$O(h^2)$\\
\hline
\end{tabular}
\end{table}

\end{document}

• Thank you very much, @Bernard ! That's what I want.. Commented May 28, 2019 at 12:03

Vertical centering of cell contents is not a trivial issue.

The previous answer just solves the problem by using manual adjustment. Another approach could be lying about the row number in the \multirow statements. It is shown below.

This also solves the cosmetic matter. However, in my opinion they are not satisfactory solutions, and I would love a general method to do this.

\documentclass{article}

\usepackage{amsmath}
\usepackage{multirow,cellspace,caption}
\usepackage[table]{xcolor}
\usepackage{graphicx}

\setlength{\cellspacetoplimit}{4pt}
\setlength{\cellspacebottomlimit}{4pt}

\begin{document}
\begin{table}[h]
\centering
\caption{Tabel Turunan Numerik Beda Hingga}
\label{tabelbedahingga}
\begin{tabular}{|c|c|Sc|c|}
\hline
\rowcolor{green!10}
\multicolumn{2}{|c|}{Beda Hingga} & Rumus & Orde Kesalahan\\
\hline
\multirow{3}{*}{Beda Maju}
& Turunan Pertama & $y'_i =\dfrac{y_{i+1}-y_{i}}{h}$&$O(h)$\\
\cline{2-3}
& Turunan Kedua & $y''_i =\dfrac{y_{i+2}-2y_{i+1}+y_i}{h^2}$ & $O(h)$ \\
\hline
\multirow{3}{*}{Beda Mundur}
& Turunan Pertama & $y'_i=\dfrac{y_{i}-y_{i-1}}{h}$&$O(h)$\\
\cline{2-3}
& Turunan Kedua & $y''_i =\dfrac{y_{i}-2y_{i-1}+y_{i-2}}{h^2}$&$O(h)$\\
\hline
\multirow{5}{*}{Beda Pusat}
& Turunan Pertama & $y'_i=\dfrac{y_{i+1}-y_{i-1}}{2h}$&$O(h^2)$\\
\cline{2-3}
& \multirow{3}{*}{Turunan Kedua}
& $y''_i =\dfrac{y_{i+2}-2y_{i}+y_{i-2}}{4h^2}$&$O(h^2)$\\
\cline{3-3}
&   & $y''_i =\dfrac{y_{i+1}-2y_{i}+y_{i-1}}{h^2}$&$O(h^2)$\\
\hline
\end{tabular}
\end{table}
\end{document}
• Thank you for helping me, @e_moro Commented May 28, 2019 at 12:07

If your are willing to change to another tabular package, the package cals will make it easy to construct the tabular your are asking for:

\documentclass{article}
\usepackage{amsmath, nccmath, caption, CALS}
\usepackage[table]{xcolor}
\usepackage{nccmath}

\let\nc=\nullcell   %Shortcuts
\let\sc=\spancontent

\begin{document}

\begin{table}
\centering
\caption{Tabel Turunan Numerik Beda Hingga}
\label{tabelbedahinggaga}
\begin{calstable}

% Define four columns relative to margin, makes it easy to find correct tabular width
\colwidths{{\dimexpr(\columnwidth/40* 7)\relax}
{\dimexpr(\columnwidth/40* 9)\relax}
{\dimexpr(\columnwidth/40* 13)\relax}
{\dimexpr(\columnwidth/40* 11)\relax}
}

% Set up a basic grid
\makeatletter
\def\cals@framers@width{0.8pt}
\def\cals@framecs@width{0.8pt}
\cals@setcellprevdepth{Al}
\def\cals@cs@width{0.4pt}
\def\cals@rs@width{0.4pt}

% Tabular starts
\brow
\def\cals@bgcolor{green!15} % Switch on colour
\nc{ltb}
\nc{rtb}\alignC\sc{\vfil Beda Hingga} % Horizontal centering the last until reset
\cell{\vfil Rumus}
\cell{\vfil Orde Kesalahan}
\def\cals@bgcolor{}   % Switch off colour
\erow
\mdseries}
% R2
\brow
\nc{lrt}
\cell{\vfil Turunan Pertama}
\cell{\vfil $y'_i =\dfrac{y_{i+1}-y_{i}}{h}$}
\def\cals@borderB{0pt}
\cell{$O(h)$}
\let\cals@borderB\relax
\erow
%R3
\brow
\nc{lrb}\alignC\sc{\vfil Beda Maju}
\cell{\vfil Turunan Kedua}
\cell{\vfil $y''_i =\dfrac{y_{i+2}-2y_{i+1}+y_i}{h^2}$}
\cell{\vfil $O(h)$}
\erow
%R4
\brow
\nc{lrt}
\cell{\vfil Turunan Pertama}
\cell{\vfil $y'_i=\dfrac{y_{i}-y_{i-1}}{h}$}
\def\cals@borderB{0pt} % Switch on bottom border
\cell{\vfil $O(h)$}
\let\cals@borderB\relax % % Switch off bottom border
\erow
%R5
\brow
\nc{lrb}\alignC\sc{\vfil Beda Mundur}
\cell{\vfil Turunan Kedua}
\cell{\vfil $y''_i =\dfrac{y_{i}-2y_{i-1}+y_{i-2}}{h^2}$}
\cell{\vfil $O(h)$}
\erow
%R6
\brow
\nc{lrt}
\cell{\vfil Turunan Pertama}
\cell{\vfil $y'_i=\dfrac{y_{i+1}-y_{i-1}}{2h}$}
\def\cals@borderB{0pt} % Switch on bottom border
\cell{\vfil $O(h^2)$}
\let\cals@borderB\relax %% Switch off bottom border
\erow
%R7
\brow
\nc{lr}
\nc{lrt}
\cell{\vfil $y''_i =\dfrac{y_{i+2}-2y_{i}+y_{i-2}}{4h^2}$}
\def\cals@borderB{0pt}  % Switch off bottom border.
\cell{\vfil $O(h^2)$}
\let\cals@borderB\relax % Switch on bottom border
\erow
%R8
\brow
\nc{lrb}\alignC\sc{\vfil Beda Pusat}
\nc{lrb}\sc{\vfil Turunan Kedua}
\cell{\vfil $y''_i =\dfrac{y_{i+1}-2y_{i}+y_{i-1}}{h^2}$}
\cell{\vfil $O(h^2)$}
\erow

\makeatother
\end{calstable}
\end{table}
\end{document}

Be aware that many lines of code can be removed by defining simple switches that turn on and off colour, line, side bearing etc. Based on an example from the documentation, I have defined a macro that turns colour on and off:

\def\green{\ifx\cals@bgcolor\empty      % Colour switch (on-off)
\def\cals@bgcolor{green!15}
\else \def\cals@bgcolor{} \fi}

If you place \greenbefore and after the cell, you get a green cell. If you place it at the beginning and end of a row, you have a \rowcolourthat functions. The on-switch works on all cells in all rows until it is turned off. Be aware that you need to place the line

\def\cals@bgcolor{}

before you use the macro for the first time.

The macro can be adapted for turning on and of borders and lines (decoration):

\def\bb{\ifx\cals@borderB\relax     % Bottom border switch (on of)
\def\cals@borderB{0pt}
\else \let\cals@borderB\relax\fi}
• Thank you very much! @Sveinung Commented May 29, 2019 at 3:04