I am printing a diagram and want to use a_[0...3] as tick labels on the x-axis. Right now I have a[0...7] as labels and look for a way to print a[\tick mod 4] (i.e. a_0, a_1, a_2, a_3, a_0, a_1, a_2, a_3). I tried using the solutions found found here (How do I calculate n modulo 3 in LaTeX?), but they all bring up errors when used in the line xticklabel={$a_{\pgfmathprintnumber[int trunc]{\tick}}$}.

Here is an MWE. Can anyone help?


         xticklabel={$a_{\pgfmathprintnumber[int trunc]{\tick}}$},
         yticklabel={$b_{\pgfmathprintnumber[int trunc]{\tick}}$}

   \addplot coordinates {(0,3) (1,2) (2,1) (3,0)} {};
   \addplot coordinates {(1,3) (2,2) (3,1) (4,0)} {};
   \addplot coordinates {(2,3) (3,2) (4,1) (5,0)} {};
   \addplot coordinates {(3,3) (4,2) (5,1) (6,0)} {};


You can change one line as follows:


\pgfmathparse evaluates its argument as a mathematical expression, but does not return a result. It normally handles floating-point numbers, so we use int to truncate the resultant value to an integer. \pgfmathresult prints the result of the most-recent invocation of \pgfmathparse.

  • 4
    \pgfmathparse{mod(\tick,3)}\pgfmathprintnumber[int trunc]{\pgfmathresult}} would separate the number printing from the math parsing. – percusse May 21 '13 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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