How do they draw this in Latex ?
Asked
Active
Viewed 187 times
-1
4 Answers
5
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}
AboAmmar
- 46,352
- 4
- 58
- 127
5
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}
Sebastiano
- 54,118
5
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}
5
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}
Bernard
- 271,350





tikz-cdshould do it very simply. – Bernard Mar 02 '19 at 17:19