I wish to top align a horizontal folder structure type of tree. However, top aligning does not produce a good result unfortunately.
I have taken some code from a previous post (Making a (simple) directory tree) to generate a folder structure type of tree. It looks perfectly aligned at the bottom as shown here:
When I wish to topalign using either
begin draw/.code={\begin{tikzpicture}[baseline=(current bounding box.north)]}
or top align using \begin{adjustbox}{valign=t} I get:
Full code:
%% Compile and read me!
\documentclass[a4paper,12pt]{article}
\usepackage{forest}
\newcommand{\fff}[1]{%\begin{adjustbox}{valign=t}
\begin{forest}
for tree={
font=\ttfamily,
s sep=.5em,
inner sep=1,
grow'=0,
child anchor=west,
parent anchor=south,
anchor=west,
% node distance=1.2cm,
calign=first,
% align=top,
edge path={
\noexpand\path [draw, \forestoption{edge}]
(!u.south west) +(7.5pt,0) |- node[fill,inner sep=1.25pt] {} (.child anchor)\forestoption{edge label};
},
before typesetting nodes={
if n=1
{insert before={[,phantom]}}
{}
},
fit=band,
before computing xy={l=15pt},
begin draw/.code={\begin{tikzpicture}[baseline=(current bounding box.north)]}
}
#1\end{forest}
}
\begin{document}
\begin{figure}
\centering
% \begin{tabular}{ccc}
% \fff{ [Forward ]}&
% \fff{ [repeat [Forward ] ]}&
% \fff{ [if \textit{PathAhead} [Forward] [TurnLeft] ]}
% \end{tabular}
\fff{ [Forward ]}
\fff{ [repeat [Forward ] ]}
\fff{ [if \textit{PathAhead} [Forward] [TurnLeft] ]
}
\caption{Partial correct programs}
\label{tree:partial-correct}
\end{figure}
\end{document}




edgeslibrary? That's easier, more flexible and less fragile. – cfr Aug 30 '18 at 00:22