我有 3 个垂直排列的子条形图。但由于空间限制,第三个没有完全显示。Mico 建议我使用图形和子图环境。我已将表子表更改为图形子图。现在问题出在 \textwidth 上。我已经给它提供了一个数字,但 TexMaker 仍然告诉我缺少数字,而且它是非法的计量单位。
错误消息:!缺少数字,视为零。} l.16 \begin{subfigure}{0.9\textwidth} 这里应该有一个数字;我
0'. (If you can't figure out why I needed to see a number, look up
在 The TeXbook 的索引中插入了奇怪的错误。)!非法计量单位(插入了 pt)。
我的脚本如下,为了缩短脚本,这里我只给出了一个条形图:
\documentclass{article}
\usepackage{subfigure}
\usepackage{amsmath,amssymb,amsfonts,amsthm}
\usepackage{xcolor}
\usepackage{caption}
\usepackage{pgfplots}
\usepackage{tikz}
\definecolor{bblue}{HTML}{4F81BD}
\definecolor{rred}{HTML}{C0504D}
\definecolor{ggreen}{HTML}{9BBB59}
\definecolor{ppurple}{HTML}{9F4C7C}
\begin{document}
\begin{figure}
\begin{subfigure}{1\textwidth}
\centering
\begin{tikzpicture}
\begin{axis}[
width = 1*\textwidth,
height = 8cm,
enlarge y limits={upper, value=0.2},
ymin=0,
major x tick style = transparent,
ybar=2*\pgflinewidth,
bar width=20pt,
ymajorgrids = true,
ylabel = {Percentage Error in X Direction \%},
symbolic x coords={FH,UT,LT},
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 {(FH, 100) (UT,100) (LT,100)};
\addplot[style={rred,fill=rred,mark=none}]
coordinates {(FH, 89) (UT,170) (LT,173)};
\legend{M,V}
\end{axis}
\end{tikzpicture}
\caption{In longitudinal Direction}
\end{subfigure}
\end{figure}
\end{document}
先感谢您!
答案1
不要加载该subfigure
包 - 它已被弃用。相反,加载该subcaption
包。它与您在之前查询中加载的包相同,该查询与subtable
环境有关。
由于条形图足够大,因此无法将这三个图全部放在一页上,因此我建议您使用宏\ContinuedFloat
(由包提供caption
)。将前两个subfigure
环境放在figure
一页上,将另一个环境subfigure
连同\ContinuedFloat
指令一起放在第二个figure
环境中。
\documentclass{article}
%%\usepackage{subfigure} % Don't load this package -- it's deprecated!
\usepackage{amsmath,amssymb,amsfonts,amsthm}
\usepackage{xcolor}
\usepackage{caption,subcaption} % <-- load the "subcaption" package instead
\usepackage{pgfplots}
\usepackage{tikz}
\definecolor{bblue}{HTML}{4F81BD}
\definecolor{rred}{HTML}{C0504D}
\definecolor{ggreen}{HTML}{9BBB59}
\definecolor{ppurple}{HTML}{9F4C7C}
\begin{document}
\begin{figure}[p] % start of the first "figure" environment
\caption{Three bar charts}
\begin{subfigure}{1\textwidth}
\centering
\begin{tikzpicture}
\begin{axis}[
width = 1*\textwidth,
height = 8cm,
enlarge y limits={upper, value=0.2},
ymin=0,
major x tick style = transparent,
ybar=2*\pgflinewidth,
bar width=20pt,
ymajorgrids = true,
ylabel = {Percentage Error in X Direction \%},
symbolic x coords={FH,UT,LT},
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 {(FH, 100) (UT,100) (LT,100)};
\addplot[style={rred,fill=rred,mark=none}]
coordinates {(FH, 89) (UT,170) (LT,173)};
\legend{M,V}
\end{axis}
\end{tikzpicture}
\caption{First}
\end{subfigure}
\begin{subfigure}{1\textwidth}
\centering
\begin{tikzpicture}
\begin{axis}[
width = 1*\textwidth,
height = 8cm,
enlarge y limits={upper, value=0.2},
ymin=0,
major x tick style = transparent,
ybar=2*\pgflinewidth,
bar width=20pt,
ymajorgrids = true,
ylabel = {Percentage Error in X Direction \%},
symbolic x coords={FH,UT,LT},
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 {(FH, 100) (UT,100) (LT,100)};
\addplot[style={rred,fill=rred,mark=none}]
coordinates {(FH, 89) (UT,170) (LT,173)};
\legend{M,V}
\end{axis}
\end{tikzpicture}
\caption{Second}
\end{subfigure}
\end{figure} % End of the first "figure" environment
\begin{figure}[t!] % Start of the second "figure" environment
\ContinuedFloat % to ensure that the next subfigure is labelled "(c)", not "(a)"
\begin{subfigure}{1\textwidth}
\centering
\begin{tikzpicture}
\begin{axis}[
width = 1*\textwidth,
height = 8cm,
enlarge y limits={upper, value=0.2},
ymin=0,
major x tick style = transparent,
ybar=2*\pgflinewidth,
bar width=20pt,
ymajorgrids = true,
ylabel = {Percentage Error in X Direction \%},
symbolic x coords={FH,UT,LT},
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 {(FH, 100) (UT,100) (LT,100)};
\addplot[style={rred,fill=rred,mark=none}]
coordinates {(FH, 89) (UT,170) (LT,173)};
\legend{M,V}
\end{axis}
\end{tikzpicture}
\caption{Third}
\end{subfigure}
\end{figure} % End of the second "figure" environment
\end{document}