我希望使用迷你頁面並排放置兩張圖片,但是,似乎兩張圖片甚至不在同一邊界上。
這是我的程式碼,我無法弄清楚問題是什麼。
\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
每個框相對於基線放置。您也可以使用命名節點將第二張圖片相對於第一張圖片放置。