TikZ is a Latex package used for drawing precise images in Latex documents. It has a massive specification and a boatload of features that may be useful for style questions.

What tips do people have for golfing in TikZ? As always, tips should be specific to to TikZ (e.g. "Remove comments" is not an answer), and stick to a single tip per answer.

  • \$\begingroup\$ Does anyone golf in Tikz? \$\endgroup\$
    – Pavel
    Commented Feb 7, 2017 at 20:43
  • \$\begingroup\$ @Pavel I do. \$\endgroup\$
    – Wheat Wizard
    Commented Feb 7, 2017 at 20:44
  • 4
    \$\begingroup\$ @Serg There are a good deal of tips questions of similar content on the main site. These are generally considered to be on-topic. \$\endgroup\$
    – Wheat Wizard
    Commented Feb 7, 2017 at 22:49
  • 2
    \$\begingroup\$ For those interested, there is a tikz/pgf manual (its where I found the information for my answers). Version 3.0.1a, Version 2.10 \$\endgroup\$
    – 0 '
    Commented Feb 11, 2017 at 15:02
  • 1
    \$\begingroup\$ @ShreevatsaR I think perhaps a new question should be made for TeX/LaTeX, all of the tips here are currently specific to Tikz, and I can see some benefit in keeping them separate. \$\endgroup\$
    – Wheat Wizard
    Commented May 31, 2017 at 17:51

4 Answers 4


Use \def

\def is an incredibly powerful tool when it comes to golfing. \def allows you to assign something to a variable.

This can be used simply with the to save a number you may use a bunch of times for instance


Will define 1456 as \x for future use much like saving a variable might in a programming language.

However \def is much more powerful than that, because \def doesn't define a variable it defines a snippet of code to be substituted into the program whenever it is called.

For example say you want to draw some rectangles using \draw you might write the following code:


Using \def this could be written as:

  • \$\begingroup\$ This is brilliant in golfing point of view but also very useful to more deeply understand these important commands...you know when they ask you "what is the difference between \def and \newcommand"... \$\endgroup\$ Commented Feb 18, 2020 at 21:38

Use \tikz instead of the tikzpicture environment

Instead of creating a tikzpicture environment (36 bytes) you can use the \tikz command (7 bytes)

Global options can be set in square brackets in using the tikz command as such \tikz[options...]{...}. If the tikz code is one line long the curly braces can be omitted saving an additional two bytes.


Both of the following programs output the image at the bottom

\documentclass{standalone}\input tikz\begin{document}\tikz{\draw[thick,rounded corners=8pt](0,0)--(0,2)--(1,3.25)--(2,2)--(2,0)--(0,2)--(2,2)--(0,0)--(2,0);\draw(-1.5,0)--(0,1.5);}\end{document}

\documentclass{standalone}\input tikz\begin{document}\begin{tikzpicture}\draw[thick,rounded corners=8pt](0,0)--(0,2)--(1,3.25)--(2,2)--(2,0)--(0,2)--(2,2)--(0,0)--(2,0);\draw(-1.5,0)--(0,1.5);\end{tikzpicture}\end{document}


Credit to WheatWizard for figuring the multiline use of \tikz


Use \documentclass[tikz]{standalone}

By chance I found the following in the manual of the standalone package:

For pictures drawn with TikZ a dedicated tikz option is provided which loads the tikz package and also configures the tikzpicture environment to create a single cropped page.

Thus, instead of

\documentclass{standalone}\input tikz\begin{document} ...

one can write

\documentclass[tikz]{standalone}\begin{document} ...

to save 5 bytes.


You can sometimes refrain from using co-ordinate (0,0) completely.
That's an easy one.
Here's a more intricate one:
(,) is the same as (1,1).
Found out that one rather by accident.
Here's a minimal example:

\documentclass[tikz,border=9]{standalone}\def~{document}\begin~\tikz{\draw grid(,);}\end~


enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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