IEEEtran 和 TikZ 子图分布在两列上

IEEEtran 和 TikZ 子图分布在两列上

我有多个由 TikZ 生成的图像,我想将它们分布在 2 列上。IEEEtran 文档说我应该使用环境figure来获取分布在 2 列上的图形。我尝试使用图形(pdf 文件),效果很好。当我尝试使用 TikZ 图形做同样的事情时,一切都变得一团糟。

以下是屏幕截图: 在此处输入图片描述

这是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}

答案1

不要在subfigure环境之间留空行;空行是\par为了下一行subfigure开始一个新段落;在子图环境之间你可以发出\hfill,例如,因为环境的总宽度是.9\textwidth

\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}\hfill
    \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:ex2}
    \end{subfigure}\hfill
    \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}

在此处输入图片描述

另外,也许是一种类型,但您正在使用\label{fig:ex3}子图二和三;确保更改其中一个(正如我在示例中所做的那样)以避免重复的标签和不良的副作用。

相关内容