3

I want to insert to graphs into a paper. I want to make these two graphs arranged like the top 2 graphs in the following pic

example

however, using the following source, I can't see (a) and (b) what are potential problems? thanks!

the source codes are with a IEEEtran.cls

    \documentclass[conference]{IEEEtran}

    \ifCLASSINFOpdf
       \usepackage[pdftex]{graphicx}
       \DeclareGraphicsExtensions{.pdf,.jpeg,.png,.eps}
    \else
       \usepackage[dvips]{graphicx}
       \DeclareGraphicsExtensions{.eps}
    \fi


    \usepackage{lscape}
    %\usepackage{subfigure}
    \usepackage{subcaption}

    \begin{document}

    \title{0000}

    \author{\IEEEauthorblockN{00000}}

    \maketitle
    \end{abstract}

    \IEEEpeerreviewmaketitle

    \section{0000}

      \begin{figure}[!htb]
        \begin{subfigure}[b]{0.45\textwidth}
          \includegraphics[width=.5\linewidth]{pic/loop.png}
          \caption{First}
          \label{subfig-1:dummy}
        \end{subfigure}
        \hfill
        \begin{subfigure}[b]{0.45\textwidth}
          \includegraphics[width=.3\linewidth]{pic/twopath.png}
          \caption{Second}
          \label{subfig-2:dummy}
        \end{subfigure}
        \caption{Dummy figure}
        \label{fig:dummy}
      \end{figure}

    \begin{thebibliography}{1}

    \end{thebibliography}

    \end{document}
misteryes
  • 131

2 Answers2

5

Your error was to use the subfigure package with a wrong syntax; but the subfigure has been obsolete for several years and its author released a successor package, subfig, in 1999.

You have two alternatives. The first is using the more modern subcaption package; here's an example based on your sample code.

\documentclass[conference]{IEEEtran}

\usepackage[demo]{graphicx} % demo is just for this example, remove it
\usepackage{subcaption}

\begin{document}

\title{0000}

\author{\IEEEauthorblockN{00000}}

\maketitle
\begin{abstract}
X
\end{abstract}

\IEEEpeerreviewmaketitle

\section{0000}

\begin{figure}[!htbp]
\centering
\begin{subfigure}[b]{0.5\columnwidth}
\includegraphics[width=\linewidth]{pic/loop.png}
\caption{First}
\label{subfig-1:dummy}
\end{subfigure}\hfill
\begin{subfigure}[b]{0.3\columnwidth}
  \includegraphics[width=\linewidth]{pic/twopath.png}
  \caption{Second}
  \label{subfig-2:dummy}
\end{subfigure}
\caption{Dummy figure}
\label{fig:dummy}
\end{figure}

\end{document}

One important point to note: you can use \columnwidth to set the width of the subfigures and \linewidth in the argument to \includegraphics for using the whole reserved space. Or, for bigger pictures, use \textwidth but in the enclosing figure* environment, that will make a float as wide as the two columns.

enter image description here

The second possibility is with subfig.

\documentclass[conference]{IEEEtran}

\usepackage[demo]{graphicx} % demo is just for this example, remove it
\usepackage{subfig}

\begin{document}

\title{0000}

\author{\IEEEauthorblockN{00000}}

\maketitle
\begin{abstract}
X
\end{abstract}

\IEEEpeerreviewmaketitle

\section{0000}

\begin{figure}[!htbp]
\centering
\subfloat[title1]{\includegraphics[width=.5\linewidth]{pic/loop.png}\label{fig:loop}}\hfill
\subfloat[title2]{\includegraphics[width=.3\linewidth]{pic/twopath.png}\label{fig:twopath}}
\caption{packet structure}
\label{fig:routing}
\end{figure}
\end{document}

The difference is that you don't have to specify a width for the subfloats like with subcaption. The syntax is quite different, as you can see. The output is just the same as before.

egreg
  • 1,121,712
3

You have to put the captions into each of the subfigure environments to get the correct numbering for the sub-figures.

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}

\begin{document}
  \begin{figure}[!htb]
    \begin{subfigure}[b]{0.45\textwidth}
      \includegraphics[width=\linewidth]{example-image-a}
      \caption{First}
      \label{subfig-1:dummy}
    \end{subfigure}
    \hfill
    \begin{subfigure}[b]{0.45\textwidth}
      \includegraphics[width=\linewidth]{example-image-b}
      \caption{Second}
      \label{subfig-2:dummy}
    \end{subfigure}
    \caption{Dummy figure}
    \label{fig:dummy}
  \end{figure}
\end{document}

The image files are available with »mwe« package installed on your system.


enter image description here


Update

Now that the used is class known, the following approach should help.

\documentclass[conference]{IEEEtran}
\usepackage[T1]{fontenc}
\usepackage[demo]{graphicx}  % drop the `demo` option in actual document
\usepackage[belowskip=3pt]{subcaption}

\title{Document title}
\author{\IEEEauthorblockN{Author}}

\begin{document}
  \maketitle
  \IEEEpeerreviewmaketitle

  \section{Foo}

  \begin{figure}[!htb]
    \begin{subfigure}[b]{\columnwidth}
      \centering
      \includegraphics[width=0.5\linewidth]{pic/loop.png}
      \caption{First}
      \label{subfig-1:dummy}
    \end{subfigure}

    \begin{subfigure}[b]{\columnwidth}
      \centering
      \includegraphics[width=0.5\linewidth]{pic/twopath.png}
      \caption{Second}
      \label{subfig-2:dummy}
    \end{subfigure}
    \caption{Dummy figure}
    \label{fig:dummy}
  \end{figure}
\end{document}

enter image description here

  • I added caption before, pls see the update, but the result is this: http://s22.postimg.org/dnz0h4l0h/cap.png – misteryes Sep 11 '13 at 21:48
  • @misteryes: Please take a look at the update I added to my initial answer. It uses the »IEEEtran« class with your settings. – Thorsten Donig Sep 11 '13 at 22:29
  • I'm using texstudio 2.3. I tried your source codes, the result is still as s22.postimg.org/dnz0h4l0h/cap.png. It prompts that there is no subcaption.sty. I downloaded a subcaption.sty and put it in the same folder as the .tex file. But the compilation incurs a lot of errors. – misteryes Sep 12 '13 at 08:59
  • @misteryes: Install or update the »caption« bundle by the package manager of your TeX distribution. The »subcaption« package is part of that bundle. – Thorsten Donig Sep 12 '13 at 09:46
  • how to install or update caption in texstudio? thanks – misteryes Sep 12 '13 at 14:40
  • @misteryes: TeXstudio is only the editor. Your TeX system needs the update. But until now you didn't tell details. Perhaps the answer to this question can help. – Thorsten Donig Sep 12 '13 at 16:19