# Horizontal tree arrows not aligned properly

I have taken some code from multiple places and pasted them together in order to show the structure of a folder and its underlying folders. I got it working, however the last arrow (from month to day) of the tree became slightly crooked as I changed to another latex template.

Can anyone tell me why this is happening and how one would go about fixing such a problem?

Code:

\usepackage{forest}
\usetikzlibrary{arrows.meta}

{\small
\begin{figure}[h]
\centering
\begin{forest}
for tree={
grow=0,reversed, % tree direction
parent anchor=east,child anchor=west, % edge anchors
edge={->},outer sep=+1pt, % edge/node connection
rounded corners,minimum width=10mm,minimum height=8mm, % node shape
l sep=5mm % level distance
}
[Root folder
[Customer id
[Machine id
[Year
[Month
[Day]]]]]
]
\end{forest}
\caption{File hierarchy}
\label{fig:filehierarchy}
\end{figure}
}


Result:

• Please post compilable code. – cfr Mar 2 '18 at 1:18

It is likely because only the last node has a descender, i.e. a letter that goes below the baseline (the y). One fix is to add font=\strut to the tree settings:

\documentclass{article}
\usepackage{forest}
\usetikzlibrary{arrows.meta}
\begin{document}

\begin{figure}[h]
\centering\small
\begin{forest}
for tree={
grow=0,reversed, % tree direction
parent anchor=east,child anchor=west, % edge anchors
edge={->},outer sep=+1pt, % edge/node connection
rounded corners,minimum width=10mm,minimum height=8mm,font=\strut, % node shape <-- added font=\strut
l sep=5mm % level distance
}
[Root folder
[Customer id
[Machine id
[Year
[Month
[Day]]]]]
]
\end{forest}
\caption{File hierarchy}
\label{fig:filehierarchy}
\end{figure}
\end{document}

• Works like a charm, what does the font=\strut parameter do exactly? – Milan van Dijck Mar 1 '18 at 10:14
• @MilanvanDijck font is intended for adding font changing commands to a node, e.g. font=\bfseries to make the node bold, but I suppose it inserts the argument at the start of the node text. A \strut is a zero-width box with (a font dependent) height and depth. So inserting a \strut in every node means that all the nodes have equal height and depth (i.e. they go the same distance below the baseline), instead of just the last one having some depth, and the rest zero depth. – Torbjørn T. Mar 1 '18 at 10:24
• the same result you can obtain with rounded corners,minimum width=10mm,minimum height=8mm,text depth=0.25ex, % node shape – Zarko Mar 1 '18 at 11:29
• For this method, I'd be inclined to use delay={content/.wrap value=\strut#1,},, to avoid abusing font. However, I guess if it doesn't do anything untoward, it should hopefully do no harm. font does whatever it does in TikZ. This isn't a Forest key that I know of. If you are not going to use them for alignment, you can make the code more flexible using parent and children rather than west and east. (But I don't think there's a mid children or mid parent, so I can't do this, I don't think :(.) – cfr Mar 2 '18 at 1:27

The simplest solution is probably to change the parent and child anchors to use mid, which TikZ provides for aligning things with variable heights and depths.

\documentclass{standalone}
\usepackage{forest}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{forest}
for tree={
grow'=0, % tree direction
parent anchor=mid east,  % edge anchors
child anchor=mid west,
edge+={->}, % edge/node connection
outer sep=+1pt,
rounded corners, % node shape
minimum width=10mm,
minimum height=8mm,
l sep'=5mm % level distance <= no it isn't - it is the minimum level separation, which is not necessarily the dimension actually used
}
[Root folder
[Customer id
[Machine id
[Year
[Month
[Day]]]]]
]
\end{forest}
\end{document}


This avoids enlarging nodes unnecessarily, which might be undesirable in some cases.