latex:tikz

Ceci est une ancienne révision du document !


TikZ

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc} 
\usepackage{tikz}
\usepackage[francais]{babel}
\usetikzlibrary{babel}
% ...
 
\begin{document}
\shorthandoff{:}%
\usetikzlibrary{arrows.meta}
\shorthandon{:}%
 
% ...

\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}

\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

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

Rectangle arrondi sans bordure, pivoté, avec texte

Faire une étoile avec un éclair

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

\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 \\ (source).

\node[align=center] at (0,0) {Nouvelle\\ligne};

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}

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 (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

Source

\begin{tikzpicture}[yscale=-1]
%   0
%    +---> x
%    |
%    |
%    v
%    y
\end{tikzpicture}

Changer la taille d'une figure Tikz

Le fichier doit avoir l'extension .tikz (source) :

\usepackage{tikzscale}
 
\includegraphics[width=\linewidth]{fichier}
fichier.tikz
\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

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

Source

\begin{tikzpicture}[every node/.style={scale=0.9}]
    % ...
\end{tikzpicture}
  • latex/tikz.1681719209.txt.gz
  • Dernière modification : 2023/04/17 10:13
  • de phsw