Unobedient diagrams and a way to resume caption enumeration

The code at the bottom of this question yields this image. Zooming this image at a relevant place shows the following.

As you can see the last three diagrams are broken (in (vi) and (vii) 2 is lower than what I want it to be and (viii) was supposed to be the vertices of a cube). I've tried creating the diagrams by explicit coordinates, but it results in the same thing, it won't work.

Another problem with this is that this is part of a larger document and the diagrams get moved to a different page due to, I assume, lack of space. I suppose this happens because the diagrams are all within \begin{figure} \end{figure}, but I need them to be so in order to get the appropriate caption.

How can I solve both these problems?

\documentclass{article}
\usepackage{tikz}
\usepackage{subcaption}
\renewcommand\thesubfigure{\roman{subfigure})}
\DeclareCaptionLabelFormat{paren}{(#2}
\captionsetup[subfigure]{labelformat=paren}
\usetikzlibrary{positioning}
\tikzset{mynode/.style={draw,circle,inner sep=2pt,outer sep=0pt}}

\begin{document}
\begin{figure}[htb]
\centering
\subcaptionbox{}{%
\begin{tikzpicture}

\node [mynode,label=above:30] (30) at (0,0) {};
\node [mynode,below left  = of 30,label=left:2] (2)  {};
\node [mynode,below right = of 30,label=right:5] (5) {};
\node [mynode, below = of 30, label=right:3] (3) {};
\node [mynode,below  = of 3,label=below:1] (1) {};

\draw (30) -- (2)
(30) -- (5)
(30) -- (3)
(2) -- (1)
(3) -- (1)
(5) -- (1);

\end{tikzpicture}
}
\hfil
\subcaptionbox{}{%
\begin{tikzpicture}

\node [mynode,label=above:12] (12) at (0,0) {};
\node [mynode,below left  = of 12,label=left:4] (4)  {};
\node [mynode,below right = of 30,label=right:3] (3) {};
\node [mynode,below left  = of 4,label=left:2] (2)  {};
\node [below = of 12] (a) {};
\node[below = of a] (b) {};
\node[mynode, below of = b, label=right:1] (1) {};

\draw (12) -- (4)
(12) -- (3)
(4) -- (2)
(2) -- (1)
(3) -- (1);

\end{tikzpicture}
}

\subcaptionbox{}{
\begin{tikzpicture}

\node [mynode,label=above:10] (10) at (0,0) {};
\node [mynode,below left  = of 10,label=left:2] (2)  {};
\node [mynode,below right = of 10,label=right:5] (5) {};
\node [mynode,below right  = of 2,label=below:1] (1)  {};

\draw (10) -- (2)
(10) -- (5)
(5) -- (1)
(2) -- (1);
\end{tikzpicture}
}
\hfil
\subcaptionbox{}{
\begin{tikzpicture}
\node [mynode,label=right:16] (16) at (0,0) {};
\node [mynode, below of = 16, label=right:8] (8) {};
\node [mynode, below of = 8, label=right:4](4) {};
\node [mynode, below of = 4, label=right:2] (2){};
\node [mynode, below of =2, label=right:1](1){};

\draw (16) -- (8)
(8) -- (4)
(4) -- (2)
(2) -- (1);
\end{tikzpicture}
}

\subcaptionbox{}{
\begin{tikzpicture}
\node [mynode,label=right:18] (18) at (0,0) {};
\node [mynode, left of = 18, label=left:12] (12) {};
\node [mynode, below of = 18, label=right:3](3) {};
\node [mynode, below of = 12, label=left:2] (2){};

\draw (18) -- (2)
(18) -- (3)
(12) -- (2)
(12) -- (3);
\end{tikzpicture}
}
\hfil
\subcaptionbox{}{
\begin{tikzpicture}

\node [mynode,label=above:12] (12) at (0,0) {};
\node [mynode,below left  = of 12,label=left:4] (4)  {};
\node [below of = 12] (a) {};
\node [mynode,below right = of 12,label=right:6] (6) {};
\node [mynode,below = of 4,label=left:2] (2)  {};
\node [below of = a] (b) {};
\node [mynode, below of = 6, label=right:3] (3) {};
\node [mynode, below of = b, label=below:1](1) {};

\draw ;
\end{tikzpicture}
}

\subcaptionbox{}{
\begin{tikzpicture}

\node [mynode,label=above:12] (12) at (0,0) {};
\node [mynode,below left  = of 12,label=left:4] (4)  {};
\node [below of = 12] (a) {};
\node [mynode,below right = of 12,label=right:6] (6) {};
\node [mynode,below = of 4,label=left:2] (2)  {};
\node [below of = a] (b) {};
\node [mynode, below of = 6, label=right:3] (3) {};
\node [mynode, below of = b, label=below:1](1) {};

\draw ;
\end{tikzpicture}
}
\hfil
\subcaptionbox{}{
\begin{tikzpicture}

\node [mynode,label=above:30] (30) at (0,0) {};
\node [mynode,below left  = of 30,label=left:6] (6)  {};
\node [mynode, below = of 30, label=right:10] (10) {};
\node [mynode,below right = of 30,label=right:15] (15) {};
\node [mynode,below = of 6,label=left:2] (2)  {};
\node [mynode, below = of 10, label=right:3] (5) {};
\node[mynode, below = of 15, label=right:5] (5) {};
\node[mynode, below of = 3, label=below:1] (1) {};

\draw ;
\end{tikzpicture}
}
\end{figure}
\end{document}

• I apologize if the code is too large. Please do adjust the question accordingly or tell me what to do to make it better. I can't exactly say what I should post, so I opted for posting all that I felt was remotely relevant. – Git Gud Mar 18 '15 at 1:11
• What do you mean by broken. Can you elaborate? There is continuedfloat from caption package to continue the same float in the next page. – user11232 Mar 18 '15 at 1:13
• @HarishKumar I've clarified what I meant with broken. – Git Gud Mar 18 '15 at 1:22

You should not mix up the below = of (without positioning library) and below = of (with positioning library). It is always better to use positioning library and its below/above/right/left = of syntax (i.e. of should come after =). For details, refer to pgfmanual (17.5.3, page 230) at search window of texdoc.net or run texdoc pgfmanual in your terminal.

Further, if your figure contains many subfigures that can not be accomodated in a single page, you can load caption package and use its \ContinuedFloat macro. You have to place the caption with (cont.) manually for all figures that go to the next page as I have done in the following code.

\documentclass{article}
\usepackage{lipsum,showframe}
\usepackage{tikz}
\usepackage{caption}
\usepackage{subcaption}
\renewcommand\thesubfigure{\roman{subfigure})}
\DeclareCaptionLabelFormat{paren}{(#2}
\captionsetup[subfigure]{labelformat=paren}
\usetikzlibrary{positioning}
\tikzset{mynode/.style={draw,circle,inner sep=2pt,outer sep=0pt}}

\begin{document}
\lipsum[1-3]
\begin{figure}[htb]
\centering
\subcaptionbox{}[0.48\linewidth][c]{%
\begin{tikzpicture}
\node [mynode,label=above:30] (30) at (0,0) {};
\node [mynode,below left  = of 30,label=left:2] (2)  {};
\node [mynode,below right = of 30,label=right:5] (5) {};
\node [mynode, below = of 30, label=right:3] (3) {};
\node [mynode,below  = of 3,label=below:1] (1) {};

\draw (30) -- (2)
(30) -- (5)
(30) -- (3)
(2) -- (1)
(3) -- (1)
(5) -- (1);

\end{tikzpicture}
}
\hfill
\subcaptionbox{}[0.48\linewidth][c]{%
\begin{tikzpicture}

\node [mynode,label=above:12] (12) at (0,0) {};
\node [mynode,below left  = of 12,label=left:4] (4)  {};
\node [mynode,below right = of 30,label=right:3] (3) {};
\node [mynode,below left  = of 4,label=left:2] (2)  {};
\node [below = of 12] (a) {};
\node[below = of a] (b) {};
\node[mynode, below of = b, label=right:1] (1) {};

\draw (12) -- (4)
(12) -- (3)
(4) -- (2)
(2) -- (1)
(3) -- (1);

\end{tikzpicture}
}
\caption{Some figure}
\end{figure}
\begin{figure}\ContinuedFloat
\subcaptionbox{}[0.48\linewidth][c]{
\begin{tikzpicture}

\node [mynode,label=above:10] (10) at (0,0) {};
\node [mynode,below left  = of 10,label=left:2] (2)  {};
\node [mynode,below right = of 10,label=right:5] (5) {};
\node [mynode,below right  = of 2,label=below:1] (1)  {};

\draw (10) -- (2)
(10) -- (5)
(5) -- (1)
(2) -- (1);
\end{tikzpicture}
}
\hfill
\subcaptionbox{}[0.48\linewidth][c]{
\begin{tikzpicture}
\node [mynode,label=right:16] (16) at (0,0) {};
\node [mynode, below = of 16, label=right:8] (8) {};
\node [mynode, below = of 8, label=right:4](4) {};
\node [mynode, below = of 4, label=right:2] (2){};
\node [mynode, below = of 2, label=right:1](1){};

\draw (16) -- (8)
(8) -- (4)
(4) -- (2)
(2) -- (1);
\end{tikzpicture}
}
%\caption{Some figure (cont.)}
\end{figure}
\begin{figure}\ContinuedFloat
\subcaptionbox{}[0.48\linewidth][c]{
\begin{tikzpicture}
\node [mynode,label=right:18] (18) at (0,0) {};
\node [mynode, left = of 18, label=left:12] (12) {};
\node [mynode, below = of 18, label=right:3](3) {};
\node [mynode, below = of 12, label=left:2] (2){};

\draw (18) -- (2)
(18) -- (3)
(12) -- (2)
(12) -- (3);
\end{tikzpicture}
}
\hfill
\subcaptionbox{}[0.48\linewidth][c]{
\begin{tikzpicture}

\node [mynode,label=above:12] (12) at (0,0) {};
\node [mynode,below left  = of 12,label=left:4] (4)  {};
\node [below of = 12] (a) {};
\node [mynode,below right = of 12,label=right:6] (6) {};
\node [mynode,below = of 4,label=left:2] (2)  {};
\node [below = of a] (b) {};
\node [mynode, below = of 6, label=right:3] (3) {};
\node [mynode, below = of b, label=below:1](1) {};

\end{tikzpicture}
}
%\caption{Some figure (cont.)}
\end{figure}
\begin{figure}\ContinuedFloat
\subcaptionbox{}[0.48\linewidth][c]{
\begin{tikzpicture}

\node [mynode,label=above:12] (12) at (0,0) {};
\node [mynode,below left  = of 12,label=left:4] (4)  {};
\node [below = of 12] (a) {};
\node [mynode,below right = of 12,label=right:6] (6) {};
\node [mynode,below = of 4,label=left:2] (2)  {};
\node [below = of a] (b) {};
\node [mynode, below = of 6, label=right:3] (3) {};
\node [mynode, below = of b, label=below:1](1) {};

\end{tikzpicture}
}
\hfill
\subcaptionbox{}[0.48\linewidth][c]{
\begin{tikzpicture}

\node [mynode,label=above:30] (30) at (0,0) {};
\node [mynode,below left  = of 30,label=left:6] (6)  {};
\node [mynode, below = of 30, label=right:10] (10) {};
\node [mynode,below right = of 30,label=right:15] (15) {};
\node [mynode,below = of 6,label=left:2] (2)  {};
\node [mynode, below = of 10, label=right:3] (3) {};
\node[mynode, below = of 15, label=right:5] (5) {};
\node[mynode, below = of 3, label=below:1] (1) {};
\end{tikzpicture}
}
\caption{Some figure (cont.)}
\end{figure}
\lipsum[4-6]
\end{document}


All roman caption numbers can be vertically aligned by fixing the width of subcaptionbox. Note the [c] in the options of subcaptionbox is for inner pos which is the default (still I added for reference).

• Thanks. As I read your answer I googled 'Latex lipsum' to try to understand what it, then I immediately saw it's just that text in latin, ahaha. I managed to work it out. But there's one small detail I'd like to see fixed. Is it possible to have the roman numeral captions vertically aligned too? – Git Gud Mar 18 '15 at 12:07
• @GitGud Happy to help. You are welcome :-) – user11232 Mar 18 '15 at 14:57

below of=3 will give you a different result than below =of 3. You are mixing an older syntax and the newer one supported by the positioning library. I suggest sticking to the newer one, as that's recommended.

I tried to correct your figure but I'm not sure what it is supposed to look like.

For the last but one diagram, for example, using

  \begin{tikzpicture}

\node [mynode, label=above:12] (12) at (0,0) {};
\node [mynode, below left=of 12, label=left:4] (4)  {};
\node [below=of 12] (a) {};
\node [mynode, below right=of 12, label=right:6] (6) {};
\node [mynode, below=of 4, label=left:2] (2)  {};
\node [below=of a] (b) {};
\node [mynode, below=of 6, label=right:3] (3) {};
\node [mynode, below=of b, label=below:1](1) {};

\draw ;
\end{tikzpicture}


produces

but I've no idea if that is correct or not.

• Yes, this is what I intended. – Git Gud Mar 18 '15 at 12:02