2

I want to create an array of custom defined styles and afterwards use these styles by getting them by index.

My approach so far, which isn't working:

  1. Defining some styles:

    \pgfplotsset{
        redline/.style={
            red
        },
        blueline/.style={
            blue
        }
    }
    
  2. Defining an array with the styles:

    \def\mystylesarray{
        {redline},
        {blueline}
    }
    
  3. Using them in a plot:

    \begin{tikzpicture}
        \begin{axis}
            \addplot[\mystylesarray[0]] {x};
            \addplot[\mystylesarray[1]] {x^2};
        \end{axis}
    \end{tikzpicture}
    

I also tried the following:

In step 2. I tried \newcommand instead of \def and using two braces around the array implementation. In step 3. I tried curly braces and normal braces. All sorts of combinations and looking for an answer online didn't bring up a solution.

Your help is appreciated.


MWE:

\documentclass{scrreprt}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\pgfplotsset{
    redline/.style={
        red
    },
    blueline/.style={
        blue
    }
}
\def\mystylesarray{
    {redline},
    {blueline}
}

\begin{document}
    \begin{tikzpicture}
    \begin{axis}
    \addplot[\mystylesarray{0}] {x};
    \addplot[\mystylesarray{1}] {x^2};
    \end{axis}
    \end{tikzpicture}
\end{document}
13
  • 4
    I think you want pgfplotscreatecyclelist
    – cmhughes
    Sep 26, 2017 at 14:52
  • Please provide a complete minimal example if @cmhughes's comment does not answer your question.
    – cfr
    Sep 26, 2017 at 14:57
  • I forgot to say: Welcome to the site :) I'll post a complete example later on demonstrating the pgfplotscreatecyclelist; of course, if you're able to construct one yourself that meets your needs, it's perfectly ok to post an answer to your own question!
    – cmhughes
    Sep 26, 2017 at 15:10
  • @cmhughes Thanks for the warm welcome. No I don't want a cycle list. I need a collection of styles I can use throughout my pictures and plots. @cfr Isn't the example I posted enough? A complete example would only include usepackage command and a documentclass...
    – daniatic
    Sep 26, 2017 at 15:22
  • 4
    I'm voting to close this question because it was solved in the comments. Sep 26, 2017 at 17:20

0

Browse other questions tagged .