# Tikz : Graphs : Shift the sublayers/levels horizontally and vertically in a tree layout?

This differs slightly from directory listing as at TeXample and Drawing a directory listing a la the tree command in TikZ in that I'd like to annotate the final structure showing links between the files. I need some means of referring back to the nodes in the tree and the following seems to be my options

1. Use a tabbing environment, to layout the tree structure leveraging tikzmark to annotate the nodes.
2. Use either the graphs or the trees libraries within a tikzpicture environment.
3. Use the dirtree and forest packages in some combination with the previous setups (1 or 2).

Method 1 gave me the desired output but the annotations got all muddled if the tree extended across more then one page, using multicols and minipage did not improve this. I am currently considering method 2 and if that fails will try 3.

My hope was that the sublayers in the following tree, drawn using TikZ graphdrawings' tree layout,

could be nested between their parents, as in the second layout using the TikZ library trees library and Loop Space's dirtree key,

My assumption, probably in error, was that the graph drawing library would allow one to manipulate the subgraphs into the preferred position. However the interface for the graphs and graphdrawing seems to be rather segregated unlike the other TikZ libraries. The examples I've encountered are as follows

• The tries key gets some of the layout correct but breaks if using subgraphs.
• Setting grow down sep gives the correct structure but I can't see how to tweak it further and it's ignored for subgraph layouts.
• Using tree layout allows subgraphs but not much control over their placement.

The code below produces the first image. Within it I specify a nudge value for the first sublayer which offsets the next sublayer as expected but not its' node, the floating rectangle in the upper right. Trying to provide phantom values also fails as seen by the errant arrows in the lowest layer.

\documentclass[tikz]{standalone}%
\usepackage{tikz}%
%
\usepackage{luatex85}%
\usetikzlibrary{graphs}%
\usetikzlibrary{graphdrawing}%
\usegdlibrary{trees}%
\usegdlibrary{layered}%
\usegdlibrary{circular}%
%
\makeatletter
\newcount\dirtree@lvl
\newcount\dirtree@plvl
\newcount\dirtree@clvl
\def\dirtree@growth{%
\ifnum\tikznumberofcurrentchild=1\relax
\expandafter\xdef\csname dirtree@p@\the\dirtree@plvl\endcsname{\the\dirtree@lvl}
\fi
\dirtree@clvl=\dirtree@lvl
\pgf@xa=\tikzleveldistance
\pgf@ya=-\tikzsiblingdistance
\pgf@ya=\dirtree@clvl\pgf@ya
\pgftransformshift{\pgfqpoint{\the\pgf@xa}{\the\pgf@ya}}%
\ifnum\tikznumberofcurrentchild=\tikznumberofchildren
\fi
}
%
\tikzset{
dirtree/.style={
growth function=\dirtree@growth,
level distance =1.2em,
sibling distance =1.2em,
growth parent anchor=west,
%     every node/.style={anchor=west},
%     every parent node/.style={anchor=south west},
every child node/.style={anchor=west},
edge from parent path={(\tikzparentnode.south west) ++(0.5*\tikzleveldistance,0) |- (\tikzchildnode\tikzchildanchor)}
}
}
\makeatother
%
%
\begin{document}%
\normalsize%
\begin{tikzpicture}%
\graph [tree layout, grow'=right]
{"00"/"\winpath{E:\CheatSheets\Algorithms}" ->
{"01"/"\winpath{Genetic}";
"02"/"\winpath{Linear_Programming}" ->
{"03"/"\winpath{build}";
"04"/"\winfile{Affine_Scaling.pseudo.tex}"};
"05"/"\winpath{build}";
"06"/"\winfile{Algorithms.tex}";
"07"/"\winfile{Genetic.tex}";
"08"/"\winfile{input.tex}";
"09"/"\winfile{input2.tex}";
"10"/"\winfile{input3.tex}"}};%
\end{tikzpicture}%
\begin{tikzpicture}%
\node (00) {\winpath{E:\CheatSheets\Algorithms}}[dirtree]
child {node (01) {\winpath{Genetic}}}
child {node (02) {\winpath{Linear_Programming}}
child {node (03) {\winpath{build}}}
child {node (04) {\winfile{Affine_Scaling.pseudo.tex}}}}
child {node (05) {\winpath{build}}}
child {node (06) {\winfile{Algorithms.tex}}}
child {node (07) {\winfile{Genetic.tex}}}
child {node (08) {\winfile{input.tex}}}
child {node (09) {\winfile{input2.tex}}}
child {node (10) {\winfile{input3.tex}}} ;%
\graph [use existing nodes]
{06      ->[in=0, out=0, looseness=3] {04     }};%
\end{tikzpicture}%
\end{document}


I would also like to use the |- line specification but can't seem to set that within the /tikz/graphs/edges key. My understanding is that the edges are drawn with to[...] commands versus the --/|-/-| commands. Effectively I would like to "down grade" the drawing mechanism from to[...] to |-. Fork down edge style with Tikz 3.0 tree graph asks a similar question. The topath library, section 70 in version 3.0.1a of the pgfmanual, allows one to use a straight line as in to[line] but makes no mention for elbows.

At present I'm trying both the trees and graph together, the former doing the layout and the latter the annotations.

I think the main question really is "how to control the placement of subgraphs beyond nudging them about". Is this actually possible reading the manual leads one to believe so but I couldn't find a nice example on how to do so and I went through the layered layout, tree layout and graphdrawing sections quite thoroughly I felt.

• Can you explain in more detail what you want to achieve? I have difficulties in understanding what you mean by having the children between the parents and what you want to shift. Anyway, I think in this case it is best to start with a drawing (maybe by hand) of what you are aiming at. After that you can still mention what you have tried so far, but I'm not sure that the best way is to modify what you already have. – gernot May 1 '17 at 14:15
• @gernot I went through the entire question again and made it more rational. Perhaps now it's a tad verbose ? – Carel May 1 '17 at 17:44
• Thanks for clarifying, I think that I now understand what you want. Except maybe one thing: At one point you write about page breaks, and at another about linking files. How do you imagine that links across page breaks are displayed? – gernot May 1 '17 at 23:05
• Originally I had encountered the page break issue when I was using large tabbed environments. The standalone class does not accomodate tabbing environments and one is forced to set crop=false which falls to the article class. This exlcudes a monolithic tabbed page. By switching to a tikzpicture I can have a monolithic graph or tikzpicture. Negating the need to deal with page breaks until another time. I noticed that the TikZmark documentation mentions some functionality for page breaks but I have not fully explored it. – Carel May 2 '17 at 0:07
• @gernot I have managed to get most of what I wanted by using both the trees library, an update to Loop Spaces' code, and the graphs library. I've updated the original code accordingly contrasting what I get with what I want. Now it's more of an interest to know whether or not it's possible to manipulate the tree layout but I'd make it a low priority question :) If you want to see my script eventually let me know, my intention is to include it with Pythons' PyLaTeX package though. – Carel May 2 '17 at 0:22