# Draw a simple 2 line using Tikz

Can we easily draw a picture like below? Where should I start from?

• To simply answer your question: yes. Honestly, I am very sure that the documentation of TikZ/PGF gives enough information on how to use TikZ to draw such a simple structure. Start with defining three \nodes add labels to them and connect them with \draws … – Jasper Habicht Oct 23 at 16:22

As Jasper is saying, this is very basic. This code may give you a start.

\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}[bullet/.style={fill=cyan,draw,circle,inner sep=2pt},
every label/.style={align=left,font=\small\sffamily}]
\path (0,4) node[bullet,label={[anchor=south west]:{1\\ 12.20}}] (p1){}
(4,4.4) node[bullet,label={[anchor=south west]:{3\\ 12.20}}] (p2){}
(2.5,0) node[bullet,label={[anchor=south west]:{2\\ 9.80}}] (p3){};
\draw[orange,thick] (p1.center) -- (p2.center) -- (p3.center);
\end{tikzpicture}
\end{document}


I would think that the following looks a tiny bit better.

\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}[bullet/.style={fill=cyan,draw,circle,inner sep=2pt},
every label/.style={align=left,font=\small\sffamily}]
\path (0,4) node[bullet,label={[anchor=south]:{1\\ 12.20}}] (p1){}
(4,4.4) node[bullet,label={[anchor=south west]:{3\\ 12.20}}] (p2){}
(2.5,0) node[bullet,label={[anchor=north]:{2\\ 9.80}}] (p3){};
\draw[orange,thick] (p1) -- (p2) -- (p3);
\end{tikzpicture}
\end{document}


If not, it illustrates a bit what the keys are for.

• @aan No, this does not replace a figure environment. You can use \begin{figure}[h!] \centering\begin{tikzpicture} ... \end{tikzpicture}\caption{...}\label{fig:...}\end{figure} but not in the standalone class, which does not support floats. – Schrödinger's cat Oct 23 at 17:03
• how can we draw a border line (like a box) in the original picture? – aan Dec 6 at 1:11
• @aan Add \draw([xshift=-1ex,yshift=-1ex]current bounding box.south west) rectangle ([xshift=1ex,yshift=1ex]current bounding box.north east); just before \end{tikzpicture}. 1ex is the grace distance, which you can adjust to your needs. Or use the show background rectangle, which requires the backgrounds library. – Schrödinger's cat Dec 6 at 1:17
• Thanks. Brillant! – aan Dec 6 at 1:24