====== TikZ ======
* [[http://math.et.info.free.fr/TikZ/bdd/TikZ-Impatient.pdf]]
* [[https://pgf-tikz.github.io/pgf/pgfmanual.pdf]]
* [[http://pgoutet.free.fr/latex/seance_10/seance_10.pdf]]
* [[http://tug.ctan.org/info/visualtikz/VisualTikZ-fr.pdf]]
* [[https://stuff.mit.edu/afs/athena/contrib/tex-contrib/beamer/pgf-1.01/doc/generic/pgf/version-for-tex4ht/en/pgfmanualse9.html]]
==== Problème avec Babel ====
\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage[francais]{babel}
\usetikzlibrary{babel}
% ...
\begin{document}
\shorthandoff{:}%
\usetikzlibrary{arrows.meta}
\shorthandon{:}%
% ...
==== Exemples ====
{{ :latex:tikz-cluster-node.png?400|}}
\usepackage{tikz}
\usetikzlibrary{shapes} % for ellipses, after \begin{document}
\begin{figure}[ht]
\centering
\begin{tikzpicture}[thick,scale=0.8, every node/.style={scale=0.8}]
\node[draw,ellipse](0) at (0,0) {CPU};
\node[draw,ellipse](1) at (0,-2) {CPU};
\node[draw,ellipse](2) at (3,0) {CPU};
\node[draw,ellipse](3) at (3,-2) {CPU};
\draw (-2,1)-- (5,1);
\draw (-2,1)-- (-2,-3);
\draw (-2,-3)-- (5,-3);
\draw (5,1)-- (5,-3);
\node[draw,ellipse](4) at (10,0) {*PU};
\node[draw](5) at (13,0) {Mémoire};
\draw (8,1)-- (15,1);
\draw (8,1)-- (8,-1);
\draw (15,1)-- (15,-1);
\draw (8,-1)-- (15,-1);
\node[draw,ellipse](6) at (10,-3) {*PU};
\node[draw](7) at (13,-3) {Mémoire};
\draw (8,-2)-- (15,-2);
\draw (8,-2)-- (8,-4);
\draw (15,-2)-- (15,-4);
\draw (8,-4)-- (15,-4);
\node[draw](8) at (3,-4) {Mémoire};
\node[draw](9) at (10,-5) {Réseau};
\draw (6.5,1)-- (6.5,-6);
\draw (5,-1)-- (6.5,-1);
\draw (6.5,0)-- (8,0);
\draw (6.5,-3)-- (8,-3);
\draw (8)-- (6.5,-4);
\draw (6.5,-5)-- (9);
\end{tikzpicture}
\caption{Éléments constituant un nœud de supercalculateur}
\end{figure}
{{ :latex:tikz-graph.png|}}
\usepackage{tikz}
\usetikzlibrary{arrows.meta} % for arrow shapes, after \begin{document}
\begin{figure}[ht]
\centering
\begin{tikzpicture}
\node[draw,circle](01) at (-2,0) {0};
\node[draw,circle](1) at (0,-2) {1};
\node[draw,circle,dashed](02) at (-2,-2) {0};
\node[draw,circle](2) at (0,-4) {2};
\node[draw,circle,dashed](03) at (-2,-4) {0};
\node[draw,circle](3) at (0,-6) {3};
\node[draw,circle,dashed](04) at (-2,-6) {0};
\node[draw,circle](4) at (0,-8) {4};
\node[draw,circle,dashed](05) at (-2,-8) {0};
\node[draw,circle](5) at (0,-10) {5};
\node[draw,circle,dashed](06) at (-2,-10) {0};
\node[draw,circle](6) at (0,-12) {6};
% or, simple arrow: \draw[->,>=latex] (a) -- (b)
\draw[-{Latex[length=3mm]}] (-4,0) -- (-4,-12) node[above,midway,rotate=90]{Temps};
\draw[-{Latex[length=3mm]}] (01) -- (1);
\draw[-{Latex[length=3mm]},dashed] (01) -- (02);
\draw[-{Latex[length=3mm]}] (02) -- (2);
\draw[-{Latex[length=3mm]},dashed] (02) -- (03);
\draw[-{Latex[length=3mm]}] (03) -- (3);
\draw[-{Latex[length=3mm]},dashed] (03) -- (04);
\draw[-{Latex[length=3mm]}] (04) -- (4);
\draw[-{Latex[length=3mm]},dashed] (04) -- (05);
\draw[-{Latex[length=3mm]}] (05) -- (5);
\draw[-{Latex[length=3mm]},dashed] (05) -- (06);
\draw[-{Latex[length=3mm]}] (06) -- (6);
\end{tikzpicture}
\end{figure}
=== Mettre du texte au-dessus d'un rectangle ===
[[https://tex.stackexchange.com/questions/13401/labeling-rectangle-above-rectangle|Source]]
\draw[orange,ultra thick,rounded corners] (0.316,0.782) rectangle (0.402,0.807);
\path (0.316,0.807) -- (0.402,0.807) node[midway,above,orange] {\textbf{A}}; % reprend les coordonnées du côté haut du rectangle
=== Mettre du texte au centre d'un rectangle ===
[[https://tex.stackexchange.com/questions/448164/add-text-within-tikz-rectangle-node|Source]]
\draw[draw=none,fill=red!40!white,opacity=0.9] (3, 0) rectangle (9.2, 7.5) node[midway,align=center] {foo};
=== Rectangle arrondi sans bordure, pivoté, avec texte ===
{{ :latex:capture_d_ecran_du_2022-02-08_18-01-18.png|}}
* [[https://tex.stackexchange.com/questions/82530/how-to-draw-a-filled-rectangle-without-a-border-using-tikz]]
* [[https://tex.stackexchange.com/questions/96340/how-to-place-a-textnode-at-the-center-of-a-drawn-rectangle/348951]]
* [[https://tex.stackexchange.com/questions/115554/how-to-rotate-a-tikz-label]]
* [[https://tex.stackexchange.com/questions/45848/rotate-node-text-and-use-relative-positioning-in-tikz]]
\path[rounded corners,fill=compColor] (x1,y1) rectangle (x2,y2) node[pos=.5,rotate=90] {$n$ computing Threads};
=== Faire une étoile avec un éclair ===
{{ :latex:capture_d_ecran_du_2022-02-08_17-36-48.png|}}
[[https://tex.stackexchange.com/questions/255916/tikz-hand-drawn-explosion]]
\node[starburst,starburst point height=8pt,fill=red,opacity=0.5,text opacity=1,scale=0.8] at (2, 2) {\huge\Lightning};
=== Chemin avec des flèches ===
{{ :latex:capture_d_ecran_du_2022-02-08_18-18-28.png|}}
* [[https://latexdraw.com/how-to-draw-an-arrow-in-the-middle-of-a-line-in-tikz/#t-1607758527668]]
* [[https://tex.stackexchange.com/questions/3161/tikz-how-to-draw-an-arrow-in-the-middle-of-the-line]]
* https://www.latex4technics.com/?note=khn6hz
\newcommand{\arrowOnLine}[1]{node[sloped,pos=#1,allow upside down]{\tikz \draw[->,line width=2pt] (-1pt,0) -- (1pt,0);}}
\draw[Round Cap-,line width=2pt,rounded corners,color=commColor] (3.5,0.1)
-- (3.5,1.4) \arrowOnLine{0.4}
-- (1.4,1.4) \arrowOnLine{0.7}
-- (1.4,5) \arrowOnLine{0.5}
-- (6.6,5) \arrowOnLine{0.15} \arrowOnLine{0.9}
-- (6.6,0.4) \arrowOnLine{0.5}
-- (6.2,0) \arrowOnLine{1};
=== Nouvelle ligne dans du texte dans un nœud ===
L'attribut ''align'' permet de faire fonctionner ''\\'' ([[https://tex.stackexchange.com/questions/24372/how-to-add-newline-within-node-using-tikz|source]]).
\node[align=center] at (0,0) {Nouvelle\\ligne};
=== Faire une grosse flèche ===
[[https://tex.stackexchange.com/questions/578524/tikz-how-to-draw-a-fat-arrow-specifying-border-and-fill-colour|Source]]
\usetikzlibrary{shapes.arrows}
\node[
single arrow,
draw=black,
fill=gray,
minimum width=7pt,
single arrow head extend=3pt,
minimum height=7mm,
rotate=-90
] at (5, -4.75) {};
==== Faire un schéma sur une image ====
[[https://tex.stackexchange.com/questions/9559/drawing-on-an-image-with-tikz|Source]]
\begin{tikzpicture}
\node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[width=0.9\textwidth]{some_image.jpg}};
\begin{scope}[x={(image.south east)},y={(image.north west)}]
% Ces trois commandes suivantes permettent d'afficher une grille qui aide à visualiser les coordonnées des éléments à dessiner:
\draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1);
\foreach \x in {0,1,...,9} { \node [anchor=north] at (\x/10,0) {0.\x}; }
\foreach \y in {0,1,...,9} { \node [anchor=east] at (0,\y/10) {0.\y}; }
\end{scope}
\end{tikzpicture}
==== Coordonnées ====
=== Définir des coordonnées ===
[[https://tex.stackexchange.com/questions/246856/how-to-label-the-nodes-coordinates-in-tikz-picture|Source]]
\coordinate (B) at (210:2);
=== Changer l'origine des coordonnées dans le schéma ===
Pour faire quelque chose de répétitif sans avoir à changer toutes les coordonnées, par exemple ([[https://tex.stackexchange.com/questions/353855/shifting-origin-0-0-to-new-coordinates-in-tikz|source]]):
\begin{tikzpicture}
\draw [->, very thick] (0, 0) -- (0,-1);
\tikzset{shift={(0,-1)}}
\draw [->, very thick] (0, 0) -- (0,-1);
\tikzset{shift={(0,-1)}}
\draw [->, very thick] (0, 0) -- (0,-1);
\end{tikzpicture}
=== Orienter l'axe des ordonnées de haut en bas ===
[[https://tex.stackexchange.com/questions/84715/tikz-change-coordinate-system-so-y-points-downwards|Source]]
\begin{tikzpicture}[yscale=-1]
% 0
% +---> x
% |
% |
% v
% y
\end{tikzpicture}
==== Tailles ====
=== Changer la taille d'une figure Tikz ===
Le fichier doit avoir l'extension ''.tikz'' ([[https://tex.stackexchange.com/questions/75449/specifying-the-width-and-height-of-a-tikzpicture/320521|source]]) :
\usepackage{tikzscale}
\includegraphics[width=\linewidth]{fichier}
\begin{tikzpicture}
% ...
\end{tikzpicture}
Si un message dit que ''fichier'' n'est pas trouvé, il est possible d'utiliser ''resizebox'' :
\resizebox{\linewidth}{!}{\includegraphics[width=\linewidth]{fichier}}
=== Changer la taille d'un node ===
\draw node[fill,circle,scale=0.3]{} (0,0);
=== Fixer la taille d'un cercle ===
[[https://tex.stackexchange.com/questions/228364/is-it-possible-to-set-a-maximum-node-width-in-tikz|Source]]
\node[draw,circle,text width=7mm,inner sep=0pt,align=center](11) at (3,0) {11};
Utiliser le même ''text width=7mm,inner sep=0pt'' pour tous les cercles.
=== Réduire la taille de tous les textes ===
[[https://tex.stackexchange.com/questions/107057/adjusting-font-size-with-tikz-picture|Source]]
\begin{tikzpicture}[every node/.style={scale=0.9}]
% ...
\end{tikzpicture}
==== Générer un PDF à partir de seulement l'image Tikz ====
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,arrows,shapes,patterns,snakes,plotmarks,arrows.meta}
\begin{document}
\begin{tikzpicture}
% \draw ...
\end{tikzpicture}
\end{document}
=== Convertir une image Tikz en SVG ===
Après avoir un PDF contenant uniquement l'image Tikz :
pdftocairo -svg test.pdf test.svg
''pdftocairo'' est dans le paquet Debian ''poppler-utils''.