未定义子表

未定义子表

以下问题已解决。脚本已编辑。

我从这个论坛上找到了一个 subtable 模板,但是运行它时出错了。我该如何解决这个问题?

错误消息:

! LaTeX Error: Environment subtable undefined.
! Missing number, treated as zero.
! Illegal unit of measure (pt inserted).
! LaTeX Error: \begin{table} on input line 164 ended by \end{subtable}.

梅威瑟:

\documentclass{article}
\usepackage{subfig}
\usepackage{array, booktabs, caption}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{xcolor}
\usepackage{subcaption}
\usepackage{pgfplots}
\usepackage{tikz}
\definecolor{bblue}{HTML}{4F81BD}
\definecolor{rred}{HTML}{C0504D}
\definecolor{ggreen}{HTML}{9BBB59}
\definecolor{ppurple}{HTML}{9F4C7C}

\begin{document}
\begin{table}   
\centering
\begin{subtable}{.5\textwidth}
\centering
\begin{tikzpicture}
    \begin{axis}[
        width  = 1.3*\textwidth,
        height = 8cm,
        enlarge y limits={upper, value=0.4},
        ymin=0,
        major x tick style = transparent,
        ybar=2*\pgflinewidth,
        bar width=20pt,
        ymajorgrids = true,
        ylabel = {\%},
        symbolic x coords={A,B,C},
        xtick = data,
        nodes near coords,
        scaled y ticks = false,
        enlarge x limits=0.25,
        ymin=0,
        legend cell align=left,
        legend style={
                at={(1,1.05)},
                anchor=south east,
                column sep=1ex
        }
    ]
        \addplot[style={bblue,fill=bblue,mark=none]}]
            coordinates {(A, 100) (B,100) (C,100)};

        \addplot[style={rred,fill=rred,mark=none}]
             coordinates {(A, 106) (B,113) (C,177)};
        \legend{MADYMO,Vivo}
    \end{axis}
\end{tikzpicture}
\caption{Phase 1}
\end{subtable}
\begin{subtable}{.5\textwidth}
\centering 
\begin{tikzpicture}
    \begin{axis}[
        width  = 1.3*\textwidth,
        height = 8cm,
        enlarge y limits={upper, value=0.4},
        ymin=0,
        major x tick style = transparent,
        ybar=2*\pgflinewidth,
        bar width=20pt,
        ymajorgrids = true,
        ylabel = {\%},
        symbolic x coords={A,B,C},
        xtick = data,
        nodes near coords,
        scaled y ticks = false,
        enlarge x limits=0.25,
        ymin=0,
        legend cell align=left,
        legend style={
                at={(1,1.05)},
                anchor=south east,
                column sep=1ex
        }
    ]
        \addplot[style={ggreen,fill=ggreen,mark=none]}]
            coordinates {(A, 100) (B,100) (C,100)};

        \addplot[style={ppurple,fill=ppurple,mark=none}]
             coordinates {(A, 98) (B,113) (C,178)};
        \legend{X,Y}
    \end{axis}
\end{tikzpicture}
\caption{Phase 2}
\end{subtable}
\caption{aaaaaaa}
\label{tab:EmMaxPE_bar_X}
\end{table}
\end{document}

答案1

(备注:我发布了这个问题OP 对查询进行了几处实质性的修改。例如,subcaption查询的初始形式中未加载环境,并且没有关于环境重要方面的信息tikzpicture。)

要使用subtable环境,您需要加载subcaption包。subfig包会不是提供一个subtable环境。

在下面的例子中,我tikzpicture用 dummy 替换了两个环境tabular环境,以简化说明。(另外,您没有指出哪个应该加载与 tikz 相关的包或如何rred定义bblue等。)请注意,如果您希望它们并排放置,则应%在第一个环境之后立即插入一个(注释)字符。subtable

在此处输入图片描述

\documentclass{article}
\usepackage{subcaption,booktabs}
\begin{document}

\begin{table}   
%\centering  <--- not needed!
\begin{subtable}{.5\textwidth}
\centering
   % dummy 'tabular' env.
   \begin{tabular}{lll}
   \toprule
   aaa bbb ccc\\
   \bottomrule
   \end{tabular}
\caption{Phase 1}
\end{subtable}% <--- new
\begin{subtable}{.5\textwidth}
\centering 
   % dummy 'tabular' env.
   \begin{tabular}{lll}
   \toprule
   xxx yyy zzz\\
   \bottomrule
   \end{tabular}
\caption{Phase 2}
\end{subtable}
\caption{aaaaaaa} \label{tab:EmMaxPE_bar_X}
\end{table}
\end{document}

相关内容