[Tex/LaTex] Increasing vertical space between two subpictures

spacingsubfloatstikz-pgf

I'd like to increase the distance between the upper pictures and the lower ones (a-c and b-d are too close to eachother). I'm new to tikz and I really don't know where to put my hands on. Thank you.

Here's the code:

\documentclass{article}

\usepackage[italian]{babel}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{tikz}
\usepackage{tkz-graph}
\usepackage{subcaption}
\newsavebox{\tempbox}

\begin{document}

\begin{figure}[!htbp]
\sbox{\tempbox}{ % store the bigger of the two pictures in a vbox
  \begin{tikzpicture}
    \GraphInit[vstyle=Dijkstra]
    \Vertex[L=$v_1$]{A}
    \Vertex[x=3,y=0,L=$v_3$]{B} \Vertex[x=1.5,y=-1.5,L=$v_2$]{C}
    \Vertex[x=4.5,y=-1.5,L=$v_4$]{D}
    \tikzset{EdgeStyle/.style={->}}
    \Edge[label=$2$](A)(C)
    \Edge[label=$3$](B)(C)
    \Edge[label=$-1$](C)(D)
  \end{tikzpicture}
}
\begin{subfigure}{.5\textwidth}
    \centering
    \usebox{\tempbox}
\caption{}
\end{subfigure}
\begin{subfigure}{.5\textwidth}
    \centering
    \vbox to\ht\tempbox{
    \vfill
  \begin{tikzpicture}
    \GraphInit[vstyle=Dijkstra]
    \Vertex[L=$0$]{A}
    \Vertex[x=3,y=0,L=$\infty$]{B} \Vertex[x=1.5,y=-1.5,L=$\infty$]{C}
    \Vertex[x=4.5,y=-1.5,L=$\infty$]{D}
    \tikzset{EdgeStyle/.style={->}}
    \Edge[label=$2$](A)(C)
    \Edge[label=$3$](B)(C)
    \Edge[label=$-1$](C)(D)
  \end{tikzpicture}
    \vfill
    }
    \caption{}
\end{subfigure}
\sbox{\tempbox}{
  \begin{tikzpicture}
    \GraphInit[vstyle=Dijkstra]
    \Vertex[L=$0$]{A}
    \Vertex[x=3,y=0,L=$\infty$]{B} \Vertex[x=1.5,y=-1.5,L=$2$]{C}
    \Vertex[x=4.5,y=-1.5,L=$\infty$]{D}
    \tikzset{EdgeStyle/.style={->}}
    \Edge[label=$2$](A)(C)
    \Edge[label=$3$](B)(C)
    \Edge[label=$-1$](C)(D)
  \end{tikzpicture}
}
\begin{subfigure}{.5\textwidth}
    \centering
    \usebox{\tempbox}
\caption{}
\end{subfigure}
\begin{subfigure}{.5\textwidth}
    \centering
    \vbox to\ht\tempbox{
    \vfill
  \begin{tikzpicture}
    \GraphInit[vstyle=Dijkstra]
    \Vertex[L=$0$]{A}
    \Vertex[x=3,y=0,L=$\infty$]{B} \Vertex[x=1.5,y=-1.5,L=$2$]{C}
    \Vertex[x=4.5,y=-1.5,L=$1$]{D}
    \tikzset{EdgeStyle/.style={->}}
    \Edge[label=$2$](A)(C)
    \Edge[label=$3$](B)(C)
    \Edge[label=$-1$](C)(D)
  \end{tikzpicture}
    \vfill
    }
    \caption{}
\end{subfigure}
\caption{General caption}
\end{figure}

\end{document}

I used a box beacause of other needs with other pictures.

Best Answer

enter image description here

I don't think you need those vbox which are not really LaTeX commands anyway, simply put a \vspace between the rows.

Also you got

Overfull \hbox (2.22168pt too wide) in paragraph at lines 27--85
[]$[]$ $[]$

Overfull \hbox (2.22168pt too wide) in paragraph at lines 27--85
[]$ $[]$ 

As you had a word-space between the half-width subfigures so there was not room on a line. You need % at the end of the lines.

You also had two word spaces due to missing % in the saved boxes, but I didn't use \sbox here.

\documentclass{article}

\usepackage[italian]{babel}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{tikz}
\usepackage{tkz-graph}
\usepackage{subcaption}
\newsavebox{\tempbox}

\begin{document}

\begin{figure}[!htbp]

\begin{subfigure}{.5\textwidth}
    \centering
  \begin{tikzpicture}
    \GraphInit[vstyle=Dijkstra]
    \Vertex[L=$v_1$]{A}
    \Vertex[x=3,y=0,L=$v_3$]{B} \Vertex[x=1.5,y=-1.5,L=$v_2$]{C}
    \Vertex[x=4.5,y=-1.5,L=$v_4$]{D}
    \tikzset{EdgeStyle/.style={->}}
    \Edge[label=$2$](A)(C)
    \Edge[label=$3$](B)(C)
    \Edge[label=$-1$](C)(D)
  \end{tikzpicture}%
\caption{}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
    \centering
  \begin{tikzpicture}
    \GraphInit[vstyle=Dijkstra]
    \Vertex[L=$0$]{A}
    \Vertex[x=3,y=0,L=$\infty$]{B} \Vertex[x=1.5,y=-1.5,L=$\infty$]{C}
    \Vertex[x=4.5,y=-1.5,L=$\infty$]{D}
    \tikzset{EdgeStyle/.style={->}}
    \Edge[label=$2$](A)(C)
    \Edge[label=$3$](B)(C)
    \Edge[label=$-1$](C)(D)
  \end{tikzpicture}
    \caption{}
\end{subfigure}%


\vspace{1cm}


\begin{subfigure}{.5\textwidth}
    \centering
     \begin{tikzpicture}
    \GraphInit[vstyle=Dijkstra]
    \Vertex[L=$0$]{A}
    \Vertex[x=3,y=0,L=$\infty$]{B} \Vertex[x=1.5,y=-1.5,L=$2$]{C}
    \Vertex[x=4.5,y=-1.5,L=$\infty$]{D}
    \tikzset{EdgeStyle/.style={->}}
    \Edge[label=$2$](A)(C)
    \Edge[label=$3$](B)(C)
    \Edge[label=$-1$](C)(D)
  \end{tikzpicture}
\caption{}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
    \centering
  \begin{tikzpicture}
    \GraphInit[vstyle=Dijkstra]
    \Vertex[L=$0$]{A}
    \Vertex[x=3,y=0,L=$\infty$]{B} \Vertex[x=1.5,y=-1.5,L=$2$]{C}
    \Vertex[x=4.5,y=-1.5,L=$1$]{D}
    \tikzset{EdgeStyle/.style={->}}
    \Edge[label=$2$](A)(C)
    \Edge[label=$3$](B)(C)
    \Edge[label=$-1$](C)(D)
  \end{tikzpicture}
    \caption{}
\end{subfigure}
\caption{General caption}
\end{figure}

\end{document}