增加两个子图片之间的垂直空间

增加两个子图片之间的垂直空间

我想增加上部图片和下部图片之间的距离(ac 和 bd 彼此太近了)。我是 tikz 新手,我真的不知道该怎么做。谢谢。

代码如下:

\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}

由于其他图片有其他需求,我使用了一个盒子。

答案1

在此处输入图片描述

我不认为你需要那些vbox不是真正的 LaTeX 命令的命令,只需\vspace在行之间放置一个即可。

你还得到了

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

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

由于半角子图之间有一个字间距,所以一行上没有空间。您需要%在行末留出空间。

由于保存的框中缺少两个单词空格%,但我在这里没有使用\sbox

\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}

答案2

\rule我在子图 a 和 b 的标题后添加了垂直线

\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{}
\rule{0ex}{10ex}%  ADDED THIS LINE HERE
\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{}
\rule{0ex}{10ex}%  ADDED THIS LINE HERE
\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}

相关内容