我正在尝试用 LaTeX 编写表格;但是,以下代码不起作用:
\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}
错误输出为:
Misplaced \omit.
\multispan ->\omit
\@multispan
答案1
第一个单元格中使用了两个\multicolum
s。删除空的 s,并将对角线更改为:
\newcommand\diag[4]{%
\multicolumn{2}{p{#2}|}{\hskip-\tabcolsep % not the 2
...
然而,我认为该表看起来不正确,但正如您在评论中所说,它对您来说是正确的......
如果您想使用booktabs
,您应该坚持它的设计,而不是使用垂直线或您尝试使用的对角线。
下面,我重写了完整的表格,以使其更加美观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}