0

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 
  • 1
    Could you provide the community with a minimal working example (MWE) that replicates your problem? For example, where is \diag from? You need to start this MWE with \documentclass and it should end with \end{document}. We want to copy-and-paste-and-compile and see exactly the problem you're experiencing. That's not the case as of now... – Werner Jan 20 '15 at 1:37
  • In particular, please be indicate which packages define the macros \subfloat and \diag. – Mico Jan 20 '15 at 6:16
  • All packeges that i added on the file: – Cagri Jan 20 '15 at 11:27
  • Could you draw a little picture of the desired result? This code is a big mix of different packages. Thank you! – LaRiFaRi Jan 20 '15 at 11:59
  • Table is presented as I want. Nothing is wrong. However, compiler gives an error (\omit), which makes so annoying – Cagri Jan 20 '15 at 12:27
1

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

  • Thanks so much. It works fine, and produces a good table. – Cagri Jan 20 '15 at 13:01
  • @Cagri Glad to hear that. You are welcome. – LaRiFaRi Jan 20 '15 at 13:02
  • I really like the first example that you ploted. However, I would like to add \subfloat , and present them side-by-side. Could you help me about it? – Cagri Jan 20 '15 at 13:29
  • @Cagri Just remove the blank line between the two subfloats (or replace it by \hfil or any other horizontal distance). Depending on your page settings, you will have to reduce font size or column separation or something else. – LaRiFaRi Jan 20 '15 at 13:59

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.