我希望使用迷你页面将两张图片并排放置,但是,这两张图片似乎甚至不在同一边界上。
这是我的代码,我不知道问题是什么。
\documentclass{article}
\usepackage{tikz}
\begin{figure}[t]
\centering
\begin{minipage}[t]{0.48\linewidth}
\centering
\begin{figure}[H]
\tikzset{
my box/.style = {draw, minimum width = 2em, minimum height=1em},
}
\begin{tikzpicture}[node distance=4mm]
\node[my box,align=center](s1){$S_1$};
\node[my box,align=center,right = of s1](s2){$S_2$};
\draw[->] (s1)--(s2);
\node[align=center,right = 2mm of s2](s){...};
\node[my box,align=center,right = 2mm of s](s3){$S_n$};
\end{tikzpicture}
\label{Before POR}
\end{figure}
\end{minipage}
\begin{minipage}[t]{0.48\linewidth}
\begin{figure}[H]
\tikzset{
my box/.style = {draw, minimum width = 2em, minimum height=1em},
}
\begin{tikzpicture}[node distance=4mm]
\node[my box,align=center](s1){$S_1$};
\node[draw,circle,left = of s1](start){};
\draw[->] (start)--(s1);
\node[draw,diamond,right = of s1](end){};
\draw[->] (s1)--(end);
\draw[->] (end) --++ (0em,1.5em) -| (start);
\node[align=center,above = 1.0em of s1](l){k};
\end{tikzpicture}
\label{After POR}
\end{figure}
\end{minipage}
\end{figure}
\end{document}
答案1
一种方法是避免使用minipage
。环境tikzpicture
会生成一个框(Tex 的框),可以使用不同的工具(基线等)随意放置框,useasboundingbox
例如,您可以使用来控制框的大小。如果您需要将段落与图片并排放置,环境minipage
会很有趣。您的问题的解决方案可能是:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes}
\tikzset{
my box/.style = {draw, minimum width = 2em, minimum height=1em},
}
\begin{document}
\begin{figure}
\hspace*{\fill}\begin{tikzpicture}[node distance=4mm]
\node[my box,align=center](s1){$S_1$};
\node[my box,align=center,right = of s1](s2){$S_2$};
\draw[->] (s1)--(s2);
\node[align=center,right = 2mm of s2](s){...};
\node[my box,align=center,right = 2mm of s](s3){$S_n$};
\node[below] at (current bounding box.south) {label fig one};
\end{tikzpicture}\hspace*{\fill}
\begin{tikzpicture}[node distance=4mm]
\node[my box,align=center](s1){$S_1$};
\node[draw,circle,left = of s1](start){};
\draw[->] (start)--(s1);
\node[draw,diamond,right = of s1](end){};
\draw[->] (s1)--(end);
\draw[->] (end) --++ (0em,1.5em) -| (start);
\node[align=center,above = 1.0em of s1](l){k};
\node[below] at (current bounding box.south) {label fig two};
\end{tikzpicture}\hspace*{\fill}
\caption{Two figures side by-side}
\label{fig:test}
\end{figure}
\end{document}
如果需要,您可以控制每张图片的宽度。
在这种情况下,框按底部对齐,但baseline
将每个框相对于基线放置非常容易。您还可以使用命名节点将第二张图片相对于第一张图片放置。