Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I need your help in creating the following figure in tikz. I am absolute beginner in tikz. enter image description here

I saw the example in the following page, but I need it the way as shown in the picture which I could not produce TikZ: Using Loop to Draw Grid of Nodes

share|improve this question
3  
Try \node [circle,draw,inner sep=1pt] {$\downarrow$};. –  Peter Grill Apr 16 '13 at 17:54
    
Do you want to know how to put arrows inside circles in TikZ or how do create that figure? –  Qrrbrbirlbel Apr 16 '13 at 18:01
    
I am finding it difficult to draw the complete picture, so it would be nice if you can tell me how to create the complete figure. I came to know about tikz just yesterday and the learning curve seems a bit higher. Thanks. –  cosmicraga Apr 16 '13 at 19:00
add comment

1 Answer

up vote 4 down vote accepted

Perhaps this code can help you. It's not possible to apply the code from your link because we don't know if the position of the arrows are automatic or not. A large part needs to be draw by manually. The next code is not very elegant but you can try to do something better. A fine idea is to determine the coordinates of all the nodes before drawing the grid with a loop like in the link without define nodes (only coordinates.

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[
    down/.style={path picture={
     \draw[->]  ([yshift=-3pt]path picture bounding box.north)  
             -- ([yshift=3pt]path picture bounding box.south);}},
    up/.style={path picture={
      \draw[->]  ([yshift=3pt]path picture bounding box.south)  
              -- ([yshift=-3pt]path picture bounding box.north);}},
    every node/.style={circle,draw, minimum size=1 cm}]

    \node[label=45:$1$,up]   (n-1-1)          {};
    \node[label=45:$2$,down] (n-1-2) at (2,0) {};
    \node[label=45:$3$,up]   (n-1-3) at (4,0) {};
    \node[label=45:$n$,up]   (n-1-4) at (6,0) {};

    \node[label=45:$n+1$,down] (n-2-1)  at (0,-2) {};
    \node[label=45:$n+2$,up]   (n-2-2)  at (2,-2) {};
    \node[label=45:$n+3$,down] (n-2-3)  at (4,-2) {};
    \node[label=45:$n+4$,up]   (n-2-4)  at (6,-2) {};

    \node[up]   (n-3-1)  at (0,-4)  {};
    \node[up]   (n-3-2)  at (2,-4)  {};
    \node[down] (n-3-3)  at (4,-4)  {};
    \node[down] (n-3-4)  at (6,-4)  {};

    \node[up]   (n-4-1)  at (0,-6) {};
    \node[down] (n-4-2)  at (2,-6) {};
    \node[up]   (n-4-3)  at (4,-6) {};
    \node[down] (n-4-4)  at (6,-6) {};  

    \foreach \i [count=\xi from 2] in {1,...,2}
        \foreach \j [count=\xj from 2] in {1,...,3}
           \draw (n-\i-\j) -- (n-\xi-\j);

     \foreach \j [count=\xj from 2] in {1,...,4}
           \draw[thick,dotted] (n-3-\j) -- (n-4-\j);


    \foreach \i [count=\xi from 2] in {1,...,3}
        \foreach \j [count=\xj from 2] in {1,...,2}
             \draw (n-\i-\j) -- (n-\i-\xj);

   \foreach \i [count=\xi from 2] in {1,...,4}
            \draw[thick,dotted]  (n-\i-3) -- (n-\i-4);

\draw (n-4-1) -- (n-4-2) (n-4-2)--(n-4-3) ;
\draw (n-1-4) -- (n-2-4) (n-2-4)--(n-3-4) ;
\foreach \i in {1,...,4} {%
     \draw (n-\i-4)--++(1.5,0) ;
     \draw (n-4-\i)--++(0,-1.5) ;
     }
\end{tikzpicture}

\end{document}

enter image description here

To do something perhaps better. I removed a large part of the code. Your problem now is to draw the vertices and the arrows inside the circles. I wrote all the labels to help you if you want to designe some nodes

\documentclass{minimal}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[darkstyle/.style={circle,draw,minimum size=10mm}]
  \foreach \x in {0,...,4}
    \foreach \y in {0,...,4} 
       {%\pgfmathtruncatemacro{\label}{\x - 5 *  \y +21}
       \node [darkstyle,label=45:$n-\x-\y)$]  (n-\x-\y) at (2*\x,2*\y) {};} 

  % \foreach \x in {0,...,4}
  %   \foreach \y [count=\yi] in {0,...,3}  
  %     \draw (n-\x-\y)--(n-\x-\yi) (n-\y-\x)--(n-\yi-\x) ;

\end{tikzpicture}
\end{document}  

enter image description here

share|improve this answer
    
Thank you very much. Can you explain the for loop that you have used so that I can try to add the horizontal lines at the last row? –  cosmicraga Apr 17 '13 at 1:06
    
I think it's more easy to add the last row by hand without a loop. The problem is that the picture is not symmetric some lines are dotted etc. Perhaps a better way is to determine the coordinates of the nodes with a loop, then to draw the nodes and the edges. Have ou an algorithm to place the arrows ? –  Alain Matthes Apr 17 '13 at 5:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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