6

I have a table and need to merge two cells in one.

enter image description here My code is below:

\begin{document}
\begin{table}[]
\centering \caption {caption}
\label{tab:boot-var}
\begin{tabular}{|c|r|r|r|r|r|r|r|r|r|r|r|r|} \hline
%
\multirow{2}{*}{$\alpha$} &
\multicolumn{3}{c|}{$\overline{\emph{VaR}}_\alpha \times 10^{-2}$}
& \multicolumn{3}{c|}{$\Delta \times 10^{-3}$} &
\multicolumn{3}{c|}{$SD \times 10^{-2}$} &
\multicolumn{3}{c|}{$RMSE \times 10^{-2}$} \\ \cline{2-13}
 & \multicolumn{1}{c|}{$C_G$} & \multicolumn{1}{c|}{$C_t$} & \multicolumn{1}{c|}{$C_R$} & \multicolumn{1}{c|}{$C_G$} & \multicolumn{1}{c|}{$C_t$} & \multicolumn{1}{c|}{$C_R$} & \multicolumn{1}{c|}{$C_G$} & \multicolumn{1}{c|}{$C_t$} & \multicolumn{1}{c|}{$C_R$} & \multicolumn{1}{c|}{$C_G$} & \multicolumn{1}{c|}{$C_t$} & \multicolumn{1}{c|}{$C_R$} \\ \hline
90,0 & 1,61 & 1,62 & 1,61 & 2,99 &  3,03 &  2,96 & 0,80 & 0,79 & 0,85 & 3,10 & 3,13 & 3,08 \\
95,0 & 2,19 & 2,20 & 2,18 & 5,00 &  5,06 &  4,93 & 1,18 & 1,37 & 1,48 & 5,14 & 5,24 & 5,14 \\
99,0 & 3,46 & 3,50 & 3,46 & 8,71 &  9,11 &  8,78 & 1,79 & 2,32 & 2,47 & 8,89 & 9,40 & 9,11 \\
99,5 & 4,04 & 4,21 & 4,09 & 4,15 &  5,82 &  4,64 & 4,22 & 6,10 & 5,69 & 5,91 & 8,42 & 7,33 \\
99,9 & 5,62 & 5,53 & 5,49 & 0,05 & -0,86 & -1,21 & 3,81 & 5,18 & 5,16 & 3,81 & 5,24 & 5,29 \\ \hline
\end{tabular}
\end{table}
\end{document}

Question. How to merge cells in the table correctlly?

My problem is \multirow{2}{*}{$\alpha$}

2
  • \multirow is not defined by default, it is impossible to tell if you have defined it as you have not shown a usable test file starting \documentclass. Do you get an error from tex? Feb 15 '18 at 8:36
  • 1
    I don't think this is related, but you're asking how to merge four cells. I'm only counting two that you've circled.
    – Teepeemm
    Feb 15 '18 at 18:35
17

