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. enter image description here. Best regards

  • 7
    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.

enter image description here

  [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
    {\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);

\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);

enter image description here


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{tkz-berge} %graph package
\usepackage[active,tightpage]{preview}  %generates a tightly fitting border around the work




\begin{scope}[shift={(4 cm,-10cm)},rotate=-120]

\begin{scope}[shift={(-4 cm,-10cm)},rotate=60]



and the result:

With TikzBerge

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.