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'd like to position some nodes in TiKZ around a given node. I could do that manually, by setting each node position, but why not looking for an easier way that looks better?

I thought about using a path and stick the nodes to the path but I have no idea about doing this, and I also wonder: is the path the best solution?

An example would be the following where the base node is A (there is a node below it, but it's not a problem; also note that if you don't include the arrows in your answer, it's ok, I know that part):

enter image description here

My code so far has reached this stage (if you think some option in the code could be changed to make things easier or better, please let me know):

\documentclass{minimal}
\usepackage{tikz}
\usepackage{verbatim}


\usetikzlibrary{arrows,positioning} 
\tikzset{
    %Define standard arrow tip
    >=stealth',
    %Define style for boxes
    punkt/.style={
           rectangle,
           rounded corners,
           draw=black, thin,
           text width=6.5em,
           minimum height=2em,
           text centered},
    % Define arrow style
    pil/.style={
           ->,
           thin,
           shorten <=2pt,
           shorten >=2pt,}
}

\begin{document}

    \center\begin{tikzpicture}[node distance=5mm,
    terminal/.style={
    % The shape:
    rectangle,minimum size=6mm,rounded corners=3mm,
    % The rest
    very thick,draw=black!50,
    top color=white,bottom color=black!20,
    font=\ttfamily}]

    \node (nodezero) [terminal] {another node below A};

    \node (a) [terminal, above=3em of nodezero] {A};

    \node (01) [terminal] {1};
    \node (02) [terminal] {2};        
    \node (03) [terminal] {3};
    \node (04) [terminal] {4};
    \node (05) [terminal] {5};
    \node (06) [terminal] {6};
    \node (07) [terminal] {7};
    \node (08) [terminal] {8};
    \node (09) [terminal] {9};

\end{tikzpicture}

\end{document}
share|improve this question
    
There is no \center macro, but a center environment. So either use \begin{center} .. \end{center} or \center .. \endcenter. I would recommend the first, which is the correct LaTeX version. –  Martin Scharrer Apr 30 '12 at 13:26

2 Answers 2

up vote 12 down vote accepted

You may want to use the trees library in tikz, which in this situation would provide, up to me, a rather easy syntax. I made a small example for you.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{positioning,trees,arrows}


\begin{document}

\begin{tikzpicture}[->,>=stealth',shorten <=0.5pt,
    main/.style={draw,thick,rounded corners, top color=blue!20, bottom color=white,
        minimum width=1cm},
    child/.style={draw,thick,rounded corners, top color=red!20, bottom color=white}]

    \tikzstyle{level 1}=[sibling angle=22.5]

    \node[main] (a) {A} [counterclockwise from=0]
        child { node[child] {1}}
        child { node[child] {2}}
        child { node[child] {3}}
        child { node[child] {4}}
        child { node[child] {5}}
        child { node[child] {6}}
        child { node[child] {7}}
        child { node[child] {8}}
        child { node[child] {9}}
    ;

    \node[main] (ba) [below of=a] {belowA};

    \path 
    (ba) edge (a)
    ;

\end{tikzpicture}

\end{document}

Which gives as result:

enter image description here

share|improve this answer
    
Nice! Where is the manual for this? –  Alenanno Apr 30 '12 at 15:17
    
You can find the pgf and tikz manual here: ftp.math.purdue.edu/mirrors/ctan.org/graphics/pgf/base/doc/… but I suggest you to take a look at this site texample.net/tikz which provides a lot of sound and complete examples. –  Edo Apr 30 '12 at 15:21
    
Of course it's that! I kind of forgot it lol Thanks... :) I'm currently tweaking with it. –  Alenanno Apr 30 '12 at 15:24
1  
I try to use \foreach \i in {1,...,9} {child { node[child] {\i}}} but without success. Does anyone know why? –  Alain Matthes Apr 30 '12 at 17:06

One way you can use here is the \node (<name>) at (<coordinate>) {<text>}; syntax, where you can use the calc library to add a polar coordinate on the position of node A, i.e. \node (1) at ($ (A) + (<angle>:<distance>) $) {1};. For another ways see the positioning library in the manual.

\documentclass{standalone}
\usepackage{tikz}

\usetikzlibrary{arrows,positioning}
\usetikzlibrary{calc}
\tikzset{
    %Define standard arrow tip
    >=stealth',
    %Define style for boxes
    punkt/.style={
           rectangle,
           rounded corners,
           draw=black, thin,
           text width=6.5em,
           minimum height=2em,
           text centered},
    % Define arrow style
    pil/.style={
           ->,
           thin,
           shorten <=2pt,
           shorten >=2pt,}
}

\begin{document}

    \begin{tikzpicture}[node distance=5mm,
    terminal/.style={
    % The shape:
    rectangle,minimum size=6mm,rounded corners=3mm,
    % The rest
    very thick,draw=black!50,
    top color=white,bottom color=black!20,
    font=\ttfamily}]

    \node (nodezero) [terminal] {another node below A};

    \node (a) [terminal, above=3em of nodezero] {A};

    \node (01) at ($ (a) + (10:2cm) $) [terminal] {1};
    \node (02) at ($ (a) + (30:2cm) $) [terminal] {2};        
    \node (03) at ($ (a) + (50:2cm) $) [terminal] {3};
    \node (04) at ($ (a) + (70:2cm) $) [terminal] {4};
    \node (05) at ($ (a) + (90:2cm) $) [terminal] {5};
    \node (06) at ($ (a) + (110:2cm) $) [terminal] {6};
    \node (07) at ($ (a) + (130:2cm) $) [terminal] {7};
    \node (08) at ($ (a) + (150:2cm) $) [terminal] {8};
    \node (09) at ($ (a) + (170:2cm) $) [terminal] {9};

\end{tikzpicture}

\end{document}

Result

share|improve this answer
3  
You can avoid the calc library and simplify the code with \begin{scope}[shift=(a)] \foreach \i in {1,...,9} \node (0\i) at ({(\i-1)*20+10}:2cm) [terminal] {\i}; \end{scope} –  Alain Matthes Apr 30 '12 at 14:02
    
@Altermundus: Indeed! Very good idea. –  Martin Scharrer Apr 30 '12 at 14:33
    
Or \path[every node/.style={terminal}] (a) foreach \i in {1,...,9} node (0\i) at +({\i-1)*20+10}:2cm) {\i}; (might have the foreach syntax incorrect). –  Loop Space Apr 30 '12 at 15:00
    
Martin, thanks for your help, I accepted the other answer, but upvoted yours for the help. :) –  Alenanno Apr 30 '12 at 16:44

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.