2

This defines a command that allows multiple lines within a forest node.

\documentclass{article}
\usepackage{forest}
\usepackage{varwidth}

\newcommand\nbox[1]{\begin{varwidth}{.5\textwidth}#1\end{varwidth}}

\begin{document}

\begin{figure}[h]
  \centering
  \begin{forest}
[parent
  [\nbox{first\\child}]
  [\nbox{second\\child}]
  ]
  \end{forest}
\end{figure}

\end{document}

Is it possible to have this command inserted automatically into all nodes, so it does not have to be repeated? This would be useful where all or almost all nodes have multiple lines.

  • Use ’\forestset{default preamble={...}}’. – Sašo Živanović Oct 12 '18 at 6:13
  • 1
    Combine @SašoŽivanović's comment with marmot's answer if you want this for all trees in the document or use just marmot's answer to apply on a per-tree basis. – cfr Nov 11 '18 at 0:47
1

You really do not need varwidth to have multiline nodes. for tree={align=left} does that already.

\documentclass{article}
\usepackage{forest}

\begin{document}

\begin{figure}[h]
  \centering
  \begin{forest}
  for tree={align=left}
[parent
  [{first\\child}]
  [{second\\child}]
  ]
  \end{forest}
\end{figure}

\end{document}

enter image description here

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.