I am following an answer in How to include caption in \begin{forest}...\end{forest} in LaTex where it shows how to put forest inside figure with caption, under the part where it says

If you want a caption, switch to article and put the tree in a figure.

But when I try it on my code, in TL 2022, the caption is not exactly in the center. It seems to be shifted to the left. Here is a MWE and screen shot


\usepackage{caption}%do I need this?

for tree={
    draw, rounded corners, fill=blue!20,
    minimum height=1.5cm, minimum width=2cm,
    align=center, base=b,
    s sep=1cm, l sep=.5cm,
    if level<=2{edge=-latex}{edge=red},
    [first Order 
        [first order\\degree not One,
           [{\small goto\\figure 2}, circle,draw,fill=yellow!20, minimum width=1cm]
        [first order\\degree one, 
            [{\small goto\\figure 1}, circle,draw,fill=yellow!20, minimum width=1cm]
    [second order, calign=first
    [higher order, fit=band]
\caption{Main flow chart for solving an ode}

Compiled using lualatex gives this

enter image description here

Is the above the correct way to put forest inside figure with frame with caption? How to make caption be centered? I am using \centering.

ps. I used \fbox to put frame around the figure. Not sure if this is the best way or not but it seems to work.

  • 2
    And yuo did notice that your forest figure is wider than the text width? Try adding \rule{\textwidth}{4mm} inside the figure but outside the forest. Caption centers against the width of the text, it does not know the size of what ever there is else in the float.
    – daleif
    Commented Nov 23, 2022 at 8:24

1 Answer 1


As commented by @daleif, you have a warning:

lilla.tex|35 warning| Overfull \hbox (84.20647pt too wide) in paragraph at lines 35--36

...and 84 points is quite a bit. I suggest using \overfullrule=5pt before \begin{document} always when editing a new document, which makes this kind of problem quite evident:

enter image description here

  • 1
    You mean people more likely to look at the pdf output than the log? Shocking! Commented Nov 23, 2022 at 10:49

You must log in to answer this question.

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