Estoy intentando crear unProgramación estructurada de Jacksondiagrama. Este es básicamente un diagrama de árbol simple con la excepción de que los cuadros pueden tener un círculo (O) o una estrella (*) en la esquina superior derecha de cada cuadro. Estoy usando la biblioteca TikZ para el diagrama pero no sé cómo extender los estilos para lograrlo. Aquí está el diagrama inacabado:
\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}
Salida de corriente:
Respuesta1
Puede utilizar label={[xshift=-1.25em, yshift=-2.25ex]north east:$\ast$}
para colocar gráficos adicionales dentro del nodo:
Notas:
- Cambié los colores para que sea más fácil ver dónde están los nodos especiales.
Código:
\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}
Respuesta2
Aquí hay un enfoque diferente, es decir, la path picture
clave y el path picture bounding box
pseudonodo.
Limpié las definiciones de estilo y cambié el nombre especialmente del circle
estilo, porque ya existe una forma circle
que podría generar confusión.
Puse el círculo directamente en la esquina redondeada (por supuesto, puedes ajustar el desplazamiento para moverlo más hacia el centro del nodo).
El starred
estilo acepta un argumento opcional (predeterminado: 5
) que indica el número de esquinas. El radio para las esquinas exteriores es 1mm
, para las esquinas interiores es .5mm
.
Código
\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}