Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1 of 13 4/14/2019, 10:50 PM
LaTeX Graphics using TikZ: A Tutorial for Beginners (Part 1)—Basic ... https://www.overleaf.com/learn/latex/LaTeX_Graphics_using_TikZ:_A_...
LaTeX Basics
Basic Drawing Using TikZ
Creating your �rst LaTeX
document (/learn
/Creating_a_document_in_LaTeX)
Choosing a LaTeX
Compiler (/learn
/Choosing_a_LaTeX_Compiler)
Paragraphs and new lines
(/learn
/Paragraphs_and_new_lines)
Bold, italics and
underlining (/learn
/Bold,_italics_and_underlining)
Lists (/learn/Lists)
Errors (/learn/Errors)
TikZ (http://cremeronline.com/LaTeX/minimaltikz.pdf) is a LaTeX
package (https://ctan.org/pkg/pgf?lang=en) that allows you to create
Mathematics
high quality diagrams—and often quite complex ones too. In this �rst
Mathematical post we'll start with the basics, showing how to draw simple shapes,
expressions (/learn with subsequent posts introducing some of the interesting things you
/Mathematical_expressions) can do using the tikz package.
Subscripts and
superscripts (/learn To get started with TikZ we need to load up the tikz package:
/Subscripts_and_superscripts)
\usepackage{tikz}
Brackets and
Parentheses (/learn Now whenever we want to create a TikZ diagram we need to use the
/Brackets_and_Parentheses) tikzpicture environment.
Fractions and Binomials
(/learn
\begin{tikzpicture}
<code goes here>
/Fractions_and_Binomials)
\end{tikzpicture}
Aligning Equations
(/learn
Basic shapes
/Aligning_equations)
Operators (/learn One of the simplest and most commonly used commands in TikZ is
/Operators) the \draw command. To draw a straight line we use this command,
Spacing in math mode then we enter a starting co-ordinate, followed by two dashes before
(/learn the ending co-ordinate. We then �nish the statement by closing it
/Spacing_in_math_mode) with a semicolon.
Integrals, sums and limits
\draw (0,0) -- (4,0);
(/learn
/Integrals,_sums_and_limits)
(/learn/File:Tiksline.png)
Display style in math
mode (/learn
/Display_style_in_math_mode) We can then add more co-ordinates in like this to make it a square:
List of Greek letters and
\draw (0,0) -- (4,0) -- (4,4) -- (0,4) -- (0,0);
math symbols (/learn
2 of 13 4/14/2019, 10:50 PM
LaTeX Graphics using TikZ: A Tutorial for Beginners (Part 1)—Basic ... https://www.overleaf.com/learn/latex/LaTeX_Graphics_using_TikZ:_A_...
/List_of_Greek_letters_and_math_symbols)
Mathematical fonts
(/learn
/Mathematical_fonts)
Figures and
tables (/learn
Bibliography We can also add lines that aren't straight. For example, this is how we
management in LaTeX draw a parabola:
(/learn
\draw (0,0) parabola (4,4);
/Bibliography_management_in_LaTeX)
Bibliography
management with
biblatex (/learn
/Bibliography_management_in_LaTeX)
Biblatex bibliography
styles (/learn
/Biblatex_bibliography_styles) (/learn
Biblatex citation styles
(/learn
/Biblatex_citation_styles)
Bibliography
management with natbib
(/learn
/File:Tiksparabola.png)
/Bibliography_management_with_natbib)
Natbib bibliography To add a curved line we use control points. We begin with our starting
styles (/learn co-ordinate, then use two dots followed by the keyword controls
/Natbib_bibliography_styles) and then the co-ordinates of our control points separated by an and.
3 of 13 4/14/2019, 10:50 PM
LaTeX Graphics using TikZ: A Tutorial for Beginners (Part 1)—Basic ... https://www.overleaf.com/learn/latex/LaTeX_Graphics_using_TikZ:_A_...
Natbib citation styles Then after two more dots we have the �nal point. These control
(/learn points act like magnets attracting the line in their direction:
/Natbib_citation_styles)
\draw (0,0) .. controls (0,4) and (4,0) .. (4,4);
Bibliography
management with bibtex
(/learn
/Bibliography_management_with_bibtex)
Bibtex bibliography styles
(/learn
/Bibtex_bibliography_styles)
(/learn/File:Tikscurve.png)
Languages
International language
support (/learn
/International_language_support)
Quotations and
quotation marks (/learn
We can then add a circle like this. The �rst co-ordinate is the circle's
/Typesetting_quotations)
centre and the length in brackets at the end is the circle's radius:
Arabic (/learn/Arabic)
Chinese (/learn/Chinese)
\draw (2,2) circle (3cm);
French (/learn/French)
German (/learn/German)
Greek (/learn/Greek)
Italian (/learn/Italian)
Japanese (/learn
/Japanese)
Korean (/learn/Korean)
Portuguese (/learn
/Portuguese)
Russian (/learn/Russian)
Spanish (/learn/Spanish)
Document
structure
Sections and chapters
(/learn/File:Tiksnicecircle.png)
(/learn
/Sections_and_chapters) This is how we draw an ellipse. This time the lengths in the brackets
Table of contents (/learn separated by an and, are the x-direction radius and the y-direction
/Table_of_contents) radius respectively:
Cross referencing
sections and equations
\draw (2,2) ellipse (3cm and 1cm);
(/learn
/Cross_referencing_sections_and_equations)
Indices (/learn/Indices)
4 of 13 4/14/2019, 10:50 PM
LaTeX Graphics using TikZ: A Tutorial for Beginners (Part 1)—Basic ... https://www.overleaf.com/learn/latex/LaTeX_Graphics_using_TikZ:_A_...
Glossaries (/learn
/Glossaries)
Nomenclatures (/learn
/Nomenclatures)
Management in a large
project (/learn
/Management_in_a_large_project) (/learn/File:Tiksellipse.png)
Multi-�le LaTeX projects
(/learn/Multi- This is how we draw an arc. In the �nal bracket we enter the starting
�le_LaTeX_projects) angle, the ending angle and the radius. This time they are separated
Hyperlinks (/learn by colons:
/Hyperlinks)
\draw (3,0) arc (0:75:3cm);
Formatting
Lengths in LATEX (/learn
/Lengths_in_LaTeX)
Headers and footers
(/learn/File:Tiksarcsegment.png)
(/learn
/Headers_and_footers)
Page numbering (/learn
/Page_numbering)
Paragraph formatting
(/learn To customise the way these lines are drawn we add extra arguments
/Paragraph_formatting)
into the \draw command. For example, we can edit the circle we
Line breaks and blank
drew so that the line is red, thick and dashed:
spaces (/learn
/Line_breaks_and_blank_spaces) \draw[red,thick,dashed] (2,2) circle (3cm);
Text alignment (/learn
/Text_alignment)
Page size and margins
(/learn
/Page_size_and_margins)
Single sided and double
sided documents (/learn
/Single_sided_and_double_sided_documents)
Multiple columns (/learn
/Multiple_columns)
Counters (/learn
/Counters)
Code listing (/learn
/Code_listing)
Code Highlighting with
minted (/learn
/Code_Highlighting_with_minted)
(/learn/File:Tiksredthickdashed.png)
Using colours in LaTeX
5 of 13 4/14/2019, 10:50 PM
LaTeX Graphics using TikZ: A Tutorial for Beginners (Part 1)—Basic ... https://www.overleaf.com/learn/latex/LaTeX_Graphics_using_TikZ:_A_...
(/learn
/Using_colours_in_LaTeX)
Footnotes (/learn Grids
/Footnotes)
Margin notes (/learn
Very often when drawing diagrams we will want to draw a grid. To do
/Margin_notes) this we use the \draw command followed by by some additional
arguments. For example, we specify the grid step size using step=
Fonts and a length. We've also speci�ed the colour gray and told it to make
Presentations
Beamer (/learn/Beamer)
Powerdot (/learn
/Powerdot)
Posters (/learn/Posters)
Commands
Commands (/learn
/Commands)
Environments (/learn
/Environments)
Field speci�c
Theorems and proofs
(/learn/File:Tiksgrid1.png)
(/learn
/Theorems_and_proofs) If we want to remove the outer lines around this grid we can crop the
Chemistry formulae size slightly like this:
(/learn
/Chemistry_formulae) \draw[step=1cm,gray,very thin] (-1.9,-1.9) grid (5.9,5.9);
Feynman diagrams
(/learn
/Feynman_diagrams)
Molecular orbital
diagrams (/learn
/Molecular_orbital_diagrams)
Chess notation (/learn
/Chess_notation)
6 of 13 4/14/2019, 10:50 PM
LaTeX Graphics using TikZ: A Tutorial for Beginners (Part 1)—Basic ... https://www.overleaf.com/learn/latex/LaTeX_Graphics_using_TikZ:_A_...
Class �les
Understanding packages
and class �les (/learn /File:Tiksgrid2.png)
/Understanding_packages_and_class_�les)
List of packages and class Colour �lling
�les (/learn
/List_of_packages_and_class_�les) Now lets add a shape onto our grid and colour it in. To do this we use
Writing your own the \fill command instead of the \draw command. Then in square
package (/learn brackets we enter a colour. For example, this speci�es a colour that is
/Writing_your_own_package) 40% blue mixed with 60% white. Then we just specify a closed shape
Writing your own class as we would normally:
(/learn
/Writing_your_own_class) \fill[blue!40!white] (0,0) rectangle (4,4);
Tips (/learn/Tips)
7 of 13 4/14/2019, 10:50 PM
LaTeX Graphics using TikZ: A Tutorial for Beginners (Part 1)—Basic ... https://www.overleaf.com/learn/latex/LaTeX_Graphics_using_TikZ:_A_...
(/learn
/File:Tiks�ll.png)
(/learn
/File:Tiks�lldraw.png)
8 of 13 4/14/2019, 10:50 PM
LaTeX Graphics using TikZ: A Tutorial for Beginners (Part 1)—Basic ... https://www.overleaf.com/learn/latex/LaTeX_Graphics_using_TikZ:_A_...
(/learn
/File:Tiksshade1.png)
(/learn
/File:Tiksshade2.png)
9 of 13 4/14/2019, 10:50 PM
LaTeX Graphics using TikZ: A Tutorial for Beginners (Part 1)—Basic ... https://www.overleaf.com/learn/latex/LaTeX_Graphics_using_TikZ:_A_...
(/learn
/File:Tiksshade3.png)
(/learn
/File:Tiksshadedraw.png)
10 of 13 4/14/2019, 10:50 PM
LaTeX Graphics using TikZ: A Tutorial for Beginners (Part 1)—Basic ... https://www.overleaf.com/learn/latex/LaTeX_Graphics_using_TikZ:_A_...
Axes
Let's �nish this post by adding some labeled axes to our grid. To do
this we draw two normal lines both from (0,0), but we'll make them
thick and add arrowheads using a dash and a pointed bracket:
(/learn
/File:Tiksplainarrows.png)
We can also label our axes using nodes. To do this we add the
keyword node into both \draw statements next to the end co-
ordinates, followed by an anchor speci�cation in square brackets
and the text in curly brackets. Every node we create in TikZ has a
number of anchors. So when we specify the north west anchor for
the x-axis node, we are telling TikZ to use the anchor in the top-left-
hand corner to anchor the node to the co-ordinate:
11 of 13 4/14/2019, 10:50 PM
LaTeX Graphics using TikZ: A Tutorial for Beginners (Part 1)—Basic ... https://www.overleaf.com/learn/latex/LaTeX_Graphics_using_TikZ:_A_...
(/learn/File:Tiksnodes.png)
To �nish our axes we can add in ticks and numbering like this:
\foreach \x in {0,1,2,3,4}
\draw (\x cm,1pt) -- (\x cm,-1pt) node[anchor=north
\foreach \y in {0,1,2,3,4}
\draw (1pt,\y cm) -- (-1pt,\y cm) node[anchor=east
(/learn/File:Tiksforeach.png)
This clever piece of code uses two for each loops to systematically
go along the axes adding the ticks and numbers. In each one, the
12 of 13 4/14/2019, 10:50 PM
LaTeX Graphics using TikZ: A Tutorial for Beginners (Part 1)—Basic ... https://www.overleaf.com/learn/latex/LaTeX_Graphics_using_TikZ:_A_...
13 of 13 4/14/2019, 10:50 PM