I have multiple images produced by TikZ and I want to span them on 2 columns.
The IEEEtran documentation says that I should use the figure
environment to get figures spanning 2 columns. I tried it with graphics (pdf files) and it works perfectly. When I try to do the same thing with TikZ graphics, everything gets messed up.
Here's a screenshot:
Here's the MWE:
\documentclass[conference]{IEEEtran}
\usepackage{hyperref}
\usepackage{cite}
\usepackage{algorithmic}
\usepackage{paralist}
\usepackage{fixltx2e}
\usepackage{varwidth}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes, calc, fit, positioning}
\usepackage{pgfplots}
\usepackage{graphicx}
\graphicspath{{./gfx/}}
\DeclareGraphicsExtensions{.pdf,.jpeg,.png}
\usepackage[cmex10]{amsmath} %[cmex10]
\usepackage{url}
\begin{document}
\title{My Title}
\author{\IEEEauthorblockN{Authors list}
\IEEEauthorblockA{My Institution}}
\maketitle
\begin{figure*}
%\centering
\begin{subfigure}[b]{.3\textwidth}
\centering
\begin{tikzpicture}[transform shape]
\node[circle, fill=gray!30] (P1) at (1,2) {$P_1$};
\node[circle, fill=gray!30] (P2) at (2,1) {$P_2$};
\node[circle, fill=gray!30] (P3) at (1,0) {$P_3$};
\node[circle, fill=gray!30] (P4) at (0,1) {$P_4$};
\node[circle, fill=gray!30] (P5) at (1,1) {$P_5$};
\node[circle, fill=gray!30] (P6) at (3,1) {$P_6$};
%links
\draw[-] (P5) -- (P1);
\draw[-] (P5) -- (P2);
\draw[-] (P5) -- (P3);
\draw[-] (P5) -- (P4);
\draw[-] (P2) -- (P6);
%dashed rectangles
\node (B1) [draw=red, dashed, thick, fit= (P1) (P2) (P3) (P4) (P5), rounded corners] {};
\node [yshift=-1.5ex, red] at (B1.south) {};
\node (B2) [draw=blue, dashed, thick, fit= (P2) (P5) (P6), rounded corners] {};
\node [yshift=-1.5ex, blue] at (B2.south east) {}; %yshift=-3.0ex,
\end{tikzpicture}
\caption{Example 1}
\label{fig:ex1}
\end{subfigure}
\begin{subfigure}[b]{.3\textwidth}
\centering
\begin{tikzpicture}[transform shape]
\node[circle, fill=gray!30] (P1) at (1,2) {$P_1$};
\node[circle, fill=gray!30] (P2) at (2,1) {$P_2$};
\node[circle, fill=gray!30] (P3) at (1,0) {$P_3$};
\node[circle, fill=gray!30] (P4) at (0,1) {$P_4$};
\node[circle, fill=gray!30] (P5) at (1,1) {$P_5$};
\node[circle, fill=gray!30] (P6) at (3,1) {$P_6$};
%links
\draw[-] (P5) -- (P1);
\draw[-] (P5) -- (P2);
\draw[-] (P5) -- (P3);
\draw[-] (P5) -- (P4);
\draw[-] (P2) -- (P6);
%dashed rectangles
\node (B1) [draw=red, dashed, thick, fit= (P1) (P2) (P3) (P4) (P5), rounded corners] {};
\node [yshift=-1.5ex, red] at (B1.south) {};
\node (B2) [draw=blue, dashed, thick, fit= (P2) (P5) (P6), rounded corners] {};
\node [yshift=-1.5ex, blue] at (B2.south east) {}; %yshift=-3.0ex,
\end{tikzpicture}
\caption{Example 2}
\label{fig:ex3}
\end{subfigure}
\begin{subfigure}[b]{.3\textwidth}
\centering
\begin{tikzpicture}[transform shape]
\node[circle, fill=gray!30] (P1) at (1,2) {$P_1$};
\node[circle, fill=gray!30] (P2) at (2,1) {$P_2$};
\node[circle, fill=gray!30] (P3) at (1,0) {$P_3$};
\node[circle, fill=gray!30] (P4) at (0,1) {$P_4$};
\node[circle, fill=gray!30] (P5) at (1,1) {$P_5$};
\node[circle, fill=gray!30] (P6) at (3,1) {$P_6$};
%links
\draw[-] (P5) -- (P1);
\draw[-] (P5) -- (P2);
\draw[-] (P5) -- (P3);
\draw[-] (P5) -- (P4);
\draw[-] (P2) -- (P6);
%dashed rectangles
\node (B1) [draw=red, dashed, thick, fit= (P1) (P2) (P3) (P4) (P5), rounded corners] {};
\node [yshift=-1.5ex, red] at (B1.south) {};
\node (B2) [draw=blue, dashed, thick, fit= (P2) (P5) (P6), rounded corners] {};
\node [yshift=-1.5ex, blue] at (B2.south east) {}; %yshift=-3.0ex,
\end{tikzpicture}
\caption{Example 3}
\label{fig:ex3}
\end{subfigure}
\end{figure*}
\end{document}
Best Answer
Don't leave blank lines between the
subfigure
environments; a blank line is\par
so the nextsubfigure
will start a new paragraph; between the subfigure environments you can issue\hfill
, for example, since the total width of the environments is.9\textwidth
:Also, perhaps a type, but you are using
\label{fig:ex3}
for subfigures two and three; make sure to change one of them (as I did in my example) to avoid duplicated labels and undesired side-effects.