2

I wish to put two pictures side by side using mini page, however, it seems the two pictures even not in the same borderline. enter image description here

Here is my code, I can not figure out what the problem is.

\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
2

One way is to avoid to use minipage. The environment tikzpicture produces a box (Tex's box) and it's possible to place boxes like you want with different tools (baseline,...) you can control the size of the box with useasboundingbox for example. The environment minipage is interesting if you need to place a paragraph side by side with a picture A solution to your problem can be perhaps :

\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}

If necessary you can control the width of each picture.

The boxes are in this case aligned by the bottom but is very easy with baselineto place each box relatively to the baseline. You can also place the second picture relatively to the first with the use of named node.

enter image description here

3
  • it seems to that is better to use the package "here" and the option "H" \begin{figure}[H] – rpapa Apr 8 '13 at 7:44
  • @rpapa Not really sure. I think H is an option for the float package ( float is a fine package perhaps indispensable). H is for <Here, always>, sometimes you get a lot of blank in the page . A possibility for example is to use h <here, if possible> or ht <here or top of the next page if not possible>. Not sure there is an unique way to get a good result. – Alain Matthes Apr 8 '13 at 8:28
  • actually I commented too fast, I did not realize you had deleted the minipage. – rpapa Apr 9 '13 at 16:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.