
下面的問題已經解決了。劇本已編輯。
我從這個論壇找到了子表的模板,但我無法在沒有錯誤的情況下運行它。我該如何解決這個問題?
錯誤訊息:
! 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
環境替換為虛擬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}