📚 The CoCalc Library - books, templates and other resources
License: OTHER
\documentclass[a4paper,10pt]{article}1\usepackage{amssymb, amsmath}2\DeclareMathOperator{\arcsinh}{arcsinh}3\DeclareMathOperator{\arccosh}{arccosh}4\DeclareMathOperator{\arctanh}{arctanh}5\usepackage[utf8]{inputenc} % this is needed for umlauts6\usepackage[ngerman]{babel} % this is needed for umlauts7\usepackage[T1]{fontenc} % this is needed for correct output of umlauts in pdf8%layout9\usepackage[margin=2.5cm]{geometry}10\usepackage{parskip}11\usepackage{xcolor}12\usepackage{hyperref}1314\pdfinfo{15/Author (StackExchange and GitHub authors)16/Title (TikZ Cheat Sheet)17/CreationDate (D:20120221095400)18/Subject (TikZ)19/Keywords (TikZ)20}2122\newcommand{\myCode}[1]{\colorbox{gray!30}{#1}}2324\begin{document}2526\title{TikZ cheat sheet}27\author{StackExchange and GitHub authors}28\date{\today}2930\section*{Command Templates}31\begin{itemize}32\item Basic path: \myCode{\textbackslash drawing-command [options] path-specification;}33\item Path specification: \myCode{(coordinate) path-component (coordinate);}34\item Path Reusage \myCode{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. \\35\myCode{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.36\end{itemize}3738\section*{Basic Drawing Commands}39\begin{itemize}40\item \myCode{\textbackslash path}: constructs a path41\end{itemize}4243All following commands are in fact short forms for \myCode{\textbackslash path} with one option or two:44\begin{itemize}45\item \myCode{\textbackslash draw}: constructs and draws ("strokes") a path46\item \myCode{\textbackslash fill}: constructs and fills a path47\item \myCode{\textbackslash filldraw}: constructs, fills, and draws a path (in that order)48\item \myCode{\textbackslash shade}: constructs and shades a path49\item \myCode{\textbackslash shadedraw}: constructs, shades, and draws a path (in that order)50\item \myCode{\textbackslash coordinate}: label a coordinate51\item \myCode{\textbackslash node}: constructs a node52\end{itemize}535455\section*{Coordinate Specifications}56\begin{itemize}57\item \myCode{(<x>,<y>)}: specifies the coordinate as a multiple of the current x- and y-vector (default: 1cm right and 1cm upwards)58\item \myCode{(<$\theta$>:<r>)} specifies a coordinate in polar form with \myCode{r} being the vector length and \myCode{$\theta$} being the angle in degrees59\item \myCode{+<coordinate specification>}: specifies a coordinate relative to the previous position but does not save the current position60\item \myCode{++<coordinate specification>}: specifies a coordinate relative to the previous position61\end{itemize}6263\subsection*{Notes}64\begin{enumerate}65\item 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).66\item 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.67\item 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).68\end{enumerate}697071\section*{Path Specifications}72\begin{itemize}73\item \myCode{(coordinate) (coordinate)}: moves the "current point" from the first coordinate to the second74\item \myCode{(coordinate) -- (coordinate)}: draws a line from the first coordinate to the second75\item \myCode{(coordinate) .. controls (control) and (control) .. (coordinate)}: draws a cubic bezier from the first coordinate to the second with the specified control points76\item \myCode{(coordinate) to[options] (coordinate)}: draws a `to path` from the first coordinate to the second; \myCode{to path}s can be extremely complicated77\item \myCode{(coordinate) rectangle (coordinate)}: draws a rectangle with the coordinates as opposite corners78\item \myCode{(coordinate) circle[options]}: draws a circle centred at the coordinate79\item \myCode{(coordinate) arc[options]}: draws an arc starting at the coordinate80\item \myCode{(coordinate) node[options] \{text\}}: adds a node at the coordinate81\item \myCode{(coordinate) coordinate}: adds a coordinate label at the given coordinate82\end{itemize}8384\section*{Basic Options}85\begin{itemize}86\item \myCode{draw[=<colour specification>]}<sup>1</sup>: draw the current path (with the given colour)87\item \myCode{fill[=<colour specification>]}<sup>1</sup>: fill the current path (with the given colour)88\item \myCode{<colour specification>}: set the colour for draw, fill, text (without explicitly enforcing those actions)89\item \myCode{line width=<dimen>}: sets the line width90\item \myCode{thin, thick, ultra thick} \href{http://martin-thoma.com/sizes-in-latex/}{etc}: presets for the line width91\end{itemize}9293[1] The brackets indicate an optional part and must not be type in the code. I.e. use \myCode{draw=red} and not \myCode{draw[=red]}.94\end{document}959697