2

I have a problem with one of my tables when I use the multicolumn command. I tried a lot of solutions on this webpage related to \noalign. But, different from those, I don't use \hline in my tables. Instead, I use cmidrule. I'm not able to zero in on the error exactly. The table appears to be pretty cool but I always get an error about misplaced \noalign <recently read> \noalign \end{tabular}}.

I'll post a bite of my code that can re-produce the table I'm having trouble with. I tried not to ask this question and fix it myself but I've spent over an hour and still not able to zero in on the error. I hope you can help me out in figuring this issue.

\begin{landscape}
\begin{table}[htp]
    \begin{center}
          \scalebox{0.72}{
        \begin{tabular}{@{} cccccccccccccccccccccccccc @{}}
        \toprule
                        {\textbf{Robustness Level}} & \multicolumn{7}{c}{\textbf{Objective ($\small{\textsc{x}}10^{2}$)}} & \phantom{abc} & \multicolumn{7}{c}{\textbf{Gap (\%)}} & \phantom{abc} & \multicolumn{7}{c}{\textbf{PoPr (\%)}}\\
                        \cmidrule{2-8} \cmidrule{10-16} \cmidrule{18-24}
            {\textit{$|S|$}} & $9$ & $18$ & $27$ & $36$ & $45$ & $54$ & $63$ && $9$ & $18$ & $27$ & $36$ & $45$ & $54$ & $63$ && $9$ & $18$ & $27$ & $36$ & $45$ & $54$ & $63$\\
                        \midrule
                        \multirow{2}{*}{$\Gamma = 0$} & $5.8$ & $11.5$ & $86.8$ & $162.7$ & $513.6$ & $727.6$ & $1010.3$ && $0$ & $1$ & $0$ & $1$ & $8$ & $11$ & $5$ && $41$ & $90$ & $12$ & $0$ & $4$ & $8$ & $2$\\
            &\rowcolor{black!15} $5.7$ & $31$ & $295.8$ & $510.4$ & $624.9$ & $1007.4$ & $1171.5$ && $0$ & $0$ & $0$ & $0$ & $1$ & $3$ & $1$ && $100$ & $13$ & $17$ & $3$ & $2$ & $1$ & $0$\\ 
                                   \bottomrule
        \end{tabular}}
    \end{center}
    \caption{Test runs without delay restrictions.}
\end{table}
\end{landscape}

Here is the table that was produced by the code: enter image description here

Thanks

crypto
  • 757

1 Answers1

3

It is a bit tricky as you want to start the grey row in the second column. I just made the cell white afterwards. I hope, the code is self explanatory.

% arara: pdflatex

\documentclass{article}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{lscape}
\usepackage{multirow}
\usepackage[table]{xcolor}

\begin{document}
\begin{landscape}
\begin{table}[htp]
    \centering
    \scalebox{0.72}{%
        \begin{tabular}{*{24}{c}}
            \toprule
            \textbf{Robustness Level} & \multicolumn{7}{c}{\textbf{Objective ($\small{\textsc{x}}10^{2}$)}} & \phantom{abc} & \multicolumn{7}{c}{\textbf{Gap (\%)}} & \phantom{abc} & \multicolumn{7}{c}{\textbf{PoPr (\%)}}\\
            \cmidrule{2-8} \cmidrule{10-16} \cmidrule{18-24}
            $|S|$ & $9$ & $18$ & $27$ & $36$ & $45$ & $54$ & $63$ && $9$ & $18$ & $27$ & $36$ & $45$ & $54$ & $63$ && $9$ & $18$ & $27$ & $36$ & $45$ & $54$ & $63$\\
            \midrule
             & $5.8$ & $11.5$ & $86.8$ & $162.7$ & $513.6$ & $727.6$ & $1010.3$ && $0$ & $1$ & $0$ & $1$ & $8$ & $11$ & $5$ && $41$ & $90$ & $12$ & $0$ & $4$ & $8$ & $2$\\
            \rowcolor{black!15}\cellcolor{white} \multirow{-2}{*}{$\Gamma = 0$}& $5.7$ & $31$ & $295.8$ & $510.4$ & $624.9$ & $1007.4$ & $1171.5$ && $0$ & $0$ & $0$ & $0$ & $1$ & $3$ & $1$ && $100$ & $13$ & $17$ & $3$ & $2$ & $1$ & $0$ \\ 
            \bottomrule
        \end{tabular}
        }
    \caption{Test runs without delay restrictions.}
\end{table}
\end{landscape}
\end{document}

Some remarks: You should not use the center environment here. You had too many c specifiers (26 instead of 24) and please try not to scale the table. This looks ugly. Maybe you can reformat somehow. Please take a look on the S column of the package siunitx which would be very nice here.


Just some ideas:

% arara: pdflatex

\documentclass{article}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{lscape}
\usepackage{multirow}
\usepackage[table]{xcolor}
\usepackage{siunitx}
\sisetup{detect-weight=true}
\usepackage{bm}

\begin{document}
\begin{landscape}
\begin{table}[htp]
    \centering
    \small
        \begin{tabular}{%
                @{}l
                S[table-format=1.1]
                S[table-format=2.1]
                *{3}{S[table-format=3.1]}
                *{2}{S[table-format=4.1]}
                S[table-format=1.0]
                *{6}{S[table-format=2.0]}
                S[table-format=3.0]
                *{6}{S[table-format=2.0]}
                }
            \toprule
            \textbf{Robustness} & \multicolumn{7}{c}{\textbf{Objective ($\bm{\times 10^{2}}$)}} & \multicolumn{7}{c}{\textbf{Gap (\si{\percent})}} & \multicolumn{7}{c}{\textbf{PoPr (\si{\percent})}}\\
            \cmidrule(r){2-8} \cmidrule(lr){9-15} \cmidrule(l){16-22}
            $|S|$ & 9 & 18 & 27 & 3 & 45 & 54 & 63 & 9 & 18 & 27 & 36 & 45 & 54 &63 & 9 & 18 & 27 & 36 & 45 & 54 & 63\\
            \midrule
             & 5.8 & 11.5 & 86.8 & 162.7 & 513.6 & 727.6 & 1010.3 & 0 & 1 & 0 & 1 & 8 & 11 & 5 & 41 & 90 & 12 & 0 & 4 & 8 & 2\\
            \rowcolor{black!15}\cellcolor{white} \multirow{-2}{*}{$\Gamma = 0$}& 5.7 & 31 & 295.8 & 510.4 & 624.9 & 1007.4 & 1171.5 & 0 & 0 & 0 & 0 & 1 & 3 & 1 & 100 & 13 & 17 & 3 & 2 & 1 & 0 \\ 
            \bottomrule
        \end{tabular}
    \caption{Test runs without delay restrictions.}
\end{table}
\end{landscape}
\end{document}
LaRiFaRi
  • 43,807
  • Oh dude, that was so fast! I'm grateful to you. It just solved the problem I've been stuck with since an hour or so. Many thanks dude – crypto Apr 29 '16 at 08:28
  • @crypto You are very welcome. Glad I could give a hand. – LaRiFaRi Apr 29 '16 at 08:29
  • 1
    @crypto Please also see my update! There is just missing something like http://tex.stackexchange.com/q/177202 in order to get rid of the white line at the end. – LaRiFaRi Apr 29 '16 at 08:47
  • Thanks a lot for the update @LaRiFaRi. I will definitely use your improved code. – crypto Apr 29 '16 at 08:49