[Tex/LaTex] How to Center Titles in Forest Trees

foresttikz-pgf

Here goes my third question. I am actually drawing Game Theory trees using the package Forest, and I have a small issue with the title of some Trees that I cannot manage. Essentially, I order LaTex to put the titles centered, but its behavior is to center them at the top node of the tree. This is fine when the tree is symmetric or almost symmetric, but looks rather strange when the tree is not. Then, I was wondering if there is any way to center the title such that it is in the centre of the entire tree and not centered in the top node. In sum, this is the tree I currently have, and I would like to slightly move the title to the right (if possible).
enter image description here

The code I am using is this one:

\begin{center}
\begin{forest} for tree={l sep=4em, s sep=8em, anchor=center}
[$P_1$, circle, draw,
    [{2, 2}, edge label={node[midway,left]{$D$}}]
    [$P_2$, edge label={node[midway,right]{$A$}}, circle, draw, 
        [{1, 1}, edge label={node[midway,left]{$d$}}] 
        [$P_1$, edge label={node[midway,right]{$a$}}, circle, draw,
            [{0, 0}, edge label={node[midway,left]{$D$}}]
            [{3, 3}, edge label={node[midway,right]{$A$}}]]]]
\node[above=30pt,align=center,anchor=center] {\textbf{Figure IV.} Extensive Form of a Centipede Game Variant};
\end{forest}
\end{center}

PS: If anyone knows how to slightly separate the letters that designate actions (D,A,d,a,D,A) to avoid that they overlap with the branches of the tree, it will be just awesome.

Best Answer

That's because you're setting the caption as a node, which is also not the standard way of doing this. Captions are added to figures in a Latex document externally to the picture, i.e. they are not part of it.

Also, you're manually assigning a number to your figure and this makes the use of Latex a bit pointless, because one of the great advantages of using Latex is that captions are automatically numbered.

You can customize them, but they are automatic, so if you add another figure, they are all automatically fixed, while in your case, you'd have to fix each one manually. And that is not good in a long document.

You can add \renewcommand{\thefigure}{\Roman{figure}} to your preamble to make figure numbering with uppercase Roman numerals, and \usepackage[labelfont=bf]{caption} to make it bold.

Output

enter image description here

Code

\documentclass{article}
\usepackage{forest}
\usepackage[labelfont=bf]{caption}

\renewcommand{\thefigure}{\Roman{figure}}

\begin{document}  
\begin{figure}
\centering
\caption{Extensive Form of a Centipede Game Variant}
\medskip
\begin{forest} for tree={l sep=4em, s sep=8em, anchor=center}
[$P_1$, circle, draw,
    [{2, 2}, edge label={node[midway,left]{$D$}}]
    [$P_2$, edge label={node[midway,right]{$A$}}, circle, draw, 
        [{1, 1}, edge label={node[midway,left]{$d$}}] 
        [$P_1$, edge label={node[midway,right]{$a$}}, circle, draw,
            [{0, 0}, edge label={node[midway,left]{$D$}}]
            [{3, 3}, edge label={node[midway,right]{$A$}}]]]]
\end{forest}
\end{figure}  
\end{document}