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.
– Adriaan Nov 18 '13 at 15:03The
\newcommand{\plotoptsa}{color=\linecolora,mark=\marka}can now be removed.The point was to have the width variable, so I'd define
axisA/.style={xlabel={\xlabela},width=\figurewidth}. So removewidth=100and add,width=\figurewidth}.\newcommand{#1}{#2}does not work because the comma's are misinterpreted. And\legend{#1}does not except styles. – Adriaan Nov 18 '13 at 16:17\newcommand{#1}{#2}supposed to work? – Johannes_B Nov 18 '13 at 19:07\legend{\legendA}in an axis environment with, say, two graphs. I specify\legendAby means of\newcommand{\legendA}{graph A,graph B}. But then I get just one legend entrygraph A,graph Binstead of the two legend entriesgraph Aandgraph B. So the comma is not interpreted properly and I do not know how to solve this. I found several other questions here at tex.stackexchange.com on for instance comma-separated-list but I can't seem to solve my problem. – Adriaan Nov 18 '13 at 22:50I rather advice you to define a macro for every entry. Something like
– Johannes_B Nov 19 '13 at 08:41