I'm trying to make a lot of different variations of PGFplots label styles so I'm trying to define different values and use \ticknum to pick one of them for example



every x tick label/.style={
    rotate=45,anchor=north east, text opacity=\x\ticknum,

But this gives me this error every time

! Undefined control sequence.\tikz@textopacity ->\x\ticknum \end{axis}

If this succeeds I also want to define different variables to change rotate value for every x tick differently for example. How can I make this to work?

EDIT : This is what works like a charm with colors but I'm trying to make something like this to work with numeric values as well.



every extra x tick/.style={
    tick label style={draw=col\ticknum},

This is a complete code



    ybar stacked,
    /pgf/bar width=0.952381cm,           
    legend style={at={(0.5,0.98)},
      anchor=north,legend columns=-1,font=\Large},
    symbolic x coords={1,2},
    enlarge x limits={abs=0.666667cm},  
    every x tick label/.style={
        rotate=45,anchor=north east, text opacity=1, inner sep=5pt    %\x\ticknum (trying make this to work)
    xticklabels={Text A,},
    every extra x tick/.style={
        tick label style={draw=COL\ticknum},    %Here this works 
    extra x ticks={2},
    extra x tick labels={Text Extra},

\addplot+[fill=COL0,ybar] plot coordinates {(1,0.00519089)(2,0.0850676)};
\addplot+[fill=COL1,ybar] plot coordinates {(1,1.74808)(2,1.06387)};
\legend{\strut A,\strut B}

  • 2
    You can't define commands with a digit after letters in their name. And you can't call the command \foo as \f\oo even if you do \newcommand{\f}{f}\newcommand{\oo}{oo}.
    – egreg
    Oct 3, 2020 at 22:06
  • Is there other way to define variables and use together with \ticknum? @egreg
    – etrusks
    Oct 3, 2020 at 22:07
  • Please, make a minimal (but complete) example.
    – egreg
    Oct 3, 2020 at 22:08
  • Look at my edit, thats what im trying to do but with numeric values instead of colors @egreg
    – etrusks
    Oct 3, 2020 at 22:11
  • The fact it works with colors is not relevant; what I asked for is a complete code, at least of the tikzpicture you want to draw.
    – egreg
    Oct 3, 2020 at 22:15

1 Answer 1


I figured out a workaround so I don't have to specify opacity. I'm just making every label as extra label and then do this and specifying different color for every characteristic




every extra x tick/.style={    
    tick label style={fill=FILL\ticknum, draw=DRAW\ticknum,  text=TEXT\ticknum},     

This way I can pick colors that look like it has opacity 0.5 for example. So instead of making text black with opacity 0.5 I'm making text greyish with opacity 1. No one sees the difference

You must log in to answer this question.

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