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
\documentclass{article}
\usepackage{amsmath}
\usepackage[edges]{forest}
\usepackage{caption}%do I need this?
\begin{document}
\begin{figure}
\centering
\fbox{\begin{forest}
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},
}
[differential\\equation
[first Order
,calign=last
[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
[linear]
[nonlinear]
]
[higher order, fit=band]
]
\end{forest}}
\caption{Main flow chart for solving an ode}
\label{fig:main}
\end{figure}
\end{document}
Compiled using lualatex gives this
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.
\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.