Many times, when I'm coding a tikz-picture, I don't remember the command syntax or the name of one option, and I have to look in pgf-manual is not very short. Does anybody has a summary of Tikz commands fit to one or two pages?
-
3Google search for tikz cheat sheet is not of much help.– mythealiasCommented Nov 29, 2012 at 7:55
-
10The problem is that it would not be an A4 paper page, more likely an A-1 paper size... That is not so helpful. However, it would be fun to see!– nickpapiorCommented Nov 29, 2012 at 7:55
-
2I've seen a shortlist in Texmaker (You know in those listings on the left hand side, where you can also pick commonly used symbols and stuff like that)– long tomCommented Dec 4, 2012 at 21:16
3 Answers
Command Templates
Basic path:
\drawing-command [options] path-specification;
Path specification:
(coordinate) path-component (coordinate);
Path Reusage
postaction={<basic drawing commands> or <decorate>}
When this option is given to any basic drawing commands below, the path is not immediately discarded and reused after the initial drawing command is finished.preaction={<basic drawing commands> or <decorate>}
When this option is given to any basic drawing commands below, the path is used once before the initial drawing command is executed.
Basic Drawing Commands:
\path
: constructs a path
All following commands are in fact short forms for \path
with one option or two:
\draw
: constructs and draws ("strokes") a path\fill
: constructs and fills a path\filldraw
: constructs, fills, and draws a path (in that order)\shade
: constructs and shades a path\shadedraw
: constructs, shades, and draws a path (in that order)\coordinate
: label a coordinate\node[<options>] at (<coordinate>) (<name>) {<text>}
: constructs a node\path (nodeName1) edge [options->] (nodeName2);
: an edge
Coordinate Specifications:
(<x>,<y>)
: specifies the coordinate as a multiple of the current x- and y-vector (default: 1cm right and 1cm upwards)(<θ>:<r>)
specifies a coordinate in polar form withr
being the vector length andθ
being the angle in degrees+<coordinate specification>
: specifies a coordinate relative to the previous position but does not save the current position++<coordinate specification>
: specifies a coordinate relative to the previous position
Notes
Lengths can be with or without unit. If with a unit they are taken literally, if without they are multiples of the current
x
ory
vector (as appropriate).Relative coordinates are with respect to the last saved position. Unless specified otherwise, the above all save their resultant position as the last saved position.
When a relative coordinate is used in a bezier curve specification the behaviour is slightly different. The second control point is taken relative to the final position of the curve, and the final point is taken relative to the initial one (or last saved position).
Path Specifications:
(coordinate) (coordinate)
: moves the "current point" from the first coordinate to the second(coordinate) -- (coordinate)
: draws a line from the first coordinate to the second(coordinate) .. controls (control) and (control) .. (coordinate)
: draws a cubic bezier from the first coordinate to the second with the specified control points(coordinate) to[options] (coordinate)
: draws ato path
from the first coordinate to the second;to path
s can be extremely complicated(coordinate) rectangle (coordinate)
: draws a rectangle with the coordinates as opposite corners(coordinate) circle[options]
: draws a circle centred at the coordinate(coordinate) arc[options]
: draws an arc starting at the coordinate(coordinate) node[options] {text}
: adds a node at the coordinate(coordinate) coordinate
: adds a coordinate label at the given coordinate
Basic Options
draw[=<colour specification>]
1: draw the current path (with the given colour)fill[=<colour specification>]
1: fill the current path (with the given colour)<colour specification>
: set the colour for draw, fill, text (without explicitly enforcing those actions)line width=<dimen>
: sets the line widththin
,thick
,ultra thick
etc: presets for the line width
1 The brackets indicate an optional part and must not be type in the code. I.e. use draw=red
and not draw[=red]
.
-
21I've run out of steam for the moment. This is CW because I think it is one of those things where if lots of people contribute a little bit then it'll be a doable project but if one person tries to do it all then they'll never finish it. Commented Nov 29, 2012 at 9:05
-
1The comments area here should be used for temporary discussion of what should or should not go into this answer. All comments are liable to be deleted once they are resolved as the eventual aim of a CW answer like this is that all useful information be folded into it. Commented Nov 29, 2012 at 10:24
-
I added a small section about coordinate specifications. Hope this is within the spirit of the answer. Commented Nov 29, 2012 at 12:31
-
@Alexander I was pondering your edits as you edited again. The distinction between dimensioned and dimensionless coordinates is a "meta distinction" as it holds for just about anywhere a number is used in TikZ so I think that should be a note at the start of the coordinate section. I was also pondering the distinction between the "most recent coordinate on a path" and the "last saved coordinate" (as used for relative positioning). The aim of this is to be a cheat-sheet so I wouldn't go for a lengthy explanation, but I think that "previous position" is ambiguous as it could mean either. Commented Nov 29, 2012 at 12:32
-
3How deep should this go? Or: The OP says “I don't remember the command syntax or the name of one option“. Oftentimes I feel the same: I know that there exist (too) many options, but which are they and what do they do? For example: I know of
arc
but maybe notstart angle
,end angle
anddelta angle
. There are 21 styles for thecurve to
to path
. We could fill an answer solely with nodes, another one with shapes, some libraries (decorations!) are big enough for an answer alone … Commented Nov 30, 2012 at 1:53
The lazy mathematician in me decided to come up with another approach. I ran the following script on the documentation:
(for f in pgfmanual-en-tikz-{design,scopes,coordinates,paths,actions,shapes,graphs,matrices,trees,plots,transparency,decorations,transformations}.tex; do
cat $f
done) | perl -ne '
if (/(\\(begin|end)\{(coordinatesystem|keylist|package|predefinednode|command|key|stylekey|pathoperation)\})|\\(sub)*section|\\catcode/) {
print;
$c = ($_ =~ tr/{/{/);
$c -= ($_ =~ tr/}/}/);
} else {
if ($c > 0) {
print;
$c += ($_ =~ tr/{/{/);
$c -= ($_ =~ tr/}/}/);
};
};
' | xclip
Then pasted the result into the following template:
\documentclass[a4paper]{ltxdoc}
\usepackage[scale=.9]{geometry}
\usepackage{tikz}
% The location of this will depend on where you put the sources of the pgfmanual
\input{../../../local/share/pgf/doc/generic/pgf/macros/pgfmanual-en-macros}
\begin{document}
%%%% <--- pasted text goes here
\end{document}
Then removed some stuff that had been included by accident (search for codeexample
and remove all such environments - they get included due to the \catcode
switches.), and added a missing closing brace.
When I originally ran this in 2012, it produced a 21-page document listing all (as far as I can tell) of the commands and keys in the TikZ segment of the manual. I've re-run the process in 2022 and it is now a 27-page document.
- 2012 version: https://docs.mathforge.org/tikzcheatsheet-2012.pdf
- 2022 version, PGF version 3.1.8: https://docs.mathforge.org/tikzcheatsheet-2022.pdf
-
6+1 for laziness. Also, a lovely example on why plain-text documentation is awesome; I would never have thought of simply extracting all of the
tikz
commands. Bravo! (I know this is a six month old post, but come on --- this is awesome.) Commented Jun 16, 2013 at 2:24 -
1@HenriMenke Thanks for the bounty - always nice when an answer is appreciated widely. PGFTricks No idea! Why don't you try to write one? Commented Oct 8, 2013 at 8:28
-
1@LoopSpace Can you update the link to the summary PDF please? (if the file still available)– CfunCommented Jul 3, 2016 at 16:28
-
23
-
1@Atcold I've posted an updated link to the original document, I'm re-running the script now to see if it works with the latest documentation. Commented Jul 27, 2022 at 20:01
VisualTikZ
was recently uploaded to CTAN. It consists in more than 150 pages full of examples for TikZ
commands and options. For every command or option a little figure is shown. Just as example, here you have some pages: