Skip to content
Effie Daum edited this page Feb 4, 2024 · 1 revision

Here is a small tutorial on how to use Tikz to create figures. This tutorial was created by Johann Laconte (Thanks 🎉).

Presentation

First, a small presentation to explain what is Tikz and why you should use it: Presentation

Practical examples

For those examples, you can copy the code in Overleaf directly or in your desktop LaTex application (i.e. TexStudio). I suggest you to modify the code to see the effect of each command on the figure and see how the figure itself responds if you change the coordinates.

Robot on a trajectory

\documentclass[tikz, dvipsnames, margin=1mm]{standalone}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}

    %4) draw trajectory
    \draw[BrickRed, thick] plot[smooth, tension=1] coordinates{
    (0,0)
    (1,1)
    (3,2)
    (4,4)
    };
    
    %1) draw warthog
    \coordinate (R) at (3,2);
    \begin{scope}[shift={(R)}, rotate=45]
        \draw[fill=black!40] (.3,.4) rectangle +(.5,.3); 
        \draw[fill=black!40] (.3,-.4) rectangle +(.5,-.3); 
        \draw[fill=black!40] (-.3,.4) rectangle +(-.5,.3); 
        \draw[fill=black!40] (-.3,-.4) rectangle +(-.5,-.3); 
        \draw[fill=Goldenrod] (-.7,-.5) rectangle +(1.4,1);
        \draw[fill=black] (0,0) circle(1pt);
    \end{scope}
    
    % draw axis
    \draw[<->] (0,5) -- (0,0) -- (5,0);
    
    %draw coords
    \coordinate (O) at (0,0);
    \draw[dashed] (R) -- (O|-R) node[left]{$y_r$};
    \draw[dashed] (R) -- (R|-O) node[below]{$x_r$};
    
\end{tikzpicture}

\end{document}

drawing

Flowchart

\documentclass[tikz, dvipsnames, margin=1mm]{standalone}
\usetikzlibrary{positioning}

\begin{document}
\tikzset{
box/.style={
    rectangle, 
    fill=black!10,
    rounded corners,
    text centered,
    minimum height=3em,
    text width=7em,
    %or minimum width
    draw,},
bigbox/.style={
    box,
    minimum height=5em
},
bigbigbox/.style={
    box,
    minimum height=8em
},
>=stealth
}
\begin{tikzpicture}
    \node[box] (LS) {3D lidar scans};
    \node[box, below=1cm of LS] (IMU) {IMU and odometry};
    \node[bigbox, right=1cm of LS] (DS) {De-skew point cloud};
    \node[bigbigbox, right=1cm of DS, yshift=-1cm] (ICP) {ICP};
    
    \draw[->] (LS) --node[above]{$^{\mathcal{L}}\mathcal{P}_s$} (DS);
    \draw[->] (IMU) -| (DS);
    
    \draw[->] (DS) -- (DS-|ICP.west);
    \draw[->] (IMU) -- (IMU-|ICP.west);
\end{tikzpicture}

\end{document}

drawing

Useful Cheatsheet

You can use this reference sheet that we found on the Internet. It is very useful for basic and more advanced commands.

Clone this wiki locally