Graphisme in Latex
Graphisme in Latex
Graphisme in Latex
This five‐part series of ar�cles uses a combina�on of video and textual descrip�ons to
teach the basics of crea�ng LaTeX graphics using TikZ. These tutorials were first published
on the original ShareLateX blog site during August 2013; consequently, today's editor
interface (Overleaf) has changed considerably due to the development of ShareLaTeX and
the subsequent merger of ShareLaTeX and Overleaf. However, much of the content is s�ll
relevant and teaches you some basic LaTeX—skills and exper�se that will apply across all
pla�orms.
\usepackage{tikz}
Now whenever we want to create a TikZ diagram we need to use the tikzpicture
environment.
\begin{tikzpicture}
<code goes here>
\end{tikzpicture}
Basic shapes
One of the simplest and most commonly used commands in TikZ is the \draw command.
To draw a straight line we use this command, then we enter a star�ng co‐ordinate, followed
by two dashes before the ending co‐ordinate. We then finish the statement by closing it
with a semicolon.
However this isn't par�cularly good style. As we are drawing a line that ends up in the
same place we started, it is be�er to finish the statement with the keyword cycle rather
than the last co‐ordinate.
To simplify this code further we can use the rectangle keyword a�er the star�ng co‐
ordinate and then follow it with the co‐ordinate of the corner diagonally opposite.
We can also add lines that aren't straight. For example, this is how we draw a parabola:
To add a curved line we use control points. We begin with our star�ng co‐ordinate, then use
two dots followed by the keyword controls and then the co‐ordinates of our control
points separated by an and. Then a�er two more dots we have the final point. These
control points act like magnets a�rac�ng the line in their direc�on:
We can then add a circle like this. The first co‐ordinate is the circle's centre and the length
in brackets at the end is the circle's radius:
This is how we draw an ellipse. This �me the lengths in the brackets separated by an and,
are the x‐direc�on radius and the y‐direc�on radius respec�vely:
This is how we draw an arc. In the final bracket we enter the star�ng angle, the ending
angle and the radius. This �me they are separated by colons:
To customise the way these lines are drawn we add extra arguments into the \draw
command. For example, we can edit the circle we drew so that the line is red, thick and
dashed:
Grids
Very o�en when drawing diagrams we will want to draw a grid. To do this we use the
\draw command followed by by some addi�onal arguments. For example, we specify the
grid step size using step= and a length. We've also specified the colour gray and told it to
make the lines very thin. A�er these arguments we enter the co‐ordinates of the
bo�om‐le� corner, followed by the keyword grid and then the co‐ordinates of the top
right‐corner:
If we want to remove the outer lines around this grid we can crop the size slightly like this:
Colour �lling
Now lets add a shape onto our grid and colour it in. To do this we use the \fill command
instead of the \draw command. Then in square brackets we enter a colour. For example,
this specifies a colour that is 40% blue mixed with 60% white. Then we just specify a
closed shape as we would normally:
If we wanted to add a border around this shape we could change it to the \filldraw
command and then alter the arguments so that we have both a fill colour and a draw colour
specified:
If instead of one solid colour we want a colour gradient, we could change it to the \shade
command. Then in the square brackets we specify a le� colour and a right colour:
Or we could even change it by specifying an inner and outer colour like this:
Finally we could also add a border to this by using the \shadedraw command and adding a
draw colour:
Axes
Let's finish 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:
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 specifica�on 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‐le�‐hand corner to anchor the node to the co‐ordinate:
To finish our axes we can add in �cks and numbering like this:
\foreach \x in {0,1,2,3,4}
\draw (\x cm,1pt) -- (\x cm,-1pt) node[anchor=north] {$\x$};
\foreach \y in {0,1,2,3,4}
\draw (1pt,\y cm) -- (-1pt,\y cm) node[anchor=east] {$\y$};
This clever piece of code uses two for each loops to systema�cally go along the axes
adding the �cks and numbers. In each one, the variable x or y takes on all of the numbers in
the curly brackets, each in turn and executes the \draw command.
This concludes our discussion on basic drawing in TikZ. If you want to play around with the
document we created in this post you can access it here (h�ps://www.sharelatex.com
/project/521b4a1206bf09190f129751). In the next post (/learn/latex
/LaTeX_Graphics_using_TikZ%3A_A_Tutorial_for_Beginners_(Part_2)%E2%80
%94Genera�ng_TikZ_Code_from_GeoGebra) we'll look expor�ng TikZ code from
GeoGebra (h�ps://www.geogebra.org/?lang=en‐GB).
/LaTeX_Graphics_using_TikZ%3A_A_Tutorial_for_Beginners_(Part_4)%E2%80
%94Circuit_Diagrams_Using_Circui�kz);
• Part 5: Crea�ng Mind Maps (/learn/latex
/LaTeX_Graphics_using_TikZ%3A_A_Tutorial_for_Beginners_(Part_5)%E2%80
%94Crea�ng_Mind_Maps).
Overleaf guides
Crea�ng a document in Overleaf (/learn/how‐to/Crea�ng_a_document_in_Overleaf)
Uploading a project (/learn/how‐to/Uploading_a_project)
Copying a project (/learn/how‐to/Copying_a_project)
Crea�ng a project from a template (/learn/how‐to/Crea�ng_a_project_from_a_template)
Using the Overleaf project menu (/learn/how‐to/Using_the_Overleaf_project_menu)
Including images in Overleaf (/learn/how‐to/Including_images_on_Overleaf)
Expor�ng your work from Overleaf (/learn/how‐to/Expor�ng_your_work_from_Overleaf)
Working offline in Overleaf (/learn/how‐to/Working_Offline_in_Overleaf)
Using Track Changes in Overleaf (/learn/how‐to/Track_Changes_in_Overleaf)
Using bibliographies in Overleaf (/learn/how‐to/Using_bibliographies_on_Overleaf)
Sharing your work with others (/learn/how‐to/Sharing_a_project)
Using the History feature (/learn/latex/Using_the_History_feature)
Debugging Compila�on �meout errors (/learn/how‐
to/Why_do_I_keep_ge�ng_the_compile_�meout_error_message%3F)
How‐to guides (/learn/how‐to)
Guide to Overleaf’s premium features (/learn/how‐to/Overleaf_premium_features)
LaTeX Basics
Crea�ng your first LaTeX document (/learn/latex/Crea�ng_a_document_in_LaTeX)
Mathematics
Mathema�cal expressions (/learn/latex/Mathema�cal_expressions)
Subscripts and superscripts (/learn/latex/Subscripts_and_superscripts)
Brackets and Parentheses (/learn/latex/Brackets_and_Parentheses)
Matrices (/learn/latex/Matrices)
Frac�ons and Binomials (/learn/latex/Frac�ons_and_Binomials)
Aligning equa�ons (/learn/latex/Aligning_equa�ons_with_amsmath)
Operators (/learn/latex/Operators)
Spacing in math mode (/learn/latex/Spacing_in_math_mode)
Integrals, sums and limits (/learn/latex/Integrals%2C_sums_and_limits)
Display style in math mode (/learn/latex/Display_style_in_math_mode)
List of Greek le�ers and math symbols (/learn/latex/List_of_Greek_le�ers_and_math_symbols)
Mathema�cal fonts (/learn/latex/Mathema�cal_fonts)
Using the Symbol Pale�e in Overleaf (h�ps://www.overleaf.com/learn/how‐
to/Using_the_Symbol_Pale�e_in_Overleaf)
Languages
Mul�lingual typese�ng on Overleaf using polyglossia and fontspec (/learn/latex
/Mul�lingual_typese�ng_on_Overleaf_using_polyglossia_and_fontspec)
Mul�lingual typese�ng on Overleaf using babel and fontspec (/learn/latex
/Mul�lingual_typese�ng_on_Overleaf_using_babel_and_fontspec)
Interna�onal language support (/learn/latex/Interna�onal_language_support)
Quota�ons and quota�on marks (/learn/latex/Typese�ng_quota�ons)
Arabic (/learn/latex/Arabic)
Chinese (/learn/latex/Chinese)
French (/learn/latex/French)
German (/learn/latex/German)
Greek (/learn/latex/Greek)
Italian (/learn/latex/Italian)
Japanese (/learn/latex/Japanese)
Korean (/learn/latex/Korean)
Portuguese (/learn/latex/Portuguese)
Russian (/learn/latex/Russian)
Spanish (/learn/latex/Spanish)
Document structure
Sec�ons and chapters (/learn/latex/Sec�ons_and_chapters)
Table of contents (/learn/latex/Table_of_contents)
Cross referencing sec�ons, equa�ons and floats (/learn/latex
/Cross_referencing_sec�ons%2C_equa�ons_and_floats)
Indices (/learn/latex/Indices)
Glossaries (/learn/latex/Glossaries)
Nomenclatures (/learn/latex/Nomenclatures)
Management in a large project (/learn/latex/Management_in_a_large_project)
Mul�‐file LaTeX projects (/learn/latex/Mul�‐file_LaTeX_projects)
Hyperlinks (/learn/latex/Hyperlinks)
Formatting
Lengths in LATEX (/learn/latex/Lengths_in_LaTeX)
Headers and footers (/learn/latex/Headers_and_footers)
Page numbering (/learn/latex/Page_numbering)
Paragraph forma�ng (/learn/latex/Paragraph_forma�ng)
Line breaks and blank spaces (/learn/latex/Line_breaks_and_blank_spaces)
Text alignment (/learn/latex/Text_alignment)
Page size and margins (/learn/latex/Page_size_and_margins)
Single sided and double sided documents (/learn/latex/Single_sided_and_double_sided_documents)
Mul�ple columns (/learn/latex/Mul�ple_columns)
Counters (/learn/latex/Counters)
Code lis�ng (/learn/latex/Code_lis�ng)
Code Highligh�ng with minted (/learn/latex/Code_Highligh�ng_with_minted)
Using colours in LaTeX (/learn/latex/Using_colours_in_LaTeX)
Footnotes (/learn/latex/Footnotes)
Margin notes (/learn/latex/Margin_notes)
Fonts
Font sizes, families, and styles (/learn/latex/Font_sizes%2C_families%2C_and_styles)
Font typefaces (/learn/latex/Font_typefaces)
Presentations
Beamer (/learn/latex/Beamer)
Powerdot (/learn/latex/Powerdot)
Posters (/learn/latex/Posters)
Commands
Commands (/learn/latex/Commands)
Environments (/learn/latex/Environments)
Field speci�c
Class �les
Understanding packages and class files (/learn/latex/Understanding_packages_and_class_files)
List of packages and class files (/learn/latex/List_of_packages_and_class_files)
Wri�ng your own package (/learn/latex/Wri�ng_your_own_package)
Wri�ng your own class (/learn/latex/Wri�ng_your_own_class)
Advanced TeX/LaTeX
In‐depth technical ar�cles on TeX/LaTeX (/learn/latex/Ar�cles)