I have created a diagram in TikZ. This is my first brush with TikZ and though I have almost completed it, I have some questions. Before asking questions, I will post my full tex file here, as a minimal version is not sufficient for explaining the question.
\documentclass{article}
\usepackage{pgfpages}
\pgfpagesuselayout{2 on 1}[a4paper,landscape, border shrink=5mm]
\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes}
\usepackage[latin1]{inputenc}
\usepackage{verbatim}
\begin{document}
\tikzstyle{pre}=[<-,shorten <=1pt,>=stealth',semithick, draw=blue!75]
\tikzstyle{post}=[->,shorten >=1pt,>=stealth',semithick, draw=blue!75]
\tikzstyle{routed}=[to path={-- ++(0,8mm) |- (\tikztotarget)},shorten >=1pt,>=stealth',semithick, draw=blue!75]
\tikzstyle{place}=[circle,thick,draw=blue!75,fill=blue!20,minimum size=6mm]
\tikzstyle{node_box}=[rectangle,thick,draw=blue!75, fill=blue!10,minimum width=25mm, minimum height=5mm]
\begin{tikzpicture}[node distance=3.7cm,>=stealth',bend angle=45,auto]
\begin{scope}
\node at (15,0) [node_box] (south_if) {south\_if};
\node[node_box] (south_r) [above left of=south_if, node distance=80mm] {south\_r}
edge [pre] node[sloped,near start] {input} node[sloped,near end,swap] {output} (south_if);
\node[node_box] (box_a) [above of=south_r] {box\_a}
edge [pre] node[sloped,above,near start] {input} node[sloped,below,near end,swap] {output} (south_r);
\node[node_box] (nout_join) [above of=box_a] {nout\_join}
edge [pre] node[sloped,above,near start] {input} node[sloped,below,near end,swap] {output} (box_a);
\node[node_box] (sout_join) [above right of=south_if, node distance=80mm] {sout\_join}
edge [post] node[sloped,near start] {output} node[sloped,below,near end,swap] {input} (south_if);
\node[node_box] (box_b) [above of=sout_join] {box\_b}
edge [post] node[sloped,above,near start] {output} node[sloped,below,near end,swap] {input} (sout_join);
\node[node_box] (north_r) [above of=box_b] {north\_r}
edge [post] node[sloped,above,near start] {output} node[sloped,below,near end,swap] {input} (box_b);
\node[node_box] (north_if) [above left of=north_r, node distance=80mm] {north\_if}
edge [post] node[sloped,near start] {output} node[sloped,near end,swap] {input} (north_r)
edge [pre] node[sloped,sloped,near start] {input} node[sloped,sloped,near end,swap] {output} (nout_join);
%% Can this be placed next to box_a automatically with out specifying node distance?
\node[node_box] (box_c) [sloped,above of=south_if, node distance=95mm] {box\_c};
\node[node_box] (t_rdr) [below of=box_c] {t\_rdr}
edge [pre] node[sloped,above,near start] {input} node[sloped,below,near end,swap] {output} (box_c)
edge [post] node[sloped,very near start] {output\_n,n\_src} node[sloped,very near end, swap] {output, n\_src} (nout_join)
edge [post] node[sloped,very near start] {output\_s,s\_src} node[sloped,very near end, swap] {output, s\_src} (sout_join);
\node[node_box] (t_output) [above of=box_c] {t\_output}
edge [post] node[sloped,above,near start] {output} node[sloped,below,near end,swap] {input} (box_c)
edge [pre] node[sloped,at start,anchor= south west] {n\_test\_in, test\_out} node[sloped,near end,swap] {test\_out, n\_test\_in} (north_r)
edge [pre] node[sloped,very near start,anchor= south east] {n\_test\_in, test\_out} node[sloped,very near end,anchor= north west] {test\_out, n\_test\_in} (south_r);
\node[node_box] (south_rp) [below of=t_rdr, node distance=30mm] {south\_rp}
edge [pre] node[near start] {input} node[near end,swap] {out} (t_rdr);
%% Can this node be better placed?
\node[node_box] (test_prov) [above right of=t_rdr, node distance=30mm] {test\_prov}
edge [pre] node[sloped,near start] {input} node[sloped,near end,swap] {prov\_out} (t_rdr)
edge [post] node[sloped,near start] {output} node[sloped,near end,swap] {test\_prov} (t_output);
\node[node_box] (sink_prov) [right of=test_prov, node distance=60mm] {sink}
edge [pre] node[near start] {fromtest} node[near end,swap] {output1} (test_prov);
\node[node_box] (sink_test_a) [left of=box_a, node distance=60mm] {sink}
edge [pre] node[near start] {test\_a} node[near end,swap] {output4} (box_a);
\node[node_box] (sink_test_p) [right of=box_b, node distance=60mm] {sink}
edge [pre] node[near start] {test\_p} node[near end,swap] {output4} (box_b);
\end{scope}
\end{tikzpicture}
\end{document}
The output image is:
Now to questions:
node
box_cis placed by specifyingabove of=south_if, node distance=95mmwhich approximates the horizontal position ofbox_a. Is there any way to remove thenode distanceand let thebox_csnap tosouth_ifandbox_aautomatically?Can I change the lines between
south_randt_outputandt_rdrandnout_jointo horizontal and vertical i.e. using-|or|-? I made some attempt at doing it, as it can be seen in\tikzstyle{routed}, but could not figure it out.I am not very happy with the positioning of
test_provnode. This is not exactly a question, but suggestions are welcome :)Any improvements to the code? This is my first TikZ code, and I did it by mostly working from the example in manual. Ideally I would like to remove hard coded formatting and numbers from the main drawing into definitions at the top so that the code is more clean and maintainable.
I would like to print this in an a4 sheet. Not quite figured out how to fit this graph in an a4 sheet.
Thanks for your time and help :)


node[...] at (node1-|node2) {};If you could arrange your nodes on an regular distribution could try with amatrixto avoid manually positioning them. To fit inside an a4 sheet, one possible option could be to usestandaloneclass and include the result as a figure. – Ignasi Oct 16 '17 at 08:35