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'm trying to create a Jackson structured programming diagram. This is basically a simple tree diagram with the exception that boxes can either have a circle (O) or a star (*) in the upper right corner of each box. I am using the TikZ libary for the diagram but I don't know how to extend the styles to achieve this. Here is the unfinished diagram:

\documentclass{minimal}
\usepackage[a4paper,margin=1cm,landscape]{geometry}
\usepackage{tikz}
\usetikzlibrary{positioning,shadows,arrows}

\begin{document}
\begin{center}
\begin{tikzpicture}[
    box/.style={rectangle, draw=red!50!black!50, rounded corners=1mm, fill=blue, drop shadow, minimum width=5em, minimum height=3em, level distance=10cm,
        text centered, anchor=north, text=white},
    circle/.style={rectangle, draw=red!50!black!50, rounded corners=1mm, fill=blue, drop shadow, minimum width=5em, minimum height=3em, level distance=10cm,
        text centered, anchor=north, text=white},
    %SHOULD CONTAIN THE CIRCLES
    star/.style={rectangle, draw=red!50!black!50, rounded corners=1mm, fill=blue, drop shadow, minimum width=5em, minimum height=3em, level distance=10cm,
        text centered, anchor=north, text=white},
     %SHOULD CONTAIN THE STARS       
]
\node (State00) [box] {Jackson Diagramm}
 [sibling distance=3cm]
    child {node (a) [box] {int a = 1}}
    child {node (a) [box] {boolean n = true}}
    child {node (a) [box] {boolean z = true}}
    child {[sibling distance=4cm] node (d) [circle] {if (n)}
        child{  [sibling distance=3cm] node (e) [star] {while (z)}
        child {node (f) [box] {n = !z}}
        child {node (g) [box] {a++}}
        child { [sibling distance=4cm] node (h) [circle] {a <= 10}
                child {node (i) [box] {z = true}}
                child {node (j) [box] {System.out.println( "z\(>\)10")}}
            }
        }
        child {node (k) [box] {System.out.println(a)}} 
        child {node (l) [box] {System.out.println(z)}}      
    } 
;
\end{tikzpicture}
\end{center}
\end{document}

Current output:

enter image description here

share|improve this question

2 Answers 2

up vote 10 down vote accepted

You can use label={[xshift=-1.25em, yshift=-2.25ex]north east:$\ast$} to place additional graphics within the node:

enter image description here

Notes:

  • I changed the colors to make it easier to see where the special nodes are.

Code:

\documentclass{minimal}
\usepackage[a4paper,margin=1cm,landscape]{geometry}
\usepackage{tikz}
\usetikzlibrary{positioning,shadows,arrows}

\begin{document}
\begin{center}
\begin{tikzpicture}[
    box/.style={rectangle, draw=red!50!black!50, rounded corners=1mm, fill=blue!25, drop shadow, minimum width=5em, minimum height=3em, level distance=10cm,
        text centered, anchor=north, text=white},
    circle/.style={rectangle, draw=red!50!black!50, rounded corners=1mm, fill=green!25, drop shadow, minimum width=5em, minimum height=3em, level distance=10cm,
        text centered, anchor=north, text=black, label={[xshift=-1.25em, yshift=-2.25ex]north east:$\circ$}},
    %SHOULD CONTAIN THE CIRCLES
    star/.style={rectangle, draw=red!50!black!50, rounded corners=1mm, fill=red!25, drop shadow, minimum width=5em, minimum height=3em, level distance=10cm,
        text centered, anchor=north, text=black, label={[xshift=-1.25em, yshift=-2.25ex]north east:$\ast$}},
     %SHOULD CONTAIN THE STARS       
]
\node (State00) [box] {Jackson Diagramm}
 [sibling distance=3cm]
    child {node (a) [box] {int a = 1}}
    child {node (a) [box] {boolean n = true}}
    child {node (a) [box] {boolean z = true}}
    child {[sibling distance=4cm] node (d) [circle] {if (n)}
        child{  [sibling distance=3cm] node (e) [star] {while (z)}
        child {node (f) [box] {n = !z}}
        child {node (g) [box] {a++}}
        child { [sibling distance=4cm] node (h) [circle] {a <= 10}
                child {node (i) [box] {z = true}}
                child {node (j) [box] {System.out.println( "z\(>\)10")}}
            }
        }
        child {node (k) [box] {System.out.println(a)}} 
        child {node (l) [box] {System.out.println(z)}}      
    } 
;
\end{tikzpicture}
\end{center}
\end{document}
share|improve this answer
    
I guess with this (probably only simple) method the symbols are positioned relative to the center instead of the corner. So if the condition is longer, the symbol appears rather in the middle than in the corner, correct? –  Patrick Apr 6 '13 at 0:47
    
@Patrick: No that is not correct. They are placed relative to the north east of the node so should be in the desired location. Try it and let me know if that does not work. –  Peter Grill Apr 6 '13 at 0:51
    
Ah yes! I set xshift to -1em and it works absolutely perfect! Thanks! –  Patrick Apr 6 '13 at 0:58

Here's a different approach, namely the path picture key and the path picture bounding box pseudo-node.

I cleaned up the style definitions and renamed especially the circle style, because there is already a shape circle which could lead to confusion.

I’ve put the the circle of directly in the rounded corner (you can of course adjust the shifting to move it further to the node’s center).

The starred style accepts one optional argment (default: 5) which denotes the number of corners. The radius for the outer corners is 1mm, for the inner corners it is .5mm.

Code

\documentclass[tikz]{standalone}

\usetikzlibrary{positioning,shadows}

\begin{document}
\begin{tikzpicture}[
  box/.style={
    shape=rectangle,
    draw=red!50!black!50,
    rounded corners=1mm,
    fill=blue,
    drop shadow,
    minimum width=5em,
    minimum height=3em,
    level distance=10cm,
    text centered,
    anchor=north,
    text=white
    },
  circled/.style={
    box,
    path picture={
      \path[draw=red!50!black!50, fill=blue!50] ([shift={(-1mm,-1mm)}]path picture bounding box.north east) circle[radius = 1mm];
    }
  },
  starred/.style={
    box,
    path picture={
       \path[sharp corners,draw=red!50!black!50, fill=blue!50,] ([shift={(-1.5mm,-1.5mm)}]path picture bounding box.north east) + (1/#1*360+90:1mm) \foreach \i in {1,...,#1} {-- + (\i/#1*360+90:1mm) -- + (\i.5/#1*360+90:.5mm)} -- cycle;
    }
  },
  starred/.default=5,% default number of corners
]
\node (State00) [box] {Jackson Diagramm}
 [sibling distance=3cm]
    child {node (a) [box] {int a = 1}}
    child {node (a) [box] {boolean n = true}}
    child {node (a) [box] {boolean z = true}}
    child {[sibling distance=4cm] node (d) [circled] {if (n)}
        child{  [sibling distance=3cm] node (e) [starred] {while (z)}
        child {node (f) [box] {n = !z}}
        child {node (g) [box] {a++}}
        child { [sibling distance=4cm] node (h) [circled] {a <= 10}
                child {node (i) [box] {z = true}}
                child {node (j) [box] {System.out.println( "z\(>\)10")}}
            }
        }
        child {node (k) [box] {System.out.println(a)}} 
        child {node (l) [box] {System.out.println(z)}}      
    } 
;
\end{tikzpicture}
\end{document}

Output

enter image description here

share|improve this answer
    
Nice, I like how customizable this is (though more complex). Stars look great :) –  Patrick Apr 14 '13 at 13:58

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.