1

I use the subfigure to put two figures together, however they are not centered.

Below is my code:

\documentclass[10pt]{IEEEtran}
\usepackage{tikz}
\usetikzlibrary{
    shapes.geometric,
    positioning,
    fit,
    calc
}

\usepackage{caption}
\usepackage{subcaption}
\begin{document}
\begin{figure}[t]
\centering
\begin{subfigure}[b]{0.24\textwidth}
\centering
\begin{tikzpicture}[
 block/.style = {circle, draw,
    text width=1em,align=center,inner sep=0pt},
    line/.style = {draw,thick, -latex},
  service/.style={align=left, text width=0.5cm},
node distance=1.0cm and 0.4cm
]

% Place nodes
\node[block](s0){$0$};
\node[service, right of= s0, xshift=10mm, text width=3cm](s10){};
\node[block, below of = s0](s1){$1$};
\node[block, below of =s1](s2){$2$};
\node[block, right of =s2] (s3){$3$};
\node[block, below of =s2] (s4){$4$};
\path [line] (s0)--(s1);
\path [line] (s1)--(s2);
\path [line]  (s1)-|(s3);
\path [line] (s2)--(s4);
\end{tikzpicture}
\caption{1}
\label{fig:workflowsim}
\end{subfigure}
\begin{subfigure}[b]{0.24\textwidth}
\centering
\begin{tikzpicture}[
 block/.style = {circle, draw,
    text width=1em,align=center,inner sep=0pt},
line/.style = {draw,thick, -latex},
  service/.style={align=left, text width=0.5cm},
node distance=1.0cm and 0.4cm
]

% Place nodes
\node[block](s2){$0$} ;
\node[service, right of=s2,xshift=10mm, text width=3cm](s10){};
\node[block, below of =s2] (s4){$4$};
\node[block, below of =s4] (s6){$6$};
\node[block, right of =s6] (s7){$S7$};
\path [line] (s2)--(s4);
\path [line] (s4)--(s6);
\path [line] (s4)-|(s7);
\end{tikzpicture}
\caption{2}
\end{subfigure}
\caption{3}
\end{figure}
\end{document}

And it shows me the figure as below enter image description here

As you can see the left figure is not on top of a(1) (the caption), it is left-align. It is similar to the right figure.

How could I resolve this?

4
  • 2
    Try to comment node s10.
    – Astrinus
    Dec 19, 2014 at 14:37
  • Put an fbox around the tikzpicture. \fbox{<wholeTikz Env>}. You are setting the width of the nodes reserving space on the right hand side.
    – Johannes_B
    Dec 19, 2014 at 14:38
  • @Johannes_B if put \fbox, still cannot work
    – sweetyBaby
    Dec 19, 2014 at 14:47
  • @sweetyBaby Wasn't suppose to work. It should merely show that the picture is centered, but that an invisible node made it look uncentered. ;-)
    – Johannes_B
    Dec 19, 2014 at 14:55

1 Answer 1

1

There's a node which affects the centering, even if it's not visible.

  • If you don't need the node, remove it.
  • If you would like to keep the node, add the overlay option so it won't take space:

    \node[overlay, service, right of= s0, xshift=10mm, text width=3cm] (s10) {};
    

This overlay method is similarly useful for removing such an undesired shifting effect of arrows, so the space they cover won't count.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .