Tikz-cheat-sheet.tex 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. \documentclass[a4paper,10pt]{article}
  2. \usepackage{amssymb, amsmath}
  3. \DeclareMathOperator{\arcsinh}{arcsinh}
  4. \DeclareMathOperator{\arccosh}{arccosh}
  5. \DeclareMathOperator{\arctanh}{arctanh}
  6. \usepackage[utf8]{inputenc} % this is needed for umlauts
  7. \usepackage[ngerman]{babel} % this is needed for umlauts
  8. \usepackage[T1]{fontenc} % this is needed for correct output of umlauts in pdf
  9. %layout
  10. \usepackage[margin=2.5cm]{geometry}
  11. \usepackage{parskip}
  12. \usepackage{xcolor}
  13. \usepackage{hyperref}
  14. \pdfinfo{
  15. /Author (StackExchange and GitHub authors)
  16. /Title (TikZ Cheat Sheet)
  17. /CreationDate (D:20120221095400)
  18. /Subject (TikZ)
  19. /Keywords (TikZ)
  20. }
  21. \newcommand{\myCode}[1]{\colorbox{gray!30}{#1}}
  22. \begin{document}
  23. \title{TikZ cheat sheet}
  24. \author{StackExchange and GitHub authors}
  25. \date{\today}
  26. \section*{Command Templates}
  27. \begin{itemize}
  28. \item Basic path: \myCode{\textbackslash drawing-command [options] path-specification;}
  29. \item Path specification: \myCode{(coordinate) path-component (coordinate);}
  30. \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. \\
  31. \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.
  32. \end{itemize}
  33. \section*{Basic Drawing Commands}
  34. \begin{itemize}
  35. \item \myCode{\textbackslash path}: constructs a path
  36. \end{itemize}
  37. All following commands are in fact short forms for \myCode{\textbackslash path} with one option or two:
  38. \begin{itemize}
  39. \item \myCode{\textbackslash draw}: constructs and draws ("strokes") a path
  40. \item \myCode{\textbackslash fill}: constructs and fills a path
  41. \item \myCode{\textbackslash filldraw}: constructs, fills, and draws a path (in that order)
  42. \item \myCode{\textbackslash shade}: constructs and shades a path
  43. \item \myCode{\textbackslash shadedraw}: constructs, shades, and draws a path (in that order)
  44. \item \myCode{\textbackslash coordinate}: label a coordinate
  45. \item \myCode{\textbackslash node}: constructs a node
  46. \end{itemize}
  47. \section*{Coordinate Specifications}
  48. \begin{itemize}
  49. \item \myCode{(<x>,<y>)}: specifies the coordinate as a multiple of the current x- and y-vector (default: 1cm right and 1cm upwards)
  50. \item \myCode{(<$\theta$>:<r>)} specifies a coordinate in polar form with \myCode{r} being the vector length and \myCode{$\theta$} being the angle in degrees
  51. \item \myCode{+<coordinate specification>}: specifies a coordinate relative to the previous position but does not save the current position
  52. \item \myCode{++<coordinate specification>}: specifies a coordinate relative to the previous position
  53. \end{itemize}
  54. \subsection*{Notes}
  55. \begin{enumerate}
  56. \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).
  57. \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.
  58. \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).
  59. \end{enumerate}
  60. \section*{Path Specifications}
  61. \begin{itemize}
  62. \item \myCode{(coordinate) (coordinate)}: moves the "current point" from the first coordinate to the second
  63. \item \myCode{(coordinate) -- (coordinate)}: draws a line from the first coordinate to the second
  64. \item \myCode{(coordinate) .. controls (control) and (control) .. (coordinate)}: draws a cubic bezier from the first coordinate to the second with the specified control points
  65. \item \myCode{(coordinate) to[options] (coordinate)}: draws a `to path` from the first coordinate to the second; \myCode{to path}s can be extremely complicated
  66. \item \myCode{(coordinate) rectangle (coordinate)}: draws a rectangle with the coordinates as opposite corners
  67. \item \myCode{(coordinate) circle[options]}: draws a circle centred at the coordinate
  68. \item \myCode{(coordinate) arc[options]}: draws an arc starting at the coordinate
  69. \item \myCode{(coordinate) node[options] \{text\}}: adds a node at the coordinate
  70. \item \myCode{(coordinate) coordinate}: adds a coordinate label at the given coordinate
  71. \end{itemize}
  72. \section*{Basic Options}
  73. \begin{itemize}
  74. \item \myCode{draw[=<colour specification>]}<sup>1</sup>: draw the current path (with the given colour)
  75. \item \myCode{fill[=<colour specification>]}<sup>1</sup>: fill the current path (with the given colour)
  76. \item \myCode{<colour specification>}: set the colour for draw, fill, text (without explicitly enforcing those actions)
  77. \item \myCode{line width=<dimen>}: sets the line width
  78. \item \myCode{thin, thick, ultra thick} \href{http://martin-thoma.com/sizes-in-latex/}{etc}: presets for the line width
  79. \end{itemize}
  80. [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]}.
  81. \end{document}