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}
Update.
Improved version:
\tikzmark
is used to set marks at the beginning and end of the text that will be boxed. The main command is
\BoxedText[<options>]{<start-mark>}{<end-mark>}
The optional argument can be used to pass options to the \draw
command used internally (by default, just a frame is drawn, but you can fill it, or change the line width, or apply any other desired valid modification):
\documentclass{article}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc}
\makeatletter
\tikzset{%
remember picture with id/.style={%
remember picture,
overlay,
save picture id=#1,
},
save picture id/.code={%
\edef\pgf@temp{#1}%
\immediate\write\pgfutil@auxout{%
\noexpand\savepointas{\pgf@temp}{\pgfpictureid}}%
},
if picture id/.code args={#1#2#3}{%
\@ifundefined{save@pt@#1}{%
\pgfkeysalso{#3}%
}{
\pgfkeysalso{#2}%
}
}
}
\def\savepointas#1#2{%
\expandafter\gdef\csname save@pt@#1\endcsname{#2}%
}
\def\tmk@labeldef#1,#2\@nil{%
\def\tmk@label{#1}%
\def\tmk@def{#2}%
}
\tikzdeclarecoordinatesystem{pic}{%
\pgfutil@in@,{#1}%
\ifpgfutil@in@%
\tmk@labeldef#1\@nil
\else
\tmk@labeldef#1,(0pt,0pt)\@nil
\fi
\@ifundefined{save@pt@\tmk@label}{%
\tikz@scan@one@point\pgfutil@firstofone\tmk@def
}{%
\pgfsys@getposition{\csname save@pt@\tmk@label\endcsname}\save@orig@pic%
\pgfsys@getposition{\pgfpictureid}\save@this@pic%
\pgf@process{\pgfpointorigin\save@this@pic}%
\pgf@xa=\pgf@x
\pgf@ya=\pgf@y
\pgf@process{\pgfpointorigin\save@orig@pic}%
\advance\pgf@x by -\pgf@xa
\advance\pgf@y by -\pgf@ya
}%
}
\newcommand\tikzmark[2][]{%
\tikz[remember picture with id=#2] #1;}
\makeatother
\newcommand\BoxedText[3][]{%
\begin{tikzpicture}[remember picture,overlay]
\draw[#1]
let \p1=(pic cs:#2), \p2=(pic cs:#3) in
([yshift=-0.8ex]\p1) --
([yshift=2ex]\p1) --
([xshift=3pt,yshift=2ex]\p1-|current page text area.east) --
([xshift=3pt,yshift=2ex]\p2-|current page text area.east) --
([yshift=2ex]\p2) --
([yshift=-0.8ex]\p2) --
([xshift=-3pt,yshift=-0.8ex]\p2-|current page text area.west) --
([xshift=-3pt,yshift=-0.8ex]\p1-|current page text area.west) --
cycle
;
\end{tikzpicture}%
}
\begin{document}
\BoxedText{start1}{end1}
\BoxedText[draw=orange!70!black,right color=orange!10,left color=orange!50]{start2}{end2}
\BoxedText[draw=cyan!70!black,fill=cyan!30,ultra thick]{start3}{end3}
Some text goes here.\tikzmark{start1} Some text goes here. Some text goes here. Some text goes here. Some text goes here. Some text goes here. Some text goes here. Some text goes here. Some text goes here. Some text goes here. Some text goes here.\tikzmark{end1} Some text goes here. Some text goes here. Some text goes here. Some text goes here. Some text goes here. Some text goes here.
Some text goes here. Some text goes here. Some text goes here. Some text goes here.Some text goes here.\tikzmark{start3} Some text goes here. Some text goes here. Some text goes here. Some text goes here. Some text Some text goes here.\tikzmark{end3}
Some text goes here. Some text goes here. Some text goes here. Some text goes here. Some text goes here.Some text goes here. Some text goes here. Some text goes here. Some text goes here.Some text goes here.\tikzmark{start2} Some text goes here. Some text goes here. Some text goes here. Some text goes here. Some text goes here. Some text goes here. Some text goes here. Some text goes here. Some text goes here. Some text goes here. Some text goes here. Some text goes here. Some text goes here. Some text goes here. Some text goes here. Some text goes here.\tikzmark{end2} Some text goes here. Some text goes here. Some text goes here. Some text goes here. Some text goes here. Some text goes here. Some text goes here.
\end{document}
The code must be run three times.
Best Answer
You can also use the
\frame
macro instead which draws a tight frame around it. For special content inside nodes, e.g. verbatim, I recommend the\Frame
macro from my recentrealboxes
package.