How do they draw this in Latex ?
4 Answers
With tikz-cd
:
\documentclass[10pt]{article}
\usepackage{tikz-cd}
\begin{document}
\begin{tikzcd}[row sep= .7cm, column sep=.5cm]
& 1 \arrow[ld, no head] &\\
2 \arrow[rd, no head] && 4 \arrow[lu, no head] \\
& 3 \arrow[ru, no head] &
\end{tikzcd}
\end{document}
Loops can help avoid repetition and polar coordinates help to make things more symmetric.
\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}
\foreach \X in {1,...,4} {\node (\X) at (\X*90:1) {\X};}
\foreach \X [remember=\X as \LastX (initially 4)] in {1,...,4}
{\draw (\LastX) -- (\X);}
\end{tikzpicture}
\end{document}
Pure tikz?
\documentclass[tikz,border=2pt]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\node (1) {1};
\node (2) [below left=of 1] {2};
\node (3) [below right=of 2] {3};
\node (4) [below right=of 1] {4};
\draw (1)--(2) (1)--(4) (2)--(3) (3)--(4);
\end{tikzpicture}
\end{document}
A shorter version with a \foreach
loop: [PS: similar to @marmot's answer below]
\begin{tikzpicture}
\foreach \i in {1,...,4}
\node (\i) at (90*\i:1cm) {\i};
\draw (1)--(2) (1)--(4) (2)--(3) (3)--(4);
\end{tikzpicture}
A short code with pstricks
and multido
:
\documentclass{article}
\usepackage{pst-node, multido}
\usepackage{auto-pst-pdf}
\begin{document}
\begin{psmatrix}[rowsep=1cm, colsep=1.25cm]
& 1 \\ 2 & & 4 \\ & 3
\end{psmatrix}
\multido{\ir=1+2}{2}{\multido{\ic=1+2}{2}{\ncline[nodesep=4pt, linewidth=0.5pt]{\ir,2}{2,\ic}}}
\end{document}
tikz-cd
should do it very simply.