0

You can use \tikzsytle{mystyle}=[some options]; to define a custom mystyle globally, that means it affects all tikz graphics in the document, but is there also something similar if you want to define a custom mystyle just within one tikzpicture?

  • You should use \tikzset (mystyle/.style={}) nowadays. That will also work locally. – TeXnician Dec 31 '17 at 15:57
  • @TeXnician I didn't know about tikzset, is this the preferred way now? – flawr Dec 31 '17 at 16:00
1

Use \tikzset instead of the \tikzstyle approach. This will allow local key-value settings.

\documentclass{article}
\usepackage{tikz}
\tikzset{mystyle/.style={fill=blue}}

\begin{document}
    \begin{tikzpicture}
        \node[mystyle] {Test};
    \end{tikzpicture}
    \begingroup
    \tikzset{mystyle/.style={fill=yellow}}
    \begin{tikzpicture}
        \node[mystyle] {Test};
    \end{tikzpicture}
    \endgroup
    \begin{tikzpicture}
        \node[mystyle] {Test};
    \end{tikzpicture}
\end{document}
|improve this answer|||||
5

Instead of groups and \tikzset, add the style definition to the optional argument of the tikzpicture environment.

\documentclass{article}
\usepackage{tikz}
\tikzset{mystyle/.style={fill=blue}}

\begin{document}
    \begin{tikzpicture}
        \node[mystyle] {Test};
    \end{tikzpicture}

    \begin{tikzpicture}[mystyle/.style={fill=yellow}]
        \node[mystyle] {Test};
    \end{tikzpicture}

    \begin{tikzpicture}
        \node[mystyle] {Test};
    \end{tikzpicture}
\end{document}
|improve this answer|||||

Not the answer you're looking for? Browse other questions tagged or ask your own question.