基本上,我试图解释深度优先搜索。我想按以下方式对齐我的图像:
我想在每一行中放置两个图表,每个图表的右侧都有相应的“表格”(代表堆栈):
- 共有 14 张图表和 12 个表格
- 第一个图和最后一个图没有表格。
这是我的代码:
\documentclass{book}
\usepackage[italian]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{geometry}
\geometry{a4paper,top=2.5cm,bottom=2.5cm,left=2cm,right=2cm}
\usepackage{tikz}
\usepackage{tkz-graph}
\usepackage{multirow}
\usepackage{subcaption} %using this package
\usepackage{array}
\newcommand{\myblue}{blue!80}
\newcommand{\mylgray}{black!15}
% I'd like to put two graphs in each single line, with the corresponding 'table' on the right side of each one.
% There are 14 graphs and 12 tables.
% The first graph and the last one have no table.
\begin{document}
% graph 1, NO table
\begin{tikzpicture}
\GraphInit[vstyle=Dijkstra]
\Vertex[L=$v_1$]{A}
\Vertex[x=1.4,y=1.2,L=$v_2$]{B}
\Vertex[x=1.4,y=-1.2,L=$v_3$]{C}
\Vertex[x=3.2,y=1.2,L=$v_4$]{D}
\Vertex[x=3.2,y=-1.2,L=$v_5$]{E}
\Vertex[x=4.6,y=0,L=$v_6$]{F}
\tikzset{EdgeStyle/.style={-}}
\Edge (A)(B)
\Edge (A)(C)
\Edge (B)(D)
\Edge (C)(E)
\Edge (B)(E)
\Edge (D)(F)
\Edge (E)(F)
\end{tikzpicture}
% graph 2, with the 1st table
\begin{tikzpicture}
\GraphInit[vstyle=Dijkstra]
\begin{scope}
\SetVertexNormal[Shape=circle,FillColor=black!20]
\Vertex[L=$v_1$]{A}
\end{scope}
\Vertex[x=1.4,y=1.2,L=$v_2$]{B}
\Vertex[x=1.4,y=-1.2,L=$v_3$]{C}
\Vertex[x=3.2,y=1.2,L=$v_4$]{D}
\Vertex[x=3.2,y=-1.2,L=$v_5$]{E}
\Vertex[x=4.6,y=0,L=$v_6$]{F}
\tikzset{EdgeStyle/.style={-}}
\Edge[color=\mylgray](A)(B)
\Edge[color=\mylgray](A)(C)
\Edge[color=\mylgray](B)(D)
\Edge[color=\mylgray](C)(E)
\Edge[color=\mylgray](B)(E)
\Edge[color=\mylgray](D)(F)
\Edge[color=\mylgray](E)(F)
\end{tikzpicture}
% graph 3, with the 2nd table
\begin{tikzpicture}
\GraphInit[vstyle=Dijkstra]
\begin{scope}
\SetVertexNormal[Shape=circle,FillColor=black!20]
\Vertex[L=$v_1$]{A}
\Vertex[x=1.4,y=1.2,L=$v_2$]{B}
\end{scope}
\Vertex[x=1.4,y=-1.2,L=$v_3$]{C}
\Vertex[x=3.2,y=1.2,L=$v_4$]{D}
\Vertex[x=3.2,y=-1.2,L=$v_5$]{E}
\Vertex[x=4.6,y=0,L=$v_6$]{F}
\tikzset{EdgeStyle/.style={-}}
\Edge (A)(B)
\Edge[color=\mylgray](A)(C)
\Edge[color=\mylgray](B)(D)
\Edge[color=\mylgray](C)(E)
\Edge[color=\mylgray](B)(E)
\Edge[color=\mylgray](D)(F)
\Edge[color=\mylgray](E)(F)
\end{tikzpicture}
% graph 4 ...
\begin{tikzpicture}
\GraphInit[vstyle=Dijkstra]
\begin{scope}
\SetVertexNormal[Shape=circle,FillColor=black!20]
\Vertex[L=$v_1$]{A}
\Vertex[x=1.4,y=1.2,L=$v_2$]{B}
\Vertex[x=3.2,y=-1.2,L=$v_5$]{E}
\end{scope}
\Vertex[x=1.4,y=-1.2,L=$v_3$]{C}
\Vertex[x=3.2,y=1.2,L=$v_4$]{D}
\Vertex[x=4.6,y=0,L=$v_6$]{F}
\tikzset{EdgeStyle/.style={-}}
\Edge (A)(B)
\Edge[color=\mylgray](A)(C)
\Edge[color=\mylgray](B)(D)
\Edge[color=\mylgray](C)(E)
\Edge (B)(E)
\Edge[color=\mylgray](D)(F)
\Edge[color=\mylgray](E)(F)
\end{tikzpicture}
\begin{tikzpicture}
\GraphInit[vstyle=Dijkstra]
\begin{scope}
\SetVertexNormal[Shape=circle,FillColor=black!20]
\Vertex[L=$v_1$]{A}
\Vertex[x=1.4,y=1.2,L=$v_2$]{B}
\Vertex[x=1.4,y=-1.2,L=$v_3$]{C}
\Vertex[x=3.2,y=-1.2,L=$v_5$]{E}
\end{scope}
\Vertex[x=3.2,y=1.2,L=$v_4$]{D}
\Vertex[x=4.6,y=0,L=$v_6$]{F}
\tikzset{EdgeStyle/.style={-}}
\Edge (A)(B)
\Edge[color=\mylgray](A)(C)
\Edge[color=\mylgray](B)(D)
\Edge (C)(E)
\Edge (B)(E)
\Edge[color=\mylgray](D)(F)
\Edge[color=\mylgray](E)(F)
\end{tikzpicture}
\begin{tikzpicture}
\GraphInit[vstyle=Dijkstra]
\begin{scope}
\SetVertexNormal[Shape=circle,FillColor=black!20]
\Vertex[L=$v_1$]{A}
\Vertex[x=1.4,y=1.2,L=$v_2$]{B}
\Vertex[x=3.2,y=-1.2,L=$v_5$]{E}
\end{scope}
\begin{scope}
\SetVertexNormal[Shape=circle,FillColor=black!90,TextColor=white]
\Vertex[x=1.4,y=-1.2,L=$v_3$]{C}
\end{scope}
\Vertex[x=3.2,y=1.2,L=$v_4$]{D}
\Vertex[x=4.6,y=0,L=$v_6$]{F}
\tikzset{EdgeStyle/.style={-}}
\Edge (A)(B)
\Edge[style=dashed](A)(C)
\Edge[color=\mylgray](B)(D)
\Edge (C)(E)
\Edge (B)(E)
\Edge[color=\mylgray](D)(F)
\Edge[color=\mylgray](E)(F)
\end{tikzpicture}
\begin{tikzpicture}
\GraphInit[vstyle=Dijkstra]
\begin{scope}
\SetVertexNormal[Shape=circle,FillColor=black!20]
\Vertex[L=$v_1$]{A}
\Vertex[x=1.4,y=1.2,L=$v_2$]{B}
\Vertex[x=3.2,y=-1.2,L=$v_5$]{E}
\Vertex[x=4.6,y=0,L=$v_6$]{F}
\end{scope}
\begin{scope}
\SetVertexNormal[Shape=circle,FillColor=black!90,TextColor=white]
\Vertex[x=1.4,y=-1.2,L=$v_3$]{C}
\end{scope}
\Vertex[x=3.2,y=1.2,L=$v_4$]{D}
\tikzset{EdgeStyle/.style={-}}
\Edge (A)(B)
%\Edge[style=dashed](A)(C)
\Edge[color=\mylgray](B)(D)
\Edge (C)(E)
\Edge (B)(E)
\Edge[color=\mylgray](D)(F)
\Edge (E)(F)
\end{tikzpicture}
\begin{tikzpicture}
\GraphInit[vstyle=Dijkstra]
\begin{scope}
\SetVertexNormal[Shape=circle,FillColor=black!20]
\Vertex[L=$v_1$]{A}
\Vertex[x=1.4,y=1.2,L=$v_2$]{B}
\Vertex[x=3.2,y=-1.2,L=$v_5$]{E}
\Vertex[x=4.6,y=0,L=$v_6$]{F}
\Vertex[x=3.2,y=1.2,L=$v_4$]{D}
\end{scope}
\begin{scope}
\SetVertexNormal[Shape=circle,FillColor=black!90,TextColor=white]
\Vertex[x=1.4,y=-1.2,L=$v_3$]{C}
\end{scope}
\tikzset{EdgeStyle/.style={-}}
\Edge (A)(B)
%\Edge[style=dashed](A)(C)
\Edge[color=\mylgray](B)(D)
\Edge (C)(E)
\Edge (B)(E)
\Edge (D)(F)
\Edge (E)(F)
\end{tikzpicture}
\begin{tikzpicture}
\GraphInit[vstyle=Dijkstra]
\begin{scope}
\SetVertexNormal[Shape=circle,FillColor=black!20]
\Vertex[L=$v_1$]{A}
\Vertex[x=1.4,y=1.2,L=$v_2$]{B}
\Vertex[x=3.2,y=-1.2,L=$v_5$]{E}
\Vertex[x=4.6,y=0,L=$v_6$]{F}
\end{scope}
\begin{scope}
\SetVertexNormal[Shape=circle,FillColor=black!90,TextColor=white]
\Vertex[x=1.4,y=-1.2,L=$v_3$]{C}
\Vertex[x=3.2,y=1.2,L=$v_4$]{D}
\end{scope}
\tikzset{EdgeStyle/.style={-}}
\Edge (A)(B)
%\Edge[style=dashed](A)(C)
\Edge[style=dashed](B)(D)
\Edge (C)(E)
\Edge (B)(E)
\Edge (D)(F)
\Edge (E)(F)
\end{tikzpicture}
\begin{tikzpicture}
\GraphInit[vstyle=Dijkstra]
\begin{scope}
\SetVertexNormal[Shape=circle,FillColor=black!20]
\Vertex[L=$v_1$]{A}
\Vertex[x=1.4,y=1.2,L=$v_2$]{B}
\Vertex[x=3.2,y=-1.2,L=$v_5$]{E}
\end{scope}
\begin{scope}
\SetVertexNormal[Shape=circle,FillColor=black!90,TextColor=white]
\Vertex[x=1.4,y=-1.2,L=$v_3$]{C}
\Vertex[x=3.2,y=1.2,L=$v_4$]{D}
\Vertex[x=4.6,y=0,L=$v_6$]{F}
\end{scope}
\tikzset{EdgeStyle/.style={-}}
\Edge (A)(B)
%\Edge[style=dashed](A)(C)
%\Edge[style=dashed](B)(D)
\Edge (C)(E)
\Edge (B)(E)
\Edge (D)(F)
\Edge (E)(F)
\end{tikzpicture}
\begin{tikzpicture}
\GraphInit[vstyle=Dijkstra]
\begin{scope}
\SetVertexNormal[Shape=circle,FillColor=black!20]
\Vertex[L=$v_1$]{A}
\Vertex[x=1.4,y=1.2,L=$v_2$]{B}
\end{scope}
\begin{scope}
\SetVertexNormal[Shape=circle,FillColor=black!90,TextColor=white]
\Vertex[x=1.4,y=-1.2,L=$v_3$]{C}
\Vertex[x=3.2,y=1.2,L=$v_4$]{D}
\Vertex[x=3.2,y=-1.2,L=$v_5$]{E}
\Vertex[x=4.6,y=0,L=$v_6$]{F}
\end{scope}
\tikzset{EdgeStyle/.style={-}}
\Edge (A)(B)
%\Edge[style=dashed](A)(C)
%\Edge[style=dashed](B)(D)
\Edge (C)(E)
\Edge (B)(E)
\Edge (D)(F)
\Edge (E)(F)
\end{tikzpicture}
\begin{tikzpicture}
\GraphInit[vstyle=Dijkstra]
\begin{scope}
\SetVertexNormal[Shape=circle,FillColor=black!20]
\Vertex[L=$v_1$]{A}
\end{scope}
\begin{scope}
\SetVertexNormal[Shape=circle,FillColor=black!90,TextColor=white]
\Vertex[x=1.4,y=1.2,L=$v_2$]{B}
\Vertex[x=1.4,y=-1.2,L=$v_3$]{C}
\Vertex[x=3.2,y=1.2,L=$v_4$]{D}
\Vertex[x=3.2,y=-1.2,L=$v_5$]{E}
\Vertex[x=4.6,y=0,L=$v_6$]{F}
\end{scope}
\tikzset{EdgeStyle/.style={-}}
\Edge (A)(B)
%\Edge[style=dashed](A)(C)
%\Edge[style=dashed](B)(D)
\Edge (C)(E)
\Edge (B)(E)
\Edge (D)(F)
\Edge (E)(F)
\end{tikzpicture}
\begin{tikzpicture}
\GraphInit[vstyle=Dijkstra]
\SetVertexNormal[Shape=circle,FillColor=black!90,TextColor=white]
\Vertex[L=$v_1$]{A}
\Vertex[x=1.4,y=1.2,L=$v_2$]{B}
\Vertex[x=1.4,y=-1.2,L=$v_3$]{C}
\Vertex[x=3.2,y=1.2,L=$v_4$]{D}
\Vertex[x=3.2,y=-1.2,L=$v_5$]{E}
\Vertex[x=4.6,y=0,L=$v_6$]{F}
\tikzset{EdgeStyle/.style={-}}
\Edge (A)(B)
%\Edge[style=dashed](A)(C)
%\Edge[style=dashed](B)(D)
\Edge (C)(E)
\Edge (B)(E)
\Edge (D)(F)
\Edge (E)(F)
\end{tikzpicture}
\begin{tikzpicture}
\GraphInit[vstyle=Dijkstra]
\SetVertexNormal[Shape=circle]
\Vertex[L=$v_1$]{A}
\Vertex[x=1.4,y=1.2,L=$v_2$]{B}
\Vertex[x=1.4,y=-1.2,L=$v_3$]{C}
\Vertex[x=3.2,y=1.2,L=$v_4$]{D}
\Vertex[x=3.2,y=-1.2,L=$v_5$]{E}
\Vertex[x=4.6,y=0,L=$v_6$]{F}
\tikzset{EdgeStyle/.style={-}}
\Edge (A)(B)
%\Edge[style=dashed](A)(C)
%\Edge[style=dashed](B)(D)
\Edge (C)(E)
\Edge (B)(E)
\Edge (D)(F)
\Edge (E)(F)
\end{tikzpicture}
% graph 2
\begin{tabular}{ |c| }
$v_1(0, -$) \\
\cline{1-1}
\end{tabular}
\bigskip
% graph 3
\begin{tabular}{ |c| }
$v_2(1, -)$ \\
\cline{1-1}
$v_1(0, -$) \\
\cline{1-1}
\end{tabular}
\bigskip
\begin{tabular}{ |c| }
$v_5(2, -)$ \\
\cline{1-1}
$v_2(1, -)$ \\
\cline{1-1}
$v_1(0, -$) \\
\cline{1-1}
\end{tabular}
\bigskip
\begin{tabular}{ |c| }
$v_3(3, -)$ \\
\cline{1-1}
$v_5(2, -)$ \\
\cline{1-1}
$v_2(1, -)$ \\
\cline{1-1}
$v_1(0, -$) \\
\cline{1-1}
\end{tabular}
\bigskip
\begin{tabular}{ |c| }
\multicolumn{1}{c}{$v_3(3, 4)$} \\
\multicolumn{1}{c}{$\uparrow$} \\
$v_5(2, -)$ \\
\cline{1-1}
$v_2(1, -)$ \\
\cline{1-1}
$v_1(0, -$) \\
\cline{1-1}
\end{tabular}
\bigskip
\begin{tabular}{ |c| }
$v_6(5, -)$ \\
\cline{1-1}
$v_5(2, -)$ \\
\cline{1-1}
$v_2(1, -)$ \\
\cline{1-1}
$v_1(0, -$) \\
\cline{1-1}
\end{tabular}
\bigskip
\begin{tabular}{ |c| }
$v_4(6, -)$ \\
\cline{1-1}
$v_6(5, -)$ \\
\cline{1-1}
$v_5(2, -)$ \\
\cline{1-1}
$v_2(1, -)$ \\
\cline{1-1}
$v_1(0, -$) \\
\cline{1-1}
\end{tabular}
\bigskip
\begin{tabular}{ |c| }
\multicolumn{1}{c}{$v_4(6, 7)$} \\
\multicolumn{1}{c}{$\uparrow$} \\
$v_6(5, -)$ \\
\cline{1-1}
$v_5(2, -)$ \\
\cline{1-1}
$v_2(1, -)$ \\
\cline{1-1}
$v_1(0, -$) \\
\cline{1-1}
\end{tabular}
\bigskip
\begin{tabular}{ |c| }
\multicolumn{1}{c}{$v_6(5, 8)$} \\
\multicolumn{1}{c}{$\uparrow$} \\
$v_5(2, -)$ \\
\cline{1-1}
$v_2(1, -)$ \\
\cline{1-1}
$v_1(0, -$) \\
\cline{1-1}
\end{tabular}
\bigskip
\begin{tabular}{ |c| }
\multicolumn{1}{c}{$v_5(2, 9)$} \\
\multicolumn{1}{c}{$\uparrow$} \\
$v_2(1, -)$ \\
\cline{1-1}
$v_1(0, -$) \\
\cline{1-1}
\end{tabular}
\bigskip
\begin{tabular}{ |c| }
\multicolumn{1}{c}{$v_2(1, 10)$} \\
\multicolumn{1}{c}{$\uparrow$} \\
$v_1(0, -$) \\
\cline{1-1}
\end{tabular}
\bigskip
\begin{tabular}{ |c| }
\multicolumn{1}{c}{$v_1(0, 11)$} \\
\multicolumn{1}{c}{$\uparrow$} \\
\\
\cline{1-1}
\end{tabular}
\end{document}
提前谢谢您。如能得到任何帮助,我将不胜感激。
答案1
有一种可能性是:使用subfigure
环境我定义了一个\MyRow
具有六个强制参数的环境:
\MyRow{<material1>}{<caption1>}{<material2>}{<material3>}{<caption2>}{<material4>}
下面的代码只显示两行:
\documentclass{book}
\usepackage[italian]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{geometry}
\geometry{a4paper,top=2.5cm,bottom=2.5cm,left=2cm,right=2cm}
\usepackage{tikz}
\usepackage{tkz-graph}
\usepackage{multirow}
\usepackage{subcaption} %using this package
\usepackage{array}
\usepackage{longtable}
\newcommand{\myblue}{blue!80}
\newcommand{\mylgray}{black!15}
% I'd like to put two graphs in each single line, with the corresponding 'table' on the right side of each one.
% There are 14 graphs and 12 tables.
% The first graph and the last one have no table.
\newcommand\MyRow[6]{%
\par\medskip\noindent\begin{subfigure}{0.4\textwidth}
\centering
#1
\caption{#2}
\end{subfigure}%
\begin{subfigure}{0.1\textwidth}
\centering
#3
\end{subfigure}%
\begin{subfigure}{0.4\textwidth}
\centering
#4
\caption{#5}
\end{subfigure}%
\begin{subfigure}{0.1\textwidth}
\centering
#6
\end{subfigure}%
}
\begin{document}
\begin{figure}
\MyRow{% graph 1, NO table
\begin{tikzpicture}
\GraphInit[vstyle=Dijkstra]
\Vertex[L=$v_1$]{A}
\Vertex[x=1.4,y=1.2,L=$v_2$]{B}
\Vertex[x=1.4,y=-1.2,L=$v_3$]{C}
\Vertex[x=3.2,y=1.2,L=$v_4$]{D}
\Vertex[x=3.2,y=-1.2,L=$v_5$]{E}
\Vertex[x=4.6,y=0,L=$v_6$]{F}
\tikzset{EdgeStyle/.style={-}}
\Edge (A)(B)
\Edge (A)(C)
\Edge (B)(D)
\Edge (C)(E)
\Edge (B)(E)
\Edge (D)(F)
\Edge (E)(F)
\end{tikzpicture}%
}{first subfigure}%
{\mbox{}}%
{%
% graph 2, with the 1st table
\begin{tikzpicture}
\GraphInit[vstyle=Dijkstra]
\begin{scope}
\SetVertexNormal[Shape=circle,FillColor=black!20]
\Vertex[L=$v_1$]{A}
\end{scope}
\Vertex[x=1.4,y=1.2,L=$v_2$]{B}
\Vertex[x=1.4,y=-1.2,L=$v_3$]{C}
\Vertex[x=3.2,y=1.2,L=$v_4$]{D}
\Vertex[x=3.2,y=-1.2,L=$v_5$]{E}
\Vertex[x=4.6,y=0,L=$v_6$]{F}
\tikzset{EdgeStyle/.style={-}}
\Edge[color=\mylgray](A)(B)
\Edge[color=\mylgray](A)(C)
\Edge[color=\mylgray](B)(D)
\Edge[color=\mylgray](C)(E)
\Edge[color=\mylgray](B)(E)
\Edge[color=\mylgray](D)(F)
\Edge[color=\mylgray](E)(F)
\end{tikzpicture}
}{second subfigure}%
{% graph 2
\begin{tabular}[t]{ |c| }
$v_1(0, -$) \\
\cline{1-1}
\end{tabular}
}
\MyRow{% graph 3, with the 2nd table
\begin{tikzpicture}
\GraphInit[vstyle=Dijkstra]
\begin{scope}
\SetVertexNormal[Shape=circle,FillColor=black!20]
\Vertex[L=$v_1$]{A}
\Vertex[x=1.4,y=1.2,L=$v_2$]{B}
\end{scope}
\Vertex[x=1.4,y=-1.2,L=$v_3$]{C}
\Vertex[x=3.2,y=1.2,L=$v_4$]{D}
\Vertex[x=3.2,y=-1.2,L=$v_5$]{E}
\Vertex[x=4.6,y=0,L=$v_6$]{F}
\tikzset{EdgeStyle/.style={-}}
\Edge (A)(B)
\Edge[color=\mylgray](A)(C)
\Edge[color=\mylgray](B)(D)
\Edge[color=\mylgray](C)(E)
\Edge[color=\mylgray](B)(E)
\Edge[color=\mylgray](D)(F)
\Edge[color=\mylgray](E)(F)
\end{tikzpicture}%
}{third subfigure}%
{% graph 3
\begin{tabular}[t]{ |c| }
$v_2(1, -)$ \\
\cline{1-1}
$v_1(0, -$) \\
\cline{1-1}
\end{tabular}%
}%
{% graph 4 ...
\begin{tikzpicture}
\GraphInit[vstyle=Dijkstra]
\begin{scope}
\SetVertexNormal[Shape=circle,FillColor=black!20]
\Vertex[L=$v_1$]{A}
\Vertex[x=1.4,y=1.2,L=$v_2$]{B}
\Vertex[x=3.2,y=-1.2,L=$v_5$]{E}
\end{scope}
\Vertex[x=1.4,y=-1.2,L=$v_3$]{C}
\Vertex[x=3.2,y=1.2,L=$v_4$]{D}
\Vertex[x=4.6,y=0,L=$v_6$]{F}
\tikzset{EdgeStyle/.style={-}}
\Edge (A)(B)
\Edge[color=\mylgray](A)(C)
\Edge[color=\mylgray](B)(D)
\Edge[color=\mylgray](C)(E)
\Edge (B)(E)
\Edge[color=\mylgray](D)(F)
\Edge[color=\mylgray](E)(F)
\end{tikzpicture}%
}{fourth subfigure}%
{% graph 4
\begin{tabular}[t]{ |c| }
$v_5(2, -)$ \\
\cline{1-1}
$v_2(1, -)$ \\
\cline{1-1}
$v_1(0, -$) \\
\cline{1-1}
\end{tabular}
}
\caption{A figure with multiple subfigures}
\label{fig:test}
\end{figure}
\end{document}