Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
1  
Google search for tikz cheat sheet is not of much help. –  mythealias Nov 29 '12 at 7:55
8  
The 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! –  zeroth Nov 29 '12 at 7:55
1  
I'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 tom Dec 4 '12 at 21:16

2 Answers 2

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: constructs a node

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 with r 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

  1. Lengths can be with or without unit. If with a unit they are taken literally, if without they are multiples of the current x or y vector (as appropriate).

  2. 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.

  3. 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 a to path from the first coordinate to the second; to paths 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 width
  • thin, 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].

share|improve this answer
15  
I'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. –  Loop Space Nov 29 '12 at 9:05
    
The 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. –  Loop Space Nov 29 '12 at 10:24
    
I added a small section about coordinate specifications. Hope this is within the spirit of the answer. –  Alexander Nov 29 '12 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. –  Loop Space Nov 29 '12 at 12:32
1  
How 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 not start angle, end angle and delta angle. There are 21 styles for the curve 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 … –  Qrrbrbirlbel Nov 30 '12 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.

This 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. The final PDF can be found on my webpage at http://www.math.ntnu.no/~stacey/documents/tikzcheatsheet.pdf.

share|improve this answer
3  
+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.) –  Sean Allred Jun 16 '13 at 2:24
    
Thank you for this awesome answer! The best thing is, that this can be adapted to future versions of the documentation and will be always complete. I started a bounty to rewards your amazing effort. –  Henri Menke Oct 6 '13 at 12:33
    
Is there the simplest example of TikZ application in which all TikZ macros and its key-values are used? :-) –  cyanide-based food Oct 6 '13 at 14:32
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? –  Loop Space Oct 8 '13 at 8:28
    
I just used this method on the new 3.0.0 manual and found out, that in the TeX file one has to do an additional \let\pgfmanualpdflabel=\@gobble and remove all text containing \pgfmanualpdflabel in the script output. –  Henri Menke Aug 5 at 10:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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