I'm trying to use TikZ graphs to draw a simple graph, but I'm having an issue, where if I draw the graph, there will be a lot of whitespace (margin) below it, which creates mess. I visualized the bounding boxes and realized that TikZ draws outside of the box where LaTex expects it to, and I have no idea why.
Here is a MWE on Overleaf and also inline:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{graphs}
\usetikzlibrary{positioning}
\title{Tikz margin}
\begin{document}
\begin{figure}
\fbox{\begin{tikzpicture}
\tikz {
%\tikzset{shift={(0.25,2.25)}}
\node at (0, 0) {X};
\graph {a -> {b, c, d}};
\draw [brown] (current bounding box.south west) rectangle (current bounding box.north east);
}
\end{tikzpicture}}
\caption{Foo}
\end{figure}
\end{document}
I have added fbox to the code to see where is the expected LaTex box, and also added drawing of the TikZ bounding box, which is way off. From the result it's obvious that TikZ simply draws outside of the LaTex box, which is why there is so much "margin" below the graph. I have also visualized a node at (0, 0) to see where the TikZ origin is.
Here is how the result looks like:

Is there a way to make sure that the TikZ box will fit inside the LaTex box automatically? Now I have to use the commented tikzset shift command to move it there manually.