[Tex/LaTex] How to solve a “Misplaced \omit” error in a table

multicolumnsubfloatstables

I'm trying to code table in LaTeX; however, the following code isn't working:

\documentclass{article}
\usepackage{a4} 
\usepackage{subfig}

\usepackage{xfrac}
\usepackage[normalem]{ulem}
\usepackage{multirow}
\usepackage{array}
\usepackage{lmodern}
\usepackage{multicol}
\usepackage{caption}
%\usepackage{subcaption}
\usepackage{float}
\usepackage[usenames, dvipsnames]{color}

\usepackage{tikz}
\newcommand\diag[4]{%
    \multicolumn{1}{p{#2}|}{\hskip-\tabcolsep
        $\vcenter{\begin{tikzpicture}[baseline=0,anchor=south west,inner sep=#1]
            \path[use as bounding box] (0,0) rectangle (#2+2\tabcolsep,\baselineskip);
            \node[minimum width={#2+2\tabcolsep-\pgflinewidth},
            minimum  height=\baselineskip+\extrarowheight-\pgflinewidth] (box) {};
            \draw[line cap=round] (box.north west) -- (box.south east);
            \node[anchor=south west] at (box.south west) {#3};
            \node[anchor=north east] at (box.north east) {#4};
            \end{tikzpicture}}$\hskip-\tabcolsep}}


\usepackage{amsmath,graphicx}
\usepackage{amssymb}
\usepackage{csquotes}
\usepackage{booktabs}
%\usepackage{color}

%\usepackage{babel,blindtext}

\newcommand{\argmin}{\arg\!\min}


\newcommand{\ts}{\textsuperscript}
\captionsetup{compatibility=false}

\begin{document}
\begin{table}[]

    \caption{View} 
    \label{ch:a:3:4:2:1}
    \centering

    \subfloat[VR]{%
        \begin{tabular}{@{}ccccccc@{}}
            \hline
            \hline
            \multicolumn{2}{c}{} \diag{.1em}{4.5cm}{\textbf{Views}}{\textbf{QP}} & 20& 26& 32& 38& 44                    \\ \cmidrule(l){2-7} 
            \multirow{3}{*}{} & \multicolumn{1}{c|}{$V_{6}$} & \multicolumn{1}{c|}{88.8 $dB$} & \multicolumn{1}{c|}{88.8 $dB$} & \multicolumn{1}{c|}{88.2 $dB$} & \multicolumn{1}{c|}{88.8 $dB$} & \multicolumn{1}{c|}{88.8 $dB$} \\ \cmidrule(l){2-7} 
            & \multicolumn{1}{c|}{$V_{7}$} & \multicolumn{1}{c|}{88.9 $dB$} & \multicolumn{1}{c|}{88.8 $dB$} & \multicolumn{1}{c|}{88.5 $dB$} & \multicolumn{1}{c|}{88.8 $dB$} & \multicolumn{1}{c|}{88.8 $dB$} \\ \cmidrule(l){2-7} 
            & \multicolumn{1}{c|}{$V_{8}$} & \multicolumn{1}{c|}{88.7 $dB$} & \multicolumn{1}{c|}{88.8 $dB$} & \multicolumn{1}{c|}{88.1 $dB$} & \multicolumn{1}{c|}{88.8 $dB$} & \multicolumn{1}{c|}{88.8 $dB$} \\ \cmidrule(l){2-7} 

        \end{tabular}
    }


    \subfloat[VS]{%
        \begin{tabular}{@{}ccccccc@{}}
            \hline
            \hline

            \multicolumn{2}{c}{} \diag{.1em}{4.5cm}{\textbf{Views}}{\textbf{QP}} & 20& 26& 32& 38& 44                      \\ \cmidrule(l){2-7} 
            \multirow{3}{*}{} & \multicolumn{1}{c|}{$V_{6}$} & \multicolumn{1}{c|}{37.1 $dB$} & \multicolumn{1}{c|}{55.6 $dB$} & \multicolumn{1}{c|}{55.5 $dB$} & \multicolumn{1}{c|}{33.6 $dB$} & \multicolumn{1}{c|}{31.3 $dB$} \\ \cmidrule(l){2-7} 
            & \multicolumn{1}{c|}{$V_{7}$} & \multicolumn{1}{c|}{36.4 $dB$} & \multicolumn{1}{c|}{55.1 $dB$} & \multicolumn{1}{c|}{55.2 $dB$} & \multicolumn{1}{c|}{33.5 $dB$} & \multicolumn{1}{c|}{31.3 $dB$} \\ \cmidrule(l){2-7} 
            & \multicolumn{1}{c|}{$V_{8}$} & \multicolumn{1}{c|}{36.9 $dB$} & \multicolumn{1}{c|}{55.4 $dB$} & \multicolumn{1}{c|}{55.1 $dB$} & \multicolumn{1}{c|}{33.1 $dB$} & \multicolumn{1}{c|}{30.8 $dB$} \\ \cmidrule(l){2-7}


        \end{tabular}
    }

\end{table}
\end{document}

and the error output is:

Misplaced \omit.

\multispan ->\omit 
                   \@multispan 

Best Answer

You are using two \multicolums in your first cell. Remove the empty one and change your diagonal line to:

\newcommand\diag[4]{%
    \multicolumn{2}{p{#2}|}{\hskip-\tabcolsep % not the 2
    ...

The table however looks not correct to me, but as you said in comment, it is right for you...


If you want to use booktabs, you should stick to its design and not use vertical lines or this diagonal line you try to use.

In the following, I rewrote the complete table, in order to get it nice with booktabs.

% arara: pdflatex

\documentclass[a4paper]{article} % replacing the old package a4
\usepackage{lmodern}
\usepackage{caption}
\usepackage{subfig}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{siunitx}

\begin{document}
    \begin{table}   
        \caption{View}\label{ch:a:3:4:2:1}
        \centering
        \subfloat[][VR]{
        \begin{tabular}{c*{5}{S[table-format=2.1]}}
            \toprule
            \multirow{2}{*}{\textbf{Views}} & \multicolumn{5}{c}{\textbf{QP}} \\ \cmidrule(l){2-6}
            & {$20$} & {$26$} & {$32$} & {$38$} & {$44$} \\ \midrule
            $V_{6}/\si{\decibel}$ & 88.8 & 88.8 & 88.2 & 88.8 & 88.8 \\ 
            $V_{7}/\si{\decibel}$ & 88.9 & 88.8 & 88.5 & 88.8 & 88.8 \\ 
            $V_{8}/\si{\decibel}$ & 88.7 & 88.8 & 88.1 & 88.8 & 88.8 \\ \bottomrule             
        \end{tabular}}

        \subfloat[][VS]{
        \begin{tabular}{c*{5}{S[table-format=2.1]}}
            \toprule
            \multirow{2}{*}{\textbf{Views}} & \multicolumn{5}{c}{\textbf{QP}} \\ \cmidrule(l){2-6}
            & {$20$} & {$26$} & {$32$} & {$38$} & {$44$} \\ \midrule
            $V_{6}/\si{\decibel}$ & 37.1 & 55.6 & 55.5 & 33.6 & 33.3 \\ 
            $V_{7}/\si{\decibel}$ & 36.4 & 55.1 & 55.2 & 33.5 & 31.3 \\ 
            $V_{8}/\si{\decibel}$ & 36.9 & 55.4 & 55.1 & 33.1 &30.8 \\ \bottomrule          
        \end{tabular}}   
    \end{table}
\end{document}

enter image description here

Related Question