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}
![enter image description here](https://i.stack.imgur.com/SWssd.png)
I now am using the following workaround (i call it that way because it causes circumstances).
- ever algorithm has its own tex file but without any preamble and without includes etc.
- this way I cannot compile these files directly but need another tex using \input and all neccessary includes to compile this file
- this is cumbersome because I always need to change the tex for compiling when just changed a little on the pseudo-code
this way my code-tex is looking like this:
\begin{algorithm}
...
\end{algorithm
these "wrapper-tex" is looking like this:
\documentclass[12pt, letterpaper]{article}
\usepackage[utf8]{inputenc}
\usepackage{import}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage[linesnumbered,ruled]{algorithm2e}
\begin{document}
\import{Algo}{MyAlgo.tex}
\end{document}
For not getting the line pitch of the surrounding document I use \renewcommand before unsing input on the code and after it again to setting it back.
When the code does not fit into the line latex display text, which actually occurs after the input, before the code itself (on the previous page if theres enough space left for text but not for code). I got it by adding a \newpage after the input of the code.
Using include does not show my pseudo code at all.
My include that way looks like:
\begin{flushleft}
some text
...
again some text
\renewcommand{\baselinestretch}{1.0}
\input{Algo/MyAlog.tex}
\renewcommand{\baselinestretch}{1.5}
\newpage
againagainsometext
...
u know
\end{flushleft}
...
I had also problems because in the tex with my texts I defined 12pt fontsize while I didn at first on my code-wrapper.
The pseudocode that way was enlarged after inputting it. Resizing it using recommendations of these
Reduce pseudocode font size (not global)
or othere did not help very much, I surrendered after over an hour trying so I reduced my pseudocode by dividing it into multiple/ separate algorithms and by deleting code commentary.
Best Answer
The right margin is left open in case you want to number your algorithm lines on the right (using
\setRightLinesNumbers
). However, the most common setting (or default) is to have the numbers on the left (\setLeftLinesNumbers
) with the margin on the right left open. To remove this gap on the right hand side of the algorithm, you need to patch the initial settings when starting the algorithm, all of which is handled by\algocf@start
:Line numbers on the right are placed within a
1.5em
margin that is removed from the available algorithm space specifically for that reason. The above patch replaces this reduction with0pt
.