我正在写一篇包含大量图表的论文。为了便于管理,我想使用 LaTeX 宏来设置线条样式,以便于维护。但是,每当我尝试这样做时,都会出现以下情况:
\documentclass{report}
\usepackage{tikz}
\usepackage{pgfplots}
\newcommand{\linestyleA}[0]{color=black!100,mark=star}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel=Cost,
ylabel=Error]
\addplot[\linestyleA{}] coordinates {
(2,-2.8559703)
(3,-3.5301677)
(4,-4.3050655)
(5,-5.1413136)
(6,-6.0322865)
(7,-6.9675052)
(8,-7.9377747)
};
\end{axis}
\end{tikzpicture}
\end{document}
当我执行此操作时,在第 22 行出现错误:
! Package xcolor Error: Undefined color `color=black'. See the xcolor package documentation for explanation.
我确信有一个简单的解决方法,但我无论如何也想不到。提前谢谢!
答案1
您可以用以下style
方式定义\tikzset
:
\documentclass{report}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\tikzset{linestyleA/.style={color=black!100,mark=star}}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel=Cost,
ylabel=Error]
\addplot[linestyleA] coordinates {
(2,-2.8559703)
(3,-3.5301677)
(4,-4.3050655)
(5,-5.1413136)
(6,-6.0322865)
(7,-6.9675052)
(8,-7.9377747)
};
\end{axis}
\end{tikzpicture}
\end{document}