5

I am using the forest package to draw a simple tree. When using forest with the Springer-Nature template, forest must be specified via a \RequirePackage callout before calling \documentclass. This unfortunately changes the tree structure. I provide an MWE (at the end) where the issue is replicated with the article documentclass for simplicity.

Expected Output:

Observe that the fork points are separated from the parent node

Expected Output

Alternate Output

When the command \RequirePackage[edges]{forest} is uncommented in the MWE, I get an alternate tree where the fork point is connected to the parent (see below).

Collapsed Fork Point Format

Question: How can I fix the \RequirePackage of forest so the second image appears like the first? Recall I can't delete the \RequirePackage since the Springer-Nature documentclass requires it.

Base MWE with article for Simplicity

% \RequirePackage[edges]{forest}

\documentclass{article}

\usepackage[edges]{forest}


\begin{document}
    \scriptsize
    \begin{forest}
      for tree={
        draw=black!75,
        line width=1pt,
        if level=0{%
          forked edges,
          l sep+=0.35cm,
          s sep+=0.5in,
          align=center,
        }{%
          if level=1{%
            l sep+=0.35cm,
            s sep+=0.5in,
          }{
          },
        },%
      },
      [Node~A
        [Node~B
        ]
        [Node~C
           [Node~D
           ]
           [Node~E
           ]
        ]
     ]
    \end{forest}

\end{document}

2 Answers 2

6

The sn-jnl class loads the package program that conflicts with forest or edges. From CTAN:

its main offering is a program environment; a programbox environment is available for snippets that should not break pages.

If you don't need such a programbox environment, you can avoid loading the program package.

Using

\makeatletter%
\disable@package@load{program}{}
\makeatother

prevents the program package from being loaded.

% !TeX TS-program = pdflatex

\makeatletter% added <<<<<<<<<<<<<<<<
\disable@package@load{program}{}
\makeatother

\documentclass[pdflatex,sn-mathphys]{sn-jnl}

\usepackage[edges]{forest} % added <<<<<<<<<<<<<<,

\begin{document}        
        \scriptsize
        \begin{forest}
            for tree={
                draw=black!75,
                line width=1pt,
                if level=0{%
                    forked edges,
                    l sep+=0.35cm,
                    s sep+=0.5in,
                }{%
                    if level=1{%
                        l sep+=0.35cm,
                        s sep+=0.5in,
                    }{
                    },
                },%
            },
            [Node~A
            [Node~B
            ]
            [Node~C
            [Node~D
            ]
            [Node~E
            ]
            ]
            ]
        \end{forest}
    
\end{document}

b

Another option is to use David Carlisle's answer

% !TeX TS-program = pdflatex

\documentclass[pdflatex,sn-mathphys]{sn-jnl}

\catcode`\|=12\relax % added <<<<<<<<<<

\usepackage[edges]{forest} % added <<<<<<<<<<<<<<,

\begin{document}        
        \scriptsize
        \begin{forest}
            for tree={
                draw=black!75,
                line width=1pt,
                if level=0{%
                    forked edges,
                    l sep+=0.35cm,
                    s sep+=0.5in,
                }{%
                    if level=1{%
                        l sep+=0.35cm,
                        s sep+=0.5in,
                    }{
                    },
                },%
            },
            [Node~A
            [Node~B
            ]
            [Node~C
            [Node~D
            ]
            [Node~E
            ]
            ]
            ]
        \end{forest}
    
\end{document}
4

This seems to work, don't ask me why.

\RequirePackage{forest}
\documentclass{article}
\useforestlibrary{edges}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .