1

Ideally I would like to have the tikzpictures be in one line centered horizontally with its caption each preserving its node size and line strength and vertically aligned to a common bottom line. I am quite stuck however - therefore all help is much appreciated as I simply have no time to work through the subcaption manual (if a better alternative is out there, a hint is appreciated too) and definitely not pgf manual documentation right now - though the pgf manual is on my todo list for sure.

\documentclass[a4paper, twoside]{book}

\usepackage{subcaption}
\usepackage{tikz}
\usetikzlibrary{shapes,backgrounds,shapes,positioning,petri,topaths}

\begin{document}

\begin{figure}[ht]
        \centering
        \begin{subfigure}[b]{0.16\textwidth}
                \begin{tikzpicture}[scale=0.50]
                    \node (v1) at (2,3) [circle, draw] {};
                \end{tikzpicture}
                \caption{$K_1$}
                \label{fig:20140812k1}
        \end{subfigure}%
        %\quad
        \begin{subfigure}[b]{0.3\textwidth}

                \begin{tikzpicture}[scale=0.50]
                    \node (v1) at (2,1) [circle, draw] {};
                    \node (v2) at (2,3) [circle, draw] {};
                    \draw (v1) -- (v2);
                \end{tikzpicture}
                \caption{$K_2$}
                \label{fig:20140806k2}
        \end{subfigure}
        \begin{subfigure}[b]{0.16\textwidth}
                \begin{tikzpicture}[scale=0.50]
                    \node (v1) at (1,1) [circle, draw] {};
                    \node (v2) at (3,1) [circle, draw] {};
                    \node (v3) at (2,3) [circle, draw] {};
                    \draw (v1) -- (v2);
                    \draw (v2) -- (v3);
                    \draw (v1) -- (v3);
                \end{tikzpicture}
                \caption{$K_3$}
                \label{fig:20140812k3}
        \end{subfigure}%
        %\quad
        \begin{subfigure}[b]{0.16\textwidth}
                \begin{tikzpicture}[scale=0.50]
                    \node (v1) at (1,1) [circle, draw] {};
                    \node (v2) at (5,1) [circle, draw] {};
                    \node (v3) at (3,2) [circle, draw] {};
                    \node (v4) at (3,4) [circle, draw] {};
                    \draw (v1) -- (v2);
                    \draw (v1) -- (v3);
                    \draw (v1) -- (v4);
                    \draw (v2) -- (v3);
                    \draw (v2) -- (v4);
                    \draw (v3) -- (v4);
                \end{tikzpicture}
                \caption{$K_4$}
                \label{fig:20140812k4}
        \end{subfigure}%
        %\quad
        \begin{subfigure}[b]{0.16\textwidth}
                \begin{tikzpicture}[scale=0.50]
                    \node (v1) at (2,1) [circle, draw] {};
                    \node (v2) at (4,1) [circle, draw] {};
                    \node (v3) at (1,3) [circle, draw] {};
                    \node (v4) at (5,3) [circle, draw] {};
                    \node (v5) at (3,4) [circle, draw] {};

                    \draw (v1) -- (v2);
                    \draw (v1) -- (v3);
                    \draw (v1) -- (v4);
                    \draw (v1) -- (v5);
                    \draw (v2) -- (v3);
                    \draw (v2) -- (v4);
                    \draw (v2) -- (v5);
                    \draw (v3) -- (v4);
                    \draw (v3) -- (v5);
                    \draw (v4) -- (v5);
                \end{tikzpicture}
                \caption{$K_5$}
                \label{fig:20140812k5}
        \end{subfigure}%
        %\quad
        \begin{subfigure}[b]{0.16\textwidth}
                \begin{tikzpicture}[scale=0.50]
                    \node (v1) at (2,1) [circle, draw] {};
                    \node (v2) at (4,1) [circle, draw] {};
                    \node (v3) at (1,3) [circle, draw] {};
                    \node (v4) at (5,3) [circle, draw] {};
                    \node (v5) at (2,5) [circle, draw] {};
                    \node (v6) at (4,5) [circle, draw] {};

                    \draw (v1) -- (v2);
                    \draw (v1) -- (v3);
                    \draw (v1) -- (v4);
                    \draw (v1) -- (v5);
                    \draw (v1) -- (v6);
                    \draw (v2) -- (v3);
                    \draw (v2) -- (v4);
                    \draw (v2) -- (v5);
                    \draw (v2) -- (v6);
                    \draw (v3) -- (v4);
                    \draw (v3) -- (v5);
                    \draw (v3) -- (v6);
                    \draw (v4) -- (v5);
                    \draw (v4) -- (v6);
                    \draw (v5) -- (v6);
                \end{tikzpicture}
                \caption{$K_6$}
                \label{fig:20140812k6}
        \end{subfigure}%
         \caption{Vollständige Graphen $K_1$ bi $K_6$}\label{fig:completeGraphs}