While your problem could be solved by loading multirow (you got an error message, didn't you?), there are also some smaller issues which are fixed in the following code: \emph in math mode is wrong and \mathit should be used.

I didn't fix the minus signs (you should) because I also present a better way to lay out the table that doesn't suffer from the problem.

\documentclass{article}
\usepackage{geometry}
\usepackage{multirow} % for your style
\usepackage{booktabs,siunitx} % for the better one

\sisetup{output-decimal-marker={,}}

\begin{document}

\begin{table}[htp]
\centering
\caption{Caption for the jailed table}
\label{tab:boot-var}
\begin{tabular}{|c|r|r|r|r|r|r|r|r|r|r|r|r|} \hline
%
\multirow{2}{*}{$\alpha$} &
\multicolumn{3}{c|}{$\overline{\mathit{Va}R}_\alpha \times 10^{-2}$}&
  \multicolumn{3}{c|}{$\Delta \times 10^{-3}$} &
  \multicolumn{3}{c|}{$\mathit{SD} \times 10^{-2}$} &
  \multicolumn{3}{c|}{$\mathit{RMSE} \times 10^{-2}$} \\
\cline{2-13}
&
  \multicolumn{1}{c|}{$C_G$} &
  \multicolumn{1}{c|}{$C_t$} &
  \multicolumn{1}{c|}{$C_R$} &
  \multicolumn{1}{c|}{$C_G$} &
  \multicolumn{1}{c|}{$C_t$} &
  \multicolumn{1}{c|}{$C_R$} &
  \multicolumn{1}{c|}{$C_G$} &
  \multicolumn{1}{c|}{$C_t$} &
  \multicolumn{1}{c|}{$C_R$} &
  \multicolumn{1}{c|}{$C_G$} &
  \multicolumn{1}{c|}{$C_t$} &
  \multicolumn{1}{c|}{$C_R$} \\
\hline
90,0 & 1,61 & 1,62 & 1,61 & 2,99 &  3,03 &  2,96 & 0,80 & 0,79 & 0,85 & 3,10 & 3,13 & 3,08 \\
95,0 & 2,19 & 2,20 & 2,18 & 5,00 &  5,06 &  4,93 & 1,18 & 1,37 & 1,48 & 5,14 & 5,24 & 5,14 \\
99,0 & 3,46 & 3,50 & 3,46 & 8,71 &  9,11 &  8,78 & 1,79 & 2,32 & 2,47 & 8,89 & 9,40 & 9,11 \\
99,5 & 4,04 & 4,21 & 4,09 & 4,15 &  5,82 &  4,64 & 4,22 & 6,10 & 5,69 & 5,91 & 8,42 & 7,33 \\
99,9 & 5,62 & 5,53 & 5,49 & 0,05 & -0,86 & -1,21 & 3,81 & 5,18 & 5,16 & 3,81 & 5,24 & 5,29 \\ \hline
\end{tabular}
\end{table}

\begin{table}[htp]
\centering
\caption{Caption for the nice table}
\label{tab:boot-var+}
\begin{tabular}{
 @{}
 S[table-format=2.1]
 *{4}{S[table-format=1.2]}
 *{2}{S[table-format=-1.2]}
 *{6}{S[table-format=1.2]}
 @{}
}
\toprule
{$\alpha$} &
  \multicolumn{3}{c}{$\overline{\mathit{Va}R}_\alpha \times 10^{-2}$} &
  \multicolumn{3}{c}{$\Delta \times 10^{-3}$} &
  \multicolumn{3}{c}{$\mathit{SD} \times 10^{-2}$} &
  \multicolumn{3}{c}{$\mathit{RMSE} \times 10^{-2}$} \\
\cmidrule(lr){2-4} \cmidrule(lr){5-7} \cmidrule(lr){8-10} \cmidrule(l){11-13}
&
  {$C_G$} & {$C_t$} & {$C_R$} &
  {$C_G$} & {$C_t$} & {$C_R$} &
  {$C_G$} & {$C_t$} & {$C_R$} &
  {$C_G$} & {$C_t$} & {$C_R$} \\
\midrule
90,0 & 1,61 & 1,62 & 1,61 & 2,99 &  3,03 &  2,96 & 0,80 & 0,79 & 0,85 & 3,10 & 3,13 & 3,08 \\
95,0 & 2,19 & 2,20 & 2,18 & 5,00 &  5,06 &  4,93 & 1,18 & 1,37 & 1,48 & 5,14 & 5,24 & 5,14 \\
99,0 & 3,46 & 3,50 & 3,46 & 8,71 &  9,11 &  8,78 & 1,79 & 2,32 & 2,47 & 8,89 & 9,40 & 9,11 \\
99,5 & 4,04 & 4,21 & 4,09 & 4,15 &  5,82 &  4,64 & 4,22 & 6,10 & 5,69 & 5,91 & 8,42 & 7,33 \\
99,9 & 5,62 & 5,53 & 5,49 & 0,05 & -0,86 & -1,21 & 3,81 & 5,18 & 5,16 & 3,81 & 5,24 & 5,29 \\
\bottomrule
\end{tabular}
\end{table}

\end{document}

enter image description here

As you see, the input is much easier and the table has a more professional look.

enter image description here

Don't jail table cells, says the duck.

7

You should add \usepackage{multirow}in the preamble. If it's there, the document is compiled without an error.

\documentclass{article}
\usepackage{multirow}

\begin{document}
\begin{table}[]
\centering \caption {caption}
\label{tab:boot-var}
\begin{tabular}{|c|r|r|r|r|r|r|r|r|r|r|r|r|} \hline
%
\multirow{2}{*}{$\alpha$} &
\multicolumn{3}{c|}{$\overline{\emph{VaR}}_\alpha \times 10^{-2}$}
& \multicolumn{3}{c|}{$\Delta \times 10^{-3}$} &
\multicolumn{3}{c|}{$SD \times 10^{-2}$} &
\multicolumn{3}{c|}{$RMSE \times 10^{-2}$} \\ \cline{2-13}
 & \multicolumn{1}{c|}{$C_G$} & \multicolumn{1}{c|}{$C_t$} & \multicolumn{1}{c|}{$C_R$} & \multicolumn{1}{c|}{$C_G$} & \multicolumn{1}{c|}{$C_t$} & \multicolumn{1}{c|}{$C_R$} & \multicolumn{1}{c|}{$C_G$} & \multicolumn{1}{c|}{$C_t$} & \multicolumn{1}{c|}{$C_R$} & \multicolumn{1}{c|}{$C_G$} & \multicolumn{1}{c|}{$C_t$} & \multicolumn{1}{c|}{$C_R$} \\ \hline
90,0 & 1,61 & 1,62 & 1,61 & 2,99 &  3,03 &  2,96 & 0,80 & 0,79 & 0,85 & 3,10 & 3,13 & 3,08 \\
95,0 & 2,19 & 2,20 & 2,18 & 5,00 &  5,06 &  4,93 & 1,18 & 1,37 & 1,48 & 5,14 & 5,24 & 5,14 \\
99,0 & 3,46 & 3,50 & 3,46 & 8,71 &  9,11 &  8,78 & 1,79 & 2,32 & 2,47 & 8,89 & 9,40 & 9,11 \\
99,5 & 4,04 & 4,21 & 4,09 & 4,15 &  5,82 &  4,64 & 4,22 & 6,10 & 5,69 & 5,91 & 8,42 & 7,33 \\
99,9 & 5,62 & 5,53 & 5,49 & 0,05 & -0,86 & -1,21 & 3,81 & 5,18 & 5,16 & 3,81 & 5,24 & 5,29 \\ \hline
\end{tabular}
\end{table}
\end{document}
4

Here's another solution that deliberately uses no vertical lines whatsoever and few, but well-spaced, horizontal lines. Compared to @egreg's "nice" table solution, the code shown below (a) uses an array environment instead of a tabular environment, requiring the typing of only 2 $ symbols for the entire table (one before \begin{array}, the other after \end{array}), and (b) assigns all 12 data columns the same width in order to present a more "even-looking" output.

enter image description here

\documentclass{article}
% Choose suitable page parameters:
\usepackage[letterpaper,margin=1in]{geometry} 
\usepackage{booktabs,siunitx}
\usepackage[skip=0.333\baselineskip]{caption}
\begin{document}

\begin{table}[ht!]
\sisetup{table-format=-1.2, output-decimal-marker={,}}
\centering
\caption{Choose a suitable caption} \label{tab:boot-var+}
$\begin{array}{@{} c *{12}{S} @{}}
\toprule
\alpha & \multicolumn{3}{c}{\overline{\mathit{VaR}}_\alpha \times 10^{-2}} &
         \multicolumn{3}{c}{\Delta\times 10^{-3}} &
         \multicolumn{3}{c}{\mathit{SD}\times 10^{-2}} &
         \multicolumn{3}{c@{}}{\mathit{RMSE}\times 10^{-2}} \\
\cmidrule(lr){2-4} \cmidrule(lr){5-7} \cmidrule(lr){8-10} \cmidrule(l){11-13}
& {~~C_G} & {~~C_t} & {~~C_R} & {~~C_G} & {~~C_t} & {~~C_R} &
  {~~C_G} & {~~C_t} & {~~C_R} & {~~C_G} & {~~C_t} & {~~C_R} \\
\midrule
90,0 & 1,61 & 1,62 & 1,61 & 2,99 & 3,03 & 2,96 & 0,80 & 0,79 & 0,85 & 3,10 & 3,13 & 3,08 \\
95,0 & 2,19 & 2,20 & 2,18 & 5,00 & 5,06 & 4,93 & 1,18 & 1,37 & 1,48 & 5,14 & 5,24 & 5,14 \\
99,0 & 3,46 & 3,50 & 3,46 & 8,71 & 9,11 & 8,78 & 1,79 & 2,32 & 2,47 & 8,89 & 9,40 & 9,11 \\
99,5 & 4,04 & 4,21 & 4,09 & 4,15 & 5,82 & 4,64 & 4,22 & 6,10 & 5,69 & 5,91 & 8,42 & 7,33 \\
99,9 & 5,62 & 5,53 & 5,49 & 0,05 &-0,86 &-1,21 & 3,81 & 5,18 & 5,16 & 3,81 & 5,24 & 5,29 \\
\bottomrule
\end{array}$
\end{table}
\end{document}

This site is temporarily in read only mode and not accepting new answers.

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