I have three figures that I want to align in a matrix. Each figure is drawn in a different way and needs a caption that is centered below the corresponding figure.
Here is what I currently have:
As you can see, the centering didn't go too well 😉
The code that produces the above result is:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[grow=right]
\matrix[column sep=1cm] {
\node (R1) {X};
\node (P1) [right=45pt of R1] {P};
\draw (R1) to (P1);
&
\node {A} child { node {P} } ;
&
\node {X}
child { node {R} }
child { node {R}
child { node {A} }
child { node {A}
child { node {P} }
child { node {P} }
child { node {P} }
}
child { node {A} }
}
child { node {R} }
;
\\
\node {caption}; & \node {other caption}; & \node {more caption};
\\
};
\end{tikzpicture}
\end{document}
How can I center the captions in a non-hacky way using TikZ?
I managed to get the result I need by adding absolute positioning to the labels, but that is a non-sustainable solution.
Best Answer
A) With three
tikzpicture
environments and withoutmatrix
This way seems to work : three figures are aligned with the option
baseline
and captions are placed inside the code with(current bounding box.base)
B) One
tikzpicture
environment with threescope
environments and amatrix
We get the same result