\end{figure}

\end{document} 
  • 1
    Welcome to TeX.SX! I'm not sure that I entirely I understand your description of what you want. What do you mean by preserve node size and line strength, for example? At any rate, put \centering after begin{subfigure} and before \begin{tikzpicture} and that should solve the horizontal-alignment issue. – Adam Liter Aug 12 '14 at 19:29
2

First of all, you have to center each tikzpicture inside each subfigure. You achieve that with \centering just to the left of the \begin{tikzpicture}.

Also, giving every subfigure the same width (0.16\textwidth) is a good deal.

To have every subfigure in the same line, you should probably play with document margin, because with six figures you are very probably exceeding \textwidth. I think that will not be possible, because to get them in the same line I set 10[mm] to the left and right margins. Perhaps a better option is to have three subfigures per line, what can be achieved with a simple \\ between the third and fourth subfigure.

enter image description here

This is achieved with this LaTeX code:

\documentclass[a4paper, twoside]{book}

\usepackage{subcaption}
\usepackage[left=10mm,right=10mm]{geometry}
\usepackage{tikz}
\usetikzlibrary{shapes,backgrounds,shapes,positioning,petri,topaths}

\begin{document}

\begin{figure}[ht]
        \centering
        \begin{subfigure}[b]{0.16\textwidth}
                \centering

                \begin{tikzpicture}[scale=0.50]
                    \node (v1) at (2,3) [circle, draw] {};
                \end{tikzpicture}
                \caption{$K_1$}
                \label{fig:20140812k1}
        \end{subfigure}%
        %\quad
        \begin{subfigure}[b]{0.1\textwidth}

                \centering\begin{tikzpicture}[scale=0.50]
                    \node (v1) at (2,1) [circle, draw] {};
                    \node (v2) at (2,3) [circle, draw] {};
                    \draw (v1) -- (v2);
                \end{tikzpicture}
                \caption{$K_2$}
                \label{fig:20140806k2}
        \end{subfigure}
        \begin{subfigure}[b]{0.16\textwidth}
                \centering\begin{tikzpicture}[scale=0.50]
                    \node (v1) at (1,1) [circle, draw] {};
                    \node (v2) at (3,1) [circle, draw] {};
                    \node (v3) at (2,3) [circle, draw] {};
                    \draw (v1) -- (v2);
                    \draw (v2) -- (v3);
                    \draw (v1) -- (v3);
                \end{tikzpicture}
                \caption{$K_3$}
                \label{fig:20140812k3}
        \end{subfigure}%
        \begin{subfigure}[b]{0.16\textwidth}
                \centering\begin{tikzpicture}[scale=0.50]
                    \node (v1) at (1,1) [circle, draw] {};
                    \node (v2) at (5,1) [circle, draw] {};
                    \node (v3) at (3,2) [circle, draw] {};
                    \node (v4) at (3,4) [circle, draw] {};
                    \draw (v1) -- (v2);
                    \draw (v1) -- (v3);
                    \draw (v1) -- (v4);
                    \draw (v2) -- (v3);
                    \draw (v2) -- (v4);
                    \draw (v3) -- (v4);
                \end{tikzpicture}
                \caption{$K_4$}
                \label{fig:20140812k4}
        \end{subfigure}%
        \begin{subfigure}[b]{0.16\textwidth}
                \centering\begin{tikzpicture}[scale=0.50]
                    \node (v1) at (2,1) [circle, draw] {};
                    \node (v2) at (4,1) [circle, draw] {};
                    \node (v3) at (1,3) [circle, draw] {};
                    \node (v4) at (5,3) [circle, draw] {};
                    \node (v5) at (3,4) [circle, draw] {};

                    \draw (v1) -- (v2);
                    \draw (v1) -- (v3);
                    \draw (v1) -- (v4);
                    \draw (v1) -- (v5);
                    \draw (v2) -- (v3);
                    \draw (v2) -- (v4);
                    \draw (v2) -- (v5);
                    \draw (v3) -- (v4);
                    \draw (v3) -- (v5);
                    \draw (v4) -- (v5);
                \end{tikzpicture}
                \caption{$K_5$}
                \label{fig:20140812k5}
        \end{subfigure}%
        %\quad
        \begin{subfigure}[b]{0.16\textwidth}
                \centering
                \begin{tikzpicture}[scale=0.50]
                    \node (v1) at (2,1) [circle, draw] {};
                    \node (v2) at (4,1) [circle, draw] {};
                    \node (v3) at (1,3) [circle, draw] {};
                    \node (v4) at (5,3) [circle, draw] {};
                    \node (v5) at (2,5) [circle, draw] {};
                    \node (v6) at (4,5) [circle, draw] {};

                    \draw (v1) -- (v2);
                    \draw (v1) -- (v3);
                    \draw (v1) -- (v4);
                    \draw (v1) -- (v5);
                    \draw (v1) -- (v6);
                    \draw (v2) -- (v3);
                    \draw (v2) -- (v4);
                    \draw (v2) -- (v5);
                    \draw (v2) -- (v6);
                    \draw (v3) -- (v4);
                    \draw (v3) -- (v5);
                    \draw (v3) -- (v6);
                    \draw (v4) -- (v5);
                    \draw (v4) -- (v6);
                    \draw (v5) -- (v6);
                \end{tikzpicture}
                \caption{$K_6$}
                \label{fig:20140812k6}
        \end{subfigure}%
         \caption{Vollständige Graphen $K_1$ bi $K_6$}\label{fig:completeGraphs}
\end{figure}

\end{document} 
  • This seems more appropriate as a comment—at least until we receive further clarification from the OP—as it doesn't fully answer the question. – Adam Liter Aug 12 '14 at 19:59
  • As far as I've understood what the OP wants, my answer DOES give him the hints needed to achieve his goal. Both vertical and horizontal alignments are done, as well as the six elements in the same line. And I'm also giving an alternative for the case when the margins won't be enough to hold the six elements in the same line. – Nicolás Ozimica Aug 12 '14 at 20:10
  • The MWE makes this more appropriate as an answer, I think. Why not use .16\textwidth for all subfigures, though? There are 6, which means they will all fit on the page then. With scale=0.50, there will be some overlap between the fifth and sixth subfigures, but then the scale could just be made to be smaller across the board. The advantage of this approach is that you don't have to adjust the margins, and it will work with any margins. – Adam Liter Aug 12 '14 at 20:21
  • Also a simple blank line (or a \par) would seem to be a better way to induce a new line if you want to split the subfigures into two rows, rather than using \\ . – Adam Liter Aug 12 '14 at 20:26
  • I've been using .16\textwidth since the beginning. That's the reason of the second paragraph in my answer. – Nicolás Ozimica Aug 12 '14 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.