Because I often use the same options for multiple axes in my LaTeX documents, I use the following code to simplify my life.
\documentclass{article}
\usepackage{pgfplots}
\newcommand{\linecolora}{blue}
\newcommand{\marka}{o}
\newcommand{\plotoptsa}{color=\linecolora,mark=\marka}
\newcommand{\xlabela}{Test test 123}
\newlength\figurewidth
\setlength{\figurewidth}{\columnwidth}
\newcommand{\axisoptsa}{width=100,xlabel=\xlabela}
\newcommand{\axisoptsb}{ymin=-8,ymax=-3}
\begin{document}
\begin{tikzpicture}
\begin{axis}[\axisoptsa,\axisoptsb]
\expandafter\addplot\expandafter[\plotoptsa] 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}
It works like a charm! However, if I change width=100
into the defined width=\figurewidth
, I get Missing \endcsname inserted.
error. Using
\expandafter\begin{axis}\expandafter[\axisoptsa,\axisoptsb]
does not help.