5

I am trying to draw a tree diagram with forest package. In order to have the diagram fitting within the page margins, I moved down the subtree of NastranBulkData object, as you can see from the image. However, there is still quite a big white space left between NastranCaseControl object and NastranBulkData object that prevents the diagram from fitting into the page margins.

enter image description here

How can I remove such white space so that both NastranBulkData object and NastranSubcaseResult object are shifted left? Ideally they should be shifted in such a way that the space between Objects related to other Nastran case control entries and the line departing from NastranBulkData object is equal to the separation between children in the tree (but I do not care too much about this).

MWE:

% Class
\documentclass[10pt]{article}

% Set paper geometry
\usepackage[letterpaper,margin=1in]{geometry}

% Forest package
\usepackage[edges]{forest}

% Document
\begin{document}
    \begin{figure}[hbt!]
        \centering
        \begin{forest}
            for tree={              % style of tree nodes
                draw, semithick, rounded corners,
                align = center,
                inner sep = 2mm,
                anchor=north,
                %                     styles of tree
                forked edge,             
                l sep = 6mm,    
                fork sep = 3mm,     
            }
            [\texttt{NastranAnalysis}\\object
            [\texttt{NastranExecutiveControl}\\object
            [Solution\\sequence \#]
            ]
            [\texttt{NastranCaseControl}\\object
            [\texttt{NastranSubcase}\\object array]
            [Objects related to\\other \textsc{Nastran}\\case control entries]
            ]
            [\texttt{NastranBulkData}\\object
            [\texttt{Grid}\\object array, fork sep=3cm, l*=5, name=grid]
            [Objects related to other \\\textsc{Nastran} bulk data cards, fork sep=3cm, l*=5]
            [\texttt{NastranPart}\\object array, fork sep=3cm, l*=5
            [\texttt{NastranPart}\\object 1]
            [\texttt{NastranPart}\\object 2]
            [\dots]
            ]
            ]
            [\texttt{NastranSubcaseResult}\\object array]
            ]
        \end{forest}
    \end{figure}
\end{document}

2 Answers 2

4

Try the following:

\documentclass[10pt]{article}
% Set paper geometry
\usepackage[letterpaper,margin=1in]{geometry}
% Forest package
\usepackage[edges]{forest}

% Document
\begin{document}
    \begin{figure}[hbt!]
        \centering
        \begin{forest}
            for tree={              % style of tree nodes
                draw, semithick, rounded corners,
                font=\small,        % <--- 
                align = center,
                inner sep = 2mm,
                anchor=north,
                %                     styles of tree
                forked edge,
                s sep = 2mm,
                l sep = 6mm,
                fork sep = 3mm,
            }
[\texttt{NastranAnalysis}\\object
    [\texttt{NastranExecutiveControl}\\object
        [Solution\\sequence \#]
    ]
    [\texttt{NastranCaseControl}\\object
        [\texttt{NastranSubcase}\\object array]
        [Objects related to\\other \textsc{Nastran}\\case control entries]
    ]
    [\texttt{NastranBulkData}\\object
        [, l*=4,coordinate
            [\texttt{Grid}\\object array]
            [Objects related to other \\\textsc{Nastran} bulk data cards]
            [\texttt{NastranPart}\\object array,
                [\texttt{NastranPart}\\object 1]
                [\texttt{NastranPart}\\object 2]
                [\dots]
            ]
        ]
    ]
    [\texttt{NastranSubcaseResult}\\object array]
]
        \end{forest}
    \end{figure}
\end{document}

In code is added additional level with node as coordinate. Also is reduced font size to \small. One option is also to reduce inner sep to 1mm and use normal font size.

enter image description here

(red lines indicate text area borders)

4
  • Grid object array is at the same level of Objects related to other Nastran bulk data cards. Apart from this, your solution works perfectly adding l*=4 after coordinate.
    – fma
    Commented Sep 13, 2019 at 18:52
  • huh, I insert `coordinate on the wrong level :-(. Corrected now.
    – Zarko
    Commented Sep 13, 2019 at 19:22
  • This does not seem to reproduce the OP's tree. For instance, in your tree, the Grid node has two children while in the OP's version it has none.
    – user194703
    Commented Sep 13, 2019 at 21:16
  • @Schrödinger'scat, you are right. Corrected.
    – Zarko
    Commented Sep 14, 2019 at 5:15
2

A reliable way of shifting nodes in a forest is to use the before computing xy key. (I also added calign child=2 to avoid the kink.)

\documentclass[10pt]{article}

% Set paper geometry
\usepackage[letterpaper,margin=1in,showframe]{geometry}

% Forest package
\usepackage[edges]{forest}

% Document
\begin{document}
    \begin{figure}[hbt!]
        \centering
        \begin{forest}
            for tree={              % style of tree nodes
                draw, semithick, rounded corners,
                align = center,
                inner sep = 2mm,
                anchor=north,
                %                     styles of tree
                forked edge,             
                l sep = 6mm,    
                fork sep = 3mm,s sep=0.35em
            }
            [\texttt{NastranAnalysis}\\object
            [\texttt{NastranExecutiveControl}\\object
            [Solution\\sequence \#]
            ]
            [\texttt{NastranCaseControl}\\object
            [\texttt{NastranSubcase}\\object array]
            [Objects related to\\other \textsc{Nastran}\\case control entries]
            ]
            [\texttt{NastranBulkData}\\object,before computing
            xy={s+=-9em},calign child=2     
            [\texttt{Grid}\\object array, fork sep=3cm, l*=5, name=grid]
            [Objects related to other \\\textsc{Nastran} bulk data cards, fork sep=3cm, l*=5]
            [\texttt{NastranPart}\\object array, fork sep=3cm, l*=5
            [\texttt{NastranPart}\\object 1]
            [\texttt{NastranPart}\\object 2]
            [\dots]
            ]
            ]
            [\texttt{NastranSubcaseResult}\\object array,
            before computing xy={s+=-9em}]
            ]
        \end{forest}
    \end{figure}
\end{document}

enter image description here

The showframe option is used to show that the resulting tree really fits on the page, of course you want to drop it in your document.

You must log in to answer this question.

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