I want to place 4 tikz graphs in 4 seperate subfigures. I'm using subcaption and the \subcaptionbox
environment.
However, in the resulting figure the second-row graphs overlap the top-row captions. Moreover, the vertical distance between the graphs and their corresponding captions seems too large. I prefer a solution that does not use some fixed constant variables (like vspace
, even though it produced no effect when I tried it), and I don't really mind using a different subfigure environment than subcaptionbox
.
The code is this:
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{subcaption}
\usetikzlibrary{graphs}
\usetikzlibrary{graphs.standard}
\begin{document}
\begin{figure}
\centering
\subcaptionbox{}[0.45\textwidth][l]{
\begin{tikzpicture}
\tikz \graph [nodes={circle, draw},simple] {subgraph K_n [n=4, clockwise];
1--[edge label=A]2,3--[edge label=B]4,2--[edge label=C]3,1--[edge label'=D]4,1--[edge label=E]3,2--[edge label=F]4; };
\end{tikzpicture}
}
\subcaptionbox{}[0.45\textwidth][l]{
\begin{tikzpicture}
\tikz \graph [nodes={circle, draw},simple] {subgraph K_n [n=4, clockwise];
1--[edge label=A]2,3--[edge label=B]4,2--[edge label=C]3,1--[edge label'=D]4,1-!-3,2-!-4; };
\end{tikzpicture}
}
\subcaptionbox{}[0.45\textwidth][l]{
\begin{tikzpicture}
\tikz \graph [nodes={circle, draw},simple] {subgraph K_n [n=4, clockwise];
1--[edge label=A]2,3--[edge label=B]4,2-!-3,1-!-4,1--[edge label=E]3,2--[edge label=F]4; };
\end{tikzpicture}
}
\subcaptionbox{}[0.45\textwidth][l]{
\begin{tikzpicture}
\tikz \graph [nodes={circle, draw},simple] {subgraph K_n [n=4, clockwise];
1-!-2,3-!-4,2--[edge label=C]3,1--[edge label'=D]4,1--[edge label=E]3,2--[edge label=F]4; };
\end{tikzpicture}
}
\caption{4-Vertex graph, and the 3 possible solutions}
\label{fig:4vertex}
\end{figure}
\end{document}
And the result looks like this:
(Bonus: get the edge labels on the horizontal and vertical edges ('E','F') to be placed such that the edges do not overlap them)
\begin{tikzpicture} \tikz … \end{tikzpicture}
. Don't do this. And drop the[l]
argment. If you addpos=.25
(or any other value) to the--[<options>]
, it will apply to all nodes.