I need to draw an "easy" flowchart. I would do that, using the child statement. I've used (as example) an example found here. I've modified it and this is the code:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{trees}
\usepackage[active,tightpage]{preview}% just for showing image
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%
%-------definisce stile dei nodi---------------
\tikzstyle{startstop} = [rectangle, rounded corners, minimum width=5cm, minimum height=1cm,text centered, draw=black, fill=red!50]
\tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30]
\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, text width=3cm, draw=black, fill=orange!30]
\tikzstyle{decision} = [diamond, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=green!30]
\tikzstyle{arrow} = [thick,->,>=stealth]
%--------------------------------------
\begin{document}
\begin{tikzpicture}[
thick,
every node/.style = {
text width = 5em,
top color = blue!60,
bottom color = blue!60,
rectangle,
font = \sffamily,
text=white
},
sibling distance = 7em,
edge from parent fork down
]
\node[text width=10em] (T0) {test0}
child {node (T1) {test1}
%child {node[ellipse,draw] (right node) {right}};
child {node[diamond, red] (T4) {test4}
child {node (T5) {test5}}
}}
child {node (T2) {test2}}
;
\end{tikzpicture}
\end{document}
But the "diamond" icon doesn't work. I've also tried to insert the "decision" style that I've created
\tikzstyle{decision} = [diamond, minimum width=3cm, minimum
height=1cm, text centered, draw=black, fill=green!30]
and neither this nor "diamond" works.
How can I draw a "diamond" (because I need to draw a decision Icon)?
Best Answer
As Claudio Fiandrino said, you need to load the
shapes
(orshapes.geometric
)tikzlibrary
, too, in order to makediamond
work.When I tried your code, the setting
every node./style={...}
gave some problems, because it was overriding thedecision
style (and all the other styles):Since you have defined a style for each node, I'd suggest you to use them:
This is the code:
EDIT: some more suggestions, thanks to Claudio Fiandrino's comment:
In order to show only the image the
standalone
class is better, and you won't need this code:but only
\documentclass{standalone}
.Usually it's better to use
\tikset{...}
than\tikzstyle{...}
to define the style of a node. For more information, you can read the answer linked by Claudio Fiandrino (Should \tikzset or \tikzstyle be used to define TikZ styles?).The new improved code, that produces the same output, is the following:
EDIT 2: After some trial and error, I obtained this result:
I defined three diffent styles for the
edge
between thediamond
and itschild
s:You can set the type of edge you want giving it as a
child
option:Moreover, I changed the distance between the diamond and the subsequent nodes with:
The complete code is: