I don't really get the question so I hope this is what you wanted. If you include a full document (such that we copy paste and see the problem on our systems) things are much more easier.
Here, you can change the default setting within a scope but your block
style had a node distance
which was resetting every time it is issued. I've made it 2mm such that we can see the difference easier.
\documentclass[tikz]{standalone}
\usetikzlibrary{arrows,shapes.geometric,positioning}
\begin{document}
\begin{tikzpicture}[decision/.style={diamond, draw, text width=4.5em, text badly centered, node distance=3.5cm, inner sep=0pt},
block/.style ={rectangle, draw, text width=6em, text centered, rounded corners, minimum height=4em, minimum height=2em},
cloud/.style ={draw, ellipse, minimum height=2em},
line/.style ={draw,-latex'},
node distance = 1cm,
auto]
\node [block] (1st) {1st};
\node [block, right= of 1st] (2nd1) {2nd1};
\begin{scope}[node distance=2mm and 10mm]%Here we change it for everything inside this scope
\node [block, above= of 2nd1] (2nd2) {2nd2};
\node [block, below= of 2nd1] (2nd3) {2nd3};
\node [block, right= of 2nd1] (3rd1) {3rd1};
\node [block, above= of 3rd1] (3rd2) {3rd2};
\node [block, above= of 3rd2] (3rd3) {3rd3};
\end{scope}
\node [block, below= of 3rd1] (3rd4) {3rd4};
\node [block, below= of 3rd4] (3rd5) {3rd5};
\path [line] (1st) -- (2nd1);
\path [line] (2nd1) -- (2nd2);
\path [line] (2nd1) -- (2nd3);
\path [line] (2nd2) -- (3rd3);
\path [line] (2nd1) -- (3rd1);
\path [line] (1st) -- (2nd1);
\end{tikzpicture}
\end{document}
I am definitely unfamiliar with both beamer
and tikz
(do not quite get what the \only
are supposed to do) but perhaps this could go in the direction you want:
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{chains}
\newcounter{count}
% helper macro:
\long\def\GobToSemiColon #1;{}
\newcommand\myPicture{
\begin{tikzpicture}
\begin{scope}[start chain = going below]
\ifnum\value{count}<1 \expandafter\GobToSemiColon\fi
\ifnum\value{count}>3 \expandafter\GobToSemiColon\fi
\node[draw, rectangle, on chain] {display only when counter is between
1 and 3};
\ifnum\value{count}>-1 \expandafter\GobToSemiColon\fi
\node[draw, rectangle, on chain] {display only when counter is
negative};
\ifnum\value{count}<100 \expandafter\GobToSemiColon\fi
\ifnum\value{count}>200 \expandafter\GobToSemiColon\fi
\node[draw, rectangle, on chain] {display only if counter is between
100 and 200};
\ifnum\value{count}<3 \expandafter\GobToSemiColon\fi
\ifnum\value{count}>20 \expandafter\GobToSemiColon\fi
\node[draw, circle, on chain] {only when counter is in the range 3 to 20};
\end{scope}
\end{tikzpicture}
}
\begin{document}
\begin{frame}
\only{\setcounter{count}{-3}\myPicture}
\only{\setcounter{count}{105}\myPicture}
\only{\setcounter{count}{39}\myPicture}
\only{\setcounter{count}{2}\myPicture}
\only{\setcounter{count}{5}\myPicture}
\end{frame}
\end{document}
Best Answer
Both solutions, either with
fit
or withcalc
, have their disadvantages. Thefit
solution needs fixing withinner ysep
and more importantlyouter ysep
while thecalc
solution needs extra fiddling outside the actual node (with the\path let … in
).Let’s combine them. The
fit
key basically scans all coordinates/nodes it has been given. If it encounters a node the node’s anchorswest
,east
,north
andsouth
are scanned separately. If not, the given point is just that: a one-dimensional coordinate. At the end four dimensions are set to the height and lowest x and y value. We simply have a rectangle in the canvas plane.We can use these four dimensions
path picture bounding box
, afit bounding box
will be created locally. This makes it perfect to use it with the already well-definedposition
keys likeleft
andright
.This answer introduces four keys and one enhancement of the keys of
positioning
library (only withof
, of course).The keys are:
fit bounding box
: creates a rectangular node calledfit bounding box
around the given nodes. Syntax like thefit
key. This node is defined locally. If you want to use it in following paths use it inside a\tikzset
.span vertical
andspan horizontal
: they issueminimum height
orminimum width
respectively on the given nodes (same syntax likefit
).span
:span vertical
andspan horizontal
(without scanning the coordinates/nodes twice)The enhancement of the
positioning
keys work similar:If the part after
of
starts with an open parenthesis(
it acts as a switch between the usual behavior (just placement) and fitting around one or more nodes. That means, the placement is relatively to a rectangular box around all given nodes.If the part after
of
starts with a|
, a-
or a+
then the created node is also fitted vertically (|
), horizontally-
or vertically and horizontally+
to the given node(s) (if its only one node you can omit the parentheses( )
as inTake a look at all given examples and also change the shape of every node to see how it affects different node shapes.
A previous solution I had in mind was actually dependent on the fact that all nodes you want to span have the same horizontal extent and you had to exactly give the most upper and the most lower node (the latter could have easily resolved but the
fit
library already handles this excellently). It also used something similar likeright=of <upper node>.north east, anchor=north west
but TikZ-ified with thenorth right
or thecorner north right
(for circles) key from mypositioning-plus
library which might be helpful in some cases nonetheless.The actual
fit
key usestext width
,text height
andtext depth
to set the dimensions of the new node (which also creates the problem that the new node can’t be thinner than the fitted node). Of course, now theinner sep
s are still active and theminimum height
is only that, minimum (meaning that if you write more in it than it can take it will stretch where as the originalfit
key wasn’t really suited for putting text in the created node anyway).Code
Output