![在 tikz 中对齐图形](https://linux22.com/image/366180/%E5%9C%A8%20tikz%20%E4%B8%AD%E5%AF%B9%E9%BD%90%E5%9B%BE%E5%BD%A2.png)
我有这个 tikz 图形的代码:
\documentclass{article}
\usepackage{pgf}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{subcaption}
\usetikzlibrary{arrows,automata}
\usepackage[latin1]{inputenc}
\definecolor{mycolor}{RGB}{0, 85, 128}
\definecolor{colorforline}{RGB}{0, 26, 0}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[auto,node distance=2.8cm,thick]
\tikzstyle{every state}=[fill=mycolor,draw=none,text=white]
\tikzstyle{myarrows}=[line width=1mm,draw=mycolor,-triangle 45,postaction={draw, line width=3mm, shorten >=4mm, -}]
\node[state] (A) {$A$};
\node[state] (B) [below left of=A] {$B$};
\node[state] (C) [below right of=B] {$C$};
\node[state] (D) [below right of=A] {$D$};
\node[state] (E) [above right of=D,xshift=-1cm,yshift=0.6cm] {$E$};
\node[state] (F) [right of=C,yshift=0.3cm,xshift=1cm] {$F$};
\path
(A) edge[above,color=mycolor] node {3} (B)
(B) edge[above,color=mycolor] node {5} (C)
(C) edge[above,color=mycolor] node {2} (D)
(D) edge[color=mycolor] node {1} (E)
edge[above,color=mycolor] node {4} (A);
\draw [myarrows] (5,-2) -- (6,-2) node [right]{$$};
\end{tikzpicture}
\end{figure}
\end{document}
请注意,在最后一张带有子图的图片中,我只是重复使用了上面添加的相同 tikz 图片的代码。所以请使用它。
答案1
\documentclass[12pt]{article}
%\usepackage{fullpage}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{tikz}
\usepackage{pgf}
\usepackage{tikz}
\usepackage{graphicx}
\usetikzlibrary{arrows,automata}
\usepackage[latin1]{inputenc}
\definecolor{mycolor}{RGB}{0, 85, 128}
\definecolor{colorforline}{RGB}{0, 26, 0}
\usepackage{subfig}
\begin{document}
\begin{figure}[h!]
\centering
\subfloat[AAAA]{\label{fig:AAAA}
\resizebox{4cm}{!}{
\begin{tikzpicture}[auto,node distance=2.8cm,thick]
\tikzstyle{every state}=[fill=mycolor,draw=none,text=white]
\tikzstyle{myarrows}=[line width=1mm,draw=mycolor,-triangle 45,postaction={draw, line width=3mm, shorten >=4mm, -}]
\node[state] (A) {$A$};
\node[state] (B) [below left of=A] {$B$};
\node[state] (C) [below right of=B] {$C$};
\node[state] (D) [below right of=A] {$D$};
\node[state] (E) [above right of=D,xshift=-1cm,yshift=0.6cm] {$E$};
\node[state] (F) [right of=C,yshift=0.3cm,xshift=1cm] {$F$};
\path
(A) edge[above,color=mycolor] node {3} (B)
(B) edge[above,color=mycolor] node {5} (C)
(C) edge[above,color=mycolor] node {2} (D)
(D) edge[color=mycolor] node {1} (E)
edge[above,color=mycolor] node {4} (A);
\draw [myarrows] (5,-2) -- (6,-2) node [right]{$$};
\end{tikzpicture}
}
}%
\hfill
\subfloat[BBBB]{\label{fig:BBBB}
\resizebox{4cm}{!}{
\begin{tikzpicture}[auto,node distance=2.8cm,thick]
\tikzstyle{every state}=[fill=mycolor,draw=none,text=white]
\tikzstyle{myarrows}=[line width=1mm,draw=mycolor,-triangle 45,postaction={draw, line width=3mm, shorten >=4mm, -}]
\node[state] (A) {$A$};
\node[state] (B) [below left of=A] {$B$};
\node[state] (C) [below right of=B] {$C$};
\node[state] (D) [below right of=A] {$D$};
\node[state] (E) [above right of=D,xshift=-1cm,yshift=0.6cm] {$E$};
\node[state] (F) [right of=C,yshift=0.3cm,xshift=1cm] {$F$};
\path
(A) edge[above,color=mycolor] node {3} (B)
(B) edge[above,color=mycolor] node {5} (C)
(C) edge[above,color=mycolor] node {2} (D)
(D) edge[color=mycolor] node {1} (E)
edge[above,color=mycolor] node {4} (A);
\draw [myarrows] (5,-2) -- (6,-2) node [right]{$$};
\end{tikzpicture}
}
}%
\hfill
\subfloat[CCCC]{\label{fig:CCCC}
\resizebox{3.4cm}{!}{
\begin{tikzpicture}[auto,node distance=2.8cm,thick]
\tikzstyle{every state}=[fill=mycolor,draw=none,text=white]
\tikzstyle{myarrows}=[line width=1mm,draw=mycolor,-triangle 45,postaction={draw, line width=3mm, shorten >=4mm, -}]
\node[state] (A) {$A$};
\node[state] (B) [below left of=A] {$B$};
\node[state] (C) [below right of=B] {$C$};
\node[state] (D) [below right of=A] {$D$};
\node[state] (E) [above right of=D,xshift=-1cm,yshift=0.6cm] {$E$};
\node[state] (F) [right of=C,yshift=0.3cm,xshift=1cm] {$F$};
\path
(A) edge[above,color=mycolor] node {3} (B)
(B) edge[above,color=mycolor] node {5} (C)
(C) edge[above,color=mycolor] node {2} (D)
(D) edge[color=mycolor] node {1} (E)
edge[above,color=mycolor] node {4} (A);
%\draw [myarrows] (5,-2) -- (6,-2) node [right]{$$};
\end{tikzpicture}
}
}%
\hfill
\subfloat[DDDD]{\label{fig:DDDD}
\resizebox{4cm}{!}{
\begin{tikzpicture}[auto,node distance=2.8cm,thick]
\tikzstyle{every state}=[fill=mycolor,draw=none,text=white]
\tikzstyle{myarrows}=[line width=1mm,draw=mycolor,-triangle 45,postaction={draw, line width=3mm, shorten >=4mm, -}]
\node[state] (A) {$A$};
\node[state] (B) [below left of=A] {$B$};
\node[state] (C) [below right of=B] {$C$};
\node[state] (D) [below right of=A] {$D$};
\node[state] (E) [above right of=D,xshift=-1cm,yshift=0.6cm] {$E$};
\node[state] (F) [right of=C,yshift=0.3cm,xshift=1cm] {$F$};
\path
(A) edge[above,color=mycolor] node {3} (B)
(B) edge[above,color=mycolor] node {5} (C)
(C) edge[above,color=mycolor] node {2} (D)
(D) edge[color=mycolor] node {1} (E)
edge[above,color=mycolor] node {4} (A);
\draw [myarrows] (5,-2) -- (6,-2) node [right]{$$};
\end{tikzpicture}
}
}%
\hfill
\subfloat[DDDD]{\label{fig:DDDD}
\resizebox{4cm}{!}{
\begin{tikzpicture}[auto,node distance=2.8cm,thick]
\tikzstyle{every state}=[fill=mycolor,draw=none,text=white]
\tikzstyle{myarrows}=[line width=1mm,draw=mycolor,-triangle 45,postaction={draw, line width=3mm, shorten >=4mm, -}]
\node[state] (A) {$A$};
\node[state] (B) [below left of=A] {$B$};
\node[state] (C) [below right of=B] {$C$};
\node[state] (D) [below right of=A] {$D$};
\node[state] (E) [above right of=D,xshift=-1cm,yshift=0.6cm] {$E$};
\node[state] (F) [right of=C,yshift=0.3cm,xshift=1cm] {$F$};
\path
(A) edge[above,color=mycolor] node {3} (B)
(B) edge[above,color=mycolor] node {5} (C)
(C) edge[above,color=mycolor] node {2} (D)
(D) edge[color=mycolor] node {1} (E)
edge[above,color=mycolor] node {4} (A);
\draw [myarrows] (5,-2) -- (6,-2) node [right]{$$};
\end{tikzpicture}
}
}%
\hfill
\subfloat[DDDD]{\label{fig:DDDD}
\resizebox{3.4cm}{!}{
\begin{tikzpicture}[auto,node distance=2.8cm,thick]
\tikzstyle{every state}=[fill=mycolor,draw=none,text=white]
\tikzstyle{myarrows}=[line width=1mm,draw=mycolor,-triangle 45,postaction={draw, line width=3mm, shorten >=4mm, -}]
\node[state] (A) {$A$};
\node[state] (B) [below left of=A] {$B$};
\node[state] (C) [below right of=B] {$C$};
\node[state] (D) [below right of=A] {$D$};
\node[state] (E) [above right of=D,xshift=-1cm,yshift=0.6cm] {$E$};
\node[state] (F) [right of=C,yshift=0.3cm,xshift=1cm] {$F$};
\path
(A) edge[above,color=mycolor] node {3} (B)
(B) edge[above,color=mycolor] node {5} (C)
(C) edge[above,color=mycolor] node {2} (D)
(D) edge[color=mycolor] node {1} (E)
edge[above,color=mycolor] node {4} (A);
% \draw [myarrows] (5,-2) -- (6,-2) node [right]{$$};
\end{tikzpicture}
}
}%
\hfill
\caption{Aligning figures in a table}\label{fig:FIGone}
\end{figure}
\end{document}