In the main part of the tikzpicture
I'd like to simply create block
s. So I need somewhere in theirs' style definition to perform tracking of their common bounding rectangle. I've tried to access current bounding box
, but it is obviously set to node's rectangle, thus, unfortunately, duplicating the path picture bounding box
.
I'm going to use this box when creating another type of nodes (say, foo
, which is to be implemented shortly). So, again, it should be accessible from inside foo
's style definition. The goal is to make this calculations invisible from the user (drawer) perspective, though he will be restricted to declare nodes in two consecutive sections.
Is there a way to do this task in a somewhat more comfortable way than writing it with low-level commands, such as ifdim
, etc.? What is preferred way of storing values, when drawing with TikZ? I guess, this is not by using \newcommand
, which defines macros available at global scope. Up to now I've managed to store values using \pgfkeys
but I stuck at getting the main picture's bounding box.
\documentclass[landscape]{article}
\usepackage{tikz}
\usetikzlibrary{scopes,chains,shapes.multipart,backgrounds,positioning,fit,calc}
\newcommand{\setup}{
\tikzset{
node distance=5mm and 3cm,
block/.style={rectangle, %draw, thick,
path picture={
\draw[red, thick] (current bounding box.south west) rectangle (current bounding box.north east);
}
},
%foo/.style={circle},
every edge/.style={->, rounded corners, thick, draw,
to path={
let \p1=(\tikztostart.east),
\p2=($ (\tikztostart.east) + (1cm,0) $),
\p3=(\tikztotarget.west) in
(\p1) -- (\p2) \ifdim\y2=\y3 -- \else |- \fi (\p3)
\tikztonodes
}
}
}
}
\begin{document}
\begin{tikzpicture}
\setup
% First section. This blocks will build up the bounding rectangle, which is to be used in the next section.
\node[block=1] (A) {System A};
\node[block=2] (B) [above right=of A] {System B};
\node[block=3] (C) [right=of A] {System C};
\node[block=4] (D) [below right=of A] {System D};
% Second section. Positioning of this nodes depends on the resulting bounding rectangle of the previous section.
%\node[foo] (o1) {circle 1};
%\node[foo] (o2) {circle 2};
\path
(A) edge (B)
edge (C)
edge (D);
\end{tikzpicture}
\end{document}
\newcommand
, which defines macros available at global scope: No,\newcommand
defines macros in the local scope, not globally. You can also use\def\macroname{...}
to store content.