# How to draw a graph in LATEX?

I need your help. I try to draw a graph in Tikz but i do not know how to do that. It seems to be like that. . Best regards

• Welcome to TeX.SX! On this site, a question should typically revolve around an abstract issue (e.g. "How do I get a double horizontal line in a table?") rather than a concrete application (e.g. "How do I make this table?"). Questions that look like "Please do this complicated thing for me" tend to get closed because they are either "off topic", "too broad", or "unclear". Please try to make your question clear and simple by giving a minimal working example (MWE): you'll stand a greater chance of getting help. – Stefan Pinnow Jan 29 '17 at 16:59
• I just want to Know how to start with it. How to use \foreach, \useasboundingbox , \begin{scope}[rotate=?] \foreach \x/\y in {?/?,?/?,?/?}{ \node[vertex_style] (\y) at (canvas polar cs: radius=..cm,angle=\x){}; } – Rosalie Jan 29 '17 at 17:31
• @Rosalie - follow and exercise TikZ tutorials - the first chapter of TikZ manual. – forrest Jan 29 '17 at 18:29

The code illustrates the use of polar coordinates which make it easy to construct symmetrical graphs.

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}%
[vertex/.style={circle,draw,fill=black,minimum width=1.5mm,inner sep=0mm}]
\newcommand\coce{0.5}% distance of triangle corners from triangle center
\newcommand\cece{1.8}% distance of triangle centers from each other
% \tri{name}{coords of triangle center}{rotation angle} draws a triangle
\newcommand\tri[3]%
{\node[vertex] (#11) at ($(#2)+({#3-150}:\coce)$) {}; % vertex 1
\node[vertex] (#12) at ($(#2)+({#3- 30}:\coce)$) {}; % vertex 2
\node[vertex] (#13) at ($(#2)+({#3+ 90}:\coce)$) {}; % vertex 3
\draw (#11) -- (#12) -- (#13) -- (#11);
}
% Draw graph
\tri{C}{  0:  0  }{  0} % center triangle
\tri{T}{ 90:\cece}{180} % top triangle
\tri{L}{210:\cece}{300} % left triangle
\tri{R}{330:\cece}{ 60} % right triangle
\draw (T2) -- (L1) (L2) -- (R1) (R2) -- (T1)
(C1) -- (L3) (C2) -- (R3) (C3) -- (T3);
% Draw Hamiltonian cycle
\draw[very thick]
(T3) -- (T1) -- (T2) --
(L1) -- (L3) -- (L2) --
(R1) -- (R2) -- (R3) --
(C2) -- (C1) -- (C3) -- (T3);
\end{tikzpicture}
\end{document}

\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
\foreach \x/\y/\z in {0/0/-1,4/0/-1,2/4/-1,2/1/1}
{
\draw[ultra thick] (\x,\y) -- (\x+1,\y) -- (\x+0.5,\y+\z)--cycle;
\draw[fill] (\x,\y) circle(1.5mm);
\draw[fill] (\x+1,\y) circle(1.5mm);
\draw[fill] (\x+0.5,\y+\z) circle(1.5mm);
}
\draw[ultra thick] (0,0)--(2,4) (3,4)--(5,0) (4.5,-1)--(0.5,-1) (2.5,2)--(2.5,3) (1,0)--(2,1) (3,1)--(4,0);
\end{tikzpicture}
\end{document}


For this kind of graph, I would use the beautiful tikz-berge package. The learning curve is made easy with the documentation from: altermundus.

I give a sample code for this graph but it can be "beautified" at will with all the available options.

\usepackage{tikz}
\usepackage{tkz-berge} %graph package
\usepackage[active,tightpage]{preview}  %generates a tightly fitting border around the work
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{4mm}

\begin{document}
\begin{tikzpicture}[scale=.7]
\SetVertexMath

\begin{scope}[rotate=30]
\grComplete[RA=1.5,prefix=a]{3}
\end{scope}

\begin{scope}[shift={(0cm,-6cm)},rotate=-30]
\grComplete[RA=1.5,prefix=d]{3}
\end{scope}

\begin{scope}[shift={(4 cm,-10cm)},rotate=-120]
\grComplete[RA=1.5,prefix=c]{3}
\end{scope}

\begin{scope}[shift={(-4 cm,-10cm)},rotate=60]
\grComplete[RA=1.5,prefix=b]{3}
\end{scope}

\EdgeFromOneToSel{a}{d}{2}{1}
\EdgeFromOneToSel{a}{c}{0}{1}
\EdgeFromOneToSel{a}{b}{1}{1}
\EdgeFromOneToSel{d}{b}{2}{0}
\EdgeFromOneToSel{c}{b}{0}{2}
\EdgeFromOneToSel{c}{d}{2}{0}

\end{tikzpicture}
\end{document}


and the result: