I just started using TikZ and try to get a process control drawn by TikZ. It looks wonderful, but I am a real beginner. I use the simple flow chart as base and came to this result:
I use shapes (blue nodes) and lines together with "fit" to draw the dashed container around "Resources" and "Sensors" (complete code below). I am not satisfied with this for four reasons:
- I'd like to place the left box in between of the two middle ones (see red rectangle)
- Drawing an arrow from "Processing" to "Planning" is drawn right in the middle through "Sensors" and "Resources". Also, the arrow pointing to the dashed container should just be inside the container, not pointing to the egde
- I'd like to label the dashed container (see small rectangle just below "Planning")
- See the code, but the spacing of the rectangle is now done with a minimum height and width, because without it, the fit is too tight. However, it's not a real scalable solution, so I need to adjust the width/height every time I want to fit a rectangle around several nodes
This is my source code:
\tikzstyle{b} = [rectangle, draw, fill=blue!20, node distance=3cm, text width=6em, text centered, rounded corners, minimum height=4em, thick]
\tikzstyle{c} = [rectangle, draw, minimum height=15em, minimum width=10em, dashed]
\tikzstyle{l} = [draw, -latex',thick]
\begin{tikzpicture}[auto]
\node [b] (planning) {Planning};
\node [b, below of=planning] (resources) {Resources};
\node [b, below of=resources] (sensors) {Sensors};
\node [b, left of=resources, node distance=4cm] (information) {Information system};
\node [b, below of=sensors] (processing) {Processing};
\node[c,fit=(resources) (sensors)] (container) {};
\path [l] (planning) -- (resources);
\path [l] (resources) -- (sensors);
\path [l] (sensors) -- (processing);
\path [l] (information) |- (planning);
\path [l] (information) |- (processing);
\end{tikzpicture}
Can someone point me in the right direction to solve my problems?
Best Answer
There's a good chance some more elegant solution will appear soon, but here goes:
By using the
calc
library you can add node halfway betweensensors
andresources
, and positioninformation
with relation to this. I actually used the corners of these,resources.south west
andsensors.north west
, and put the new node midway between these.One way is to use relative coordinates to first go a little right of
processing
, then up, left toplanning
. By using|-
/-|
you can access coordinates that lie on the intersection of the horizontal line from one node and vertical line from another. That way you can end the arrow directly abovesensors.north east
, for example.I first add a new node,
lowerright
while drawing the line fromresources
toplanning
.(lowerright |- container.east)
is the point that lies on the vertical line fromlowerright
and the horizontal line fromcontainer.east
. Similar for(container.east -| resources.south east)
.You can add a node above the top left corner of
container
.Add
inner sep=<dimension>
to the container node, instead of defining width and height. This sets the distance from the contents of the node to the edge of the node.