The PGF/TikZ manual states in section 12.4 Using Graphic Options, page 120 (v2.10), that TikZ styles can be set using:

\tikzset{my style/.style={<tikz options>},...}

However, in several places in the same manual the otherwise undocumented macro \tikzstyle is used for settings styles:

\tikzstyle{my style}=[<tikz options>]

I also have seen this usage in several online code examples.

Why are there two ways to set TikZ styles and which one should be used for new code?

Note: I actually know the answer but think that such a question with good answers would be beneficial for other users.

  • 1
    I prefer \tikzset as it looks like the options that would be passed to a command
    – Someone
    Nov 27, 2020 at 16:43

2 Answers 2


Someone on pgf-users list writes to T Tantau :

I suggest keeping the old syntax, \tikzstyle{my style}=[some options,...] since it is much easier to read and understand. The new syntax would be for the more "advanced" users and library writers.

Answer of Till Tantau :

I'm a bit undecided on this.

First, for compatibility reasons \tikzstyle will be around indefinitely, so the real question is what will be better for new code.

The reason I'm trying to kick out the \tikzstyle is that I would like to encourage people to keep style settings as local as possible. So, normally, style definitions should be given at the beginning of a picture as in

[some options,
first style/.style={blah},
second style/.style={blub}]    ...

Then, if the tikzpicture is moved/copied/whatever, the styles are moved around with it. Furthermore, styles given as options always apply to the whole scope and end with it automatically.

However, I'm also not quite sure whether this argument is all that convincing. Global styles still have to be set globally using

 \tikzset anyway...

I have started to change the whole documentation code to the new system and it does not seem to change the readability much.

Now I think if you find some \tikzstyle in several places in the manual It's because it's not very important in these cases and perhaps the author forgot to correct the very big document.


  1. The full answer can be found online at http://osdir.com/ml/tex.pgf.user/2007-08/msg00004.html

  2. The answer continued:

    Anyway, you can now say things like

    \tikzstyle{my style}=[draw=#1,fill=#1!20]

    and I have actually extended the syntax of \tikzstyle so that one can also provide a default argument as in

    \tikzstyle{my style}[red]=[draw=#1,fill=#1!20]

    I never try this because I don't use \tikzstyle.

  3. For pgfplots, see page 8 of the pgfplots manual [revision 1.8]:

    Starting with pgfplots 1.1, \tikzstyle should no longer be used to set pgfplots options.

    Although \tikzstyle is still supported for some older pgfplotsoptions, you should replace any occurance of \tikzstyle with \pgfplotsset{style name/.style={key-value-list}} or the associated /.append style variant.

    Then, on page 280:

    Please note that it is not possible to use the TikZ-command \tikzstyle{stylename}=[]. This was possible in a previous version and is still supported for backwards compatibility. But in some cases, it may not work as expected.

  • 20
    This answer would benefit if you could add a short summary on the top. May 10, 2012 at 14:50
  • 1
    Yes you are right, I will make it when I have a little time (actually I write some programming notes about TikZ and it will be useful to add some notes about styles) May 10, 2012 at 15:44
  • 6
    @AlainMatthes: Are your programming notes about TikZ publicly available? If so where? Thanks. May 6, 2014 at 16:13
  • 2
    \tikzstyle{red_circle} = [draw, circle, fill=red!20] \tikzset{red_circle/.style = {draw, circle, fill=red!20}}
    – voices
    Jul 10, 2019 at 17:20
  • 3
    \tikzstyle is easier to read. Just saying.
    – voices
    Jul 10, 2019 at 17:21

TikZ and its underlying engine PGF have a powerful built-in module pgfkeys. It can also be used as a standalone package (via \usepackage{pgfkeys}) to manipulate options for other purposes.

No matter which command is used, therefore, every defined option goes to some instruction in the form of

\pgfkeys{/key family/key/.subkey = {value list} }

Since TikZ is the frontend of PGF engine, analogous to LaTeX and TeX, there is a default key family, tikz. For example, every tikzpicture when started already selects the tikz key family and internally the options are processed accordingly if not stated otherwise.

As we are mostly using TikZ commands, it is tedious to select the tikz key family every time we define a node option etc. so a shortcut serves well here which is the topic of this question. \tikzset command is defined as

% |\tikzset| is a shortcut to set keys that belongs to the tikz
% family.

Hence, \tikzset is a wrapper for Whatever is given next, belongs to the TikZ family.

Up to here, the key family part is handled and we can focus on key/.subkey part. There is not much that can be done without refering to the manual on this issue and the pgfkeys section is quite comprehensive. I will just emphasize that the most common two examples are mykey/.code and mykey/.style.

The subkey /.style is a collection or a catalogue of options to be processed whenever called for, such as "define the shape as circle and draw it then run some code and also put a label and fill it with yellow etc.". A style can also receive some parameters for example, the last example can be achieved by putting

\node[mystyle=label text] (nodename) {node text};

enter image description here

For more wizardry,say with more arguments etc. please refer to the manual. For the sake of convenience, here is another important subkey /.append style

\tikzset{mystyle/.append style={fill=red,rectangle}}
\node[mystyle=label text] (nodename) {node text};

which simply adds the arguments to the key. Note that, rectangle comes after circle and dominates the previous option, hence, the node becomes a red rectangle. The order of the style specifications matter.

Now, back to the question!! We have two options to give style specifications. Namely,

\tikzset{mystyle/.style= {draw,circle, etc.} }
\tikzset{mystyle/.append style= {rectangle,fill=red, etc.} }
% or ...

Both would lead to the same output however as we see that the \tikzstyle form is shorter to type in. Other than that, as far as I know there is no particular difference. For example, appending is simply done by putting a + sign next to = and also as shown below defining a default value is also quite convenient. However tikzstyle is only limited to this particular case and it's not applicable to other subkeys e.g. if you want to put a piece of code for some computation you can directly use

\tikzset{mystyle/.code={execute whatever is given here}}

but there is no \tikzcode similar to \tikzstyle to achieve this.

Hence, as Altermundus quoted, it's more of a shortcut.

For the interested, below is the code where these commands are defined. The relevant code is given in tikz.code.tex file at line 1143.

% Styles
\tikzoption{set style}{\tikzstyle#1}

% Handled in a special way.
\def\tikz@style@parseA#1#2=#3[#4]{% check for an optional argument

    \pgfkeys{/tikz/#1/.append style={#4}}%
    \pgfkeys{/tikz/#1/.append style={#3}}%

At the beginning of the same file there is a note which tells us directly the story about \tikzoption:

% Note: |\tikzoption| is supported for compatibility only. |\tikzset|
% should be used instead.
  • 2
    Very nice. Maybe add that you can set several keys within the same \tikzset command (\tikzset{my style/.style={...}, my second style/.style={...}, ...}), which is shorter than using \tikzstyle commands. And an added bonus of using \tikzstyle is that you can just cut and paste the same list of styles to the options of a tikzpicture or a scope, which I guess is what Till Tantau means by wanting to "encourage people to keep style settings as local as possible".
    – Jake
    Apr 18, 2012 at 10:44
  • @Jake Thanks. I agree with you but Altermundus pretty much covered these by quoting the man himself :) Feel free to edit anyway. Maybe we should make this CW.
    – percusse
    Apr 18, 2012 at 13:43
  • Pretty long, but the only answer mentioning += being an abbreviation for .append style and the fact that many more subkeys don’t have abbreviations in \tikzstyle. Sep 29, 2019 at 14:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .