我使用 minipages 放置了三个图表,但是每两个图表之间的间距宽度不一样。这是代码,有人能帮我吗?如何将 (a) (b) (c) 定位在每个图表上方?
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{
shapes.geometric,
positioning,
fit,
calc
}
\usepackage{scalefnt}
\begin{document}
\begin{figure}[htbp]
\hspace{-4mm}
\begin{minipage}{0.33\linewidth}
\centering
%\includegraphics[width=2.3in]{image/CompositionalStucture}
(a)
\tikzset{
block/.style = {circle, draw,align=center,inner sep=0pt},
line/.style = {draw,->},
}
{\scalefont{0.8}
\begin{tikzpicture}[node distance=15mm]
\node[block,minimum size=6mm] (s2) {1};
\node[block,right of =s2,anchor=center,minimum size=4mm] (s3){2};
\node[block, right of=s2,anchor=center,,minimum size=6mm] (s4) {};
\path[line] (-0.8,0)-- (s2){};
\path[line] (s2)-- node[above]{Err}(s4);
\path[line] (s2) to [out=120,in=40,looseness=5] node[above] {$\Sigma$/Err}(s2);
\path[line] (s4) to [out=120,in=40,looseness=5]node[above] {$\Sigma$}(s4);
\end{tikzpicture}
}
%\red{2}
\end{minipage}
\begin{minipage}{0.33\linewidth}
\centering
%\includegraphics[width=2.3in]{image/CompositionalStucture}
(b)
\tikzset{
block/.style = {circle, draw,align=center,inner sep=0pt},
line/.style = {draw,->},
}
{\scalefont{0.8}
\begin{tikzpicture}[node distance=15mm]
\node[block,minimum size=6mm](s2) {1};
\node[block,right of =s2,anchor=center,minimum size=4mm] (s3){2};
\node[block, right of=s2,anchor=center,minimum size=6mm] (s4) {};
\path[line] (-0.8,0)-- (s2){};
\path[line] (s2)-- node[above]{ru}(s4);
\path[line] (s2) to [out=120,in=40,looseness=5] node[above] {$\Sigma$/ru}(s2);
\path[line] (s4) to [out=120,in=40,looseness=5]node[above] {$\Sigma$}(s4);
\end{tikzpicture}
}
%\red{3}
\end{minipage}
\begin{minipage}{0.33\linewidth}
\centering
%\includegraphics[width=2.3in]{image/CompositionalStucture}
(c)
\tikzset{
block/.style = {ellipse, draw,align=center,inner sep=0pt},
line/.style = {draw,->},
}
{\scalefont{0.8}
\begin{tikzpicture}[node distance=10mm]
\node[align=center](s1) {\ldots};
\node[block,minimum size=3.5mm,below of =s1](s5) {(19,1)};
\node[block,minimum size=3.5mm,below of = s5](s6) {(20,2)};
\path[line] (s1)-- (s5);
\path[line] (s5)-- node[right]{ru}(s6);
\end{tikzpicture}
}
%\red{3}
\end{minipage}
\caption{Monitoring Automata}
\label{fig:monitoringAutomata}
\end{figure}
\end{document}
答案1
不同空间的原因与以下用途有关minipage
:您定义了固定宽度的块,而这些块内的图片不会填满整个块,而是留下不同的空白空间。如果您将小页面放在一个\fbox{...}
块中,就可以看到它们。
你最好看看子字幕包\hspace{dimension}
或者使用如下方式手动定位空格:
\begin{tikzpicture}
% picture A
\end{tikzpicture}
\hspace{5mm}
\begin{tikzpicture}
% picture B
\end{tikzpicture}
编辑:子标题包的使用
\documentclass[a4paper]{article}
\usepackage{subcaption}
\usepackage{tikz}
\usetikzlibrary{
shapes.geometric,
positioning,
fit,
calc
}
\usepackage{scalefnt}
\begin{document}
\begin{figure}[htbp]
\centering
\subcaptionbox{}{
\tikzset{
block/.style = {circle, draw,align=center,inner sep=0pt},
line/.style = {draw,->},
}
\scalefont{0.8}
\begin{tikzpicture}[node distance=15mm]
\node[block,minimum size=6mm] (s2) {1};
\node[block,right of =s2,anchor=center,minimum size=4mm] (s3){2};
\node[block, right of=s2,anchor=center,,minimum size=6mm] (s4) {};
\path[line] (-0.8,0)-- (s2){};
\path[line] (s2)-- node[above]{Err}(s4);
\path[line] (s2) to [out=120,in=40,looseness=5] node[above] {$\Sigma$/Err}(s2);
\path[line] (s4) to [out=120,in=40,looseness=5]node[above] {$\Sigma$}(s4);
\end{tikzpicture}
}
\subcaptionbox{}{
\tikzset{
block/.style = {circle, draw,align=center,inner sep=0pt},
line/.style = {draw,->},
}
\scalefont{0.8}
\begin{tikzpicture}[node distance=15mm]
\node[block,minimum size=6mm](s2) {1};
\node[block,right of =s2,anchor=center,minimum size=4mm] (s3){2};
\node[block, right of=s2,anchor=center,minimum size=6mm] (s4) {};
\path[line] (-0.8,0)-- (s2){};
\path[line] (s2)-- node[above]{ru}(s4);
\path[line] (s2) to [out=120,in=40,looseness=5] node[above] {$\Sigma$/ru}(s2);
\path[line] (s4) to [out=120,in=40,looseness=5]node[above] {$\Sigma$}(s4);
\end{tikzpicture}
}
\subcaptionbox{}{
\tikzset{
block/.style = {ellipse, draw,align=center,inner sep=0pt},
line/.style = {draw,->},
}
\scalefont{0.8}
\begin{tikzpicture}[node distance=10mm]
\node[align=center](s1) {\ldots};
\node[block,minimum size=3.5mm,below of =s1](s5) {(19,1)};
\node[block,minimum size=3.5mm,below of = s5](s6) {(20,2)};
\path[line] (s1)-- (s5);
\path[line] (s5)-- node[right]{ru}(s6);
\end{tikzpicture}
}
\caption{Monitoring Automata}
\label{fig:monitoringAutomata}
\end{figure}
\end{document}
** 编辑 2:** 要将所有图片放在同一行,您可以使用\resizebox{width}{height}{box}
。在下面的示例中,我重新缩放了中间的图片以演示命令的用法。
\documentclass[a4paper]{article}
\usepackage{subcaption}
\usepackage{tikz}
\usepackage{lipsum}
\usetikzlibrary{
shapes.geometric,
positioning,
fit,
calc
}
\usepackage{scalefnt}
\begin{document}
\lipsum[1]
\begin{figure}[h!]
\centering
\resizebox{\linewidth}{!}{%
\subcaptionbox{}{%
\tikzset{
block/.style = {circle, draw,align=center,inner sep=0pt},
line/.style = {draw,->},
}
\scalefont{0.8}
\begin{tikzpicture}[node distance=15mm]
\node[block,minimum size=6mm] (s2) {1};
\node[block,right of =s2,anchor=center,minimum size=4mm] (s3){2};
\node[block, right of=s2,anchor=center,,minimum size=6mm] (s4) {};
\path[line] (-0.8,0)-- (s2){};
\path[line] (s2)-- node[above]{Err}(s4);
\path[line] (s2) to [out=120,in=40,looseness=5] node[above] {$\Sigma$/Err}(s2);
\path[line] (s4) to [out=120,in=40,looseness=5]node[above] {$\Sigma$}(s4);
\end{tikzpicture}
}
\subcaptionbox{}{\scalebox{4}{% For demonstration purpose!
\tikzset{
block/.style = {circle, draw,align=center,inner sep=0pt},
line/.style = {draw,->},
}
\scalefont{0.8}
\begin{tikzpicture}[node distance=15mm]
\node[block,minimum size=6mm](s2) {1};
\node[block,right of =s2,anchor=center,minimum size=4mm] (s3){2};
\node[block, right of=s2,anchor=center,minimum size=6mm] (s4) {};
\path[line] (-0.8,0)-- (s2){};
\path[line] (s2)-- node[above]{ru}(s4);
\path[line] (s2) to [out=120,in=40,looseness=5] node[above] {$\Sigma$/ru}(s2);
\path[line] (s4) to [out=120,in=40,looseness=5]node[above] {$\Sigma$}(s4);
\end{tikzpicture}
}}
\subcaptionbox{}{%
\tikzset{
block/.style = {ellipse, draw,align=center,inner sep=0pt},
line/.style = {draw,->},
}
\scalefont{0.8}
\begin{tikzpicture}[node distance=10mm]
\node[align=center](s1) {\ldots};
\node[block,minimum size=3.5mm,below of =s1](s5) {(19,1)};
\node[block,minimum size=3.5mm,below of = s5](s6) {(20,2)};
\path[line] (s1)-- (s5);
\path[line] (s5)-- node[right]{ru}(s6);
\end{tikzpicture}
}
} % resizebox
\caption{Monitoring Automata}
\label{fig:monitoringAutomata}
\end{figure}
\lipsum[2]
\end{document}
笔记:! 因为高度表示“计算高度以保持纵横比”