5

I want to define a style for setting type hierarchies with forest and the types should come out in italics. I read the manual, but ... I found some examples that use the content of a node and do something with it (appending indices and so on). I tried several things, for instance the one in the code below (content=\textit{#1}), but they did not work. So how is this done right?

\documentclass{article}

\usepackage{forest}

\forestset{typehierarchy/.style={for tree={parent anchor=south, child
           anchor=north,align=center,base=top,content=\textit{#1}}}}

\begin{document}

\begin{forest}
typehierarchy
[lexeme
  [active ]
  [passive] ]
\end{forest}


\end{document}
6

You can use font=\itshape or node font=\itshape options, both produce the desired result with your MWE.

enter image description here

Section 17.4.2 Text Parameters: Font in TiKZ documentation explains the difference between these options but I'm not sure about which one should be used within forest. Next code uses font.

\documentclass{article}

\usepackage{forest}

\forestset{typehierarchy/.style={for tree={parent anchor=south, child
           anchor=north,align=center,base=top,font=\itshape}}}

\begin{document}

\begin{forest}
typehierarchy
[lexeme
  [active ]
  [passive] ]
\end{forest}


\end{document}
  • 1
    Forest doesn't know or care about the difference between node font and font: it simply passes their values on to tikz. Note that even when using node font (which was added to tikz in v3, for the reason of adjusting the node size and margins based on the selected font, I presume), forest still calculates the dimensions for separating the nodes based on the em and ex of the outer (surrounding text) font when (as in the default settings) s sep and similar dimensions are given using font-dependent units. – Sašo Živanović Feb 25 '15 at 9:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.