尝试插入 tikz 图形时,使用以下代码:
\documentclass[]{memoir}
\usepackage{pgfplots}
\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,snakes,
automata,backgrounds,
petri,topaths}
\begin{document}
\begin{figure}[h]
\input{OilPrices.tikz}
\end{figure}
\end{document}
我收到以下错误:
./OilPrices.tikz:23: Undefined control sequence. []]
./OilPrices.tikz:23: Undefined control sequence. []]
./OilPrices.tikz:39: Undefined control sequence. [\end{axis}]
./OilPrices.tikz:39: Undefined control sequence. [\end{axis}]
./OilPrices.tikz:39: Missing number, treated as zero. [\end{axis}]
./OilPrices.tikz:39: Missing number, treated as zero. [\end{axis}]
tikz 的样子如下:
\definecolor{mycolor1}{rgb}{0.00000,0.44700,0.74100}%
\definecolor{mycolor2}{rgb}{0.85000,0.32500,0.09800}%
\begin{tikzpicture}
\begin{axis}[%
width=0.951\figurewidth,
height=\figureheight,
at={(0\figurewidth,0\figureheight)},
scale only axis,
xmin=731500,
xmax=736500,
xtick={731217,731582,731947,732313,732678,733043,733408,733774,734139,734504,734869,735235,735600,735965,736330,736696},
xticklabels={{2002},{2003},{2004},{2005},{2006},{2007},{2008},{2009},{2010},{2011},{2012},{2013},{2014},{2015},{2016},{2017}},
xlabel={Time (Years)},
ymin=20,
ymax=140,
ylabel={Price (\$/Barrel)},
axis background/.style={fill=white},
title style={font=\bfseries},
title={Comparison of WTI and Brent Oil Prices},
legend style={legend cell align=left,align=left,draw=white!15!black}
] %Line 23
\addplot [color=mycolor1,solid]
table[row sep=crcr]{%
731672 49.22\\
736451 23.68\\
};
\addlegendentry{Brent};
\addplot [color=mycolor2,solid]
table[row sep=crcr]{%
731672 47.64\\
736420.560509554 29.56\\
};
\addlegendentry{WTI};
\end{axis}
\end{tikzpicture} %Line 39
答案1
钛钾Z图片尝试访问未定义的\figurewidth
宏\figureheight
来配置图像宽度。
定义并设置长度(请随意更改长度)后,编译即可。
\documentclass[]{memoir}
\usepackage{pgfplots}
\usetikzlibrary{arrows,shapes,snakes,
automata,backgrounds,
petri,topaths}
\pgfplotsset{compat=newest}
\newlength{\figureheight}
\newlength{\figurewidth}
\setlength{\figureheight}{10cm}
\setlength{\figurewidth}{12cm}
\begin{document}
\begin{figure}[h]
\input{OilPrices.tikz}
\end{figure}
\end{document}
外部代码:
\definecolor{mycolor1}{rgb}{0.00000,0.44700,0.74100}%
\definecolor{mycolor2}{rgb}{0.85000,0.32500,0.09800}%
\begin{tikzpicture}
\begin{axis}[%
width=0.951\figurewidth,
height=\figureheight,
at={(0\figurewidth,0\figureheight)},
scale only axis,
xmin=731500,
xmax=736500,
xtick={731217,731582,731947,732313,732678,733043,733408,733774,734139,734504,734869,735235,735600,735965,736330,736696},
xticklabels={{2002},{2003},{2004},{2005},{2006},{2007},{2008},{2009},{2010},{2011},{2012},{2013},{2014},{2015},{2016},{2017}},
xlabel={Time (Years)},
ymin=20,
ymax=140,
ylabel={Price (\$/Barrel)},
axis background/.style={fill=white},
title style={font=\bfseries},
title={Comparison of WTI and Brent Oil Prices},
legend style={legend cell align=left,align=left,draw=white!15!black}
] %Line 23
\addplot [color=mycolor1,solid]
table[row sep=crcr]{%
731672 49.22\\
736451 23.68\\
};
\addlegendentry{Brent};
\addplot [color=mycolor2,solid]
table[row sep=crcr]{%
731672 47.64\\
736420.560509554 29.56\\
};
\addlegendentry{WTI};
\end{axis}
\end{tikzpicture}