I'm trying to show a menu hierarchy in a diagram with graphical representations of keys using the menukeys
and forest
packages.
I have used the code from the following answer for formatting a forest the way that I would like it: Making a (simple) directory tree
The problem is that the \keys{}
command doesn't work inside the forest.
how can I make it work?
From this code:
\documentclass[12pt, a4paper]{article}
\usepackage[textwidth=16cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{forest}
\usepackage{menukeys}
\begin{document}
\section{Menu structure}
The menu can be navigated with the keyboard, from the main menu you can press \keys{A} to go the menu 2 or \keys{B} to go to menu 3.
\begin{forest}
for tree={
font=\ttfamily,
grow'=0,
child anchor=west,
parent anchor=south,
anchor=west,
calign=first,
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},
}
[Main menu
[ \keys{A} $\rightarrow$ Menu 2
[Foo]
[Bar]
[Baz]
]
[\keys{B} $\rightarrow$ Menu 3
[Quux]
]
]
\end{forest}
\end{document}
Note that the keys are missing from the diagram, just before each \rightarrow
.