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}
11
  • The captions have to go into each subfigure environment. Sep 11, 2013 at 21:25
  • @Thorsten Donig how? and how to deal with the labels? thanks
    – misteryes
    Sep 11, 2013 at 21:32
  • @misteryes Please, make a complete example document with the necessary packages, starting from \documentclass and ending with \end{document}. However, your code seems to mean you are using the obsolete subfigure package (and in a wrong way). Note that Thorsten's solution uses subcaption, instead.
    – egreg
    Sep 11, 2013 at 21:52
  • @egreg: For me the subfigure environments indicate that the OP uses already »subcaption«. The »subfigure« package would need the \subfigure command. Sep 11, 2013 at 22:05
  • I have updated the source code
    – misteryes
    Sep 11, 2013 at 22:07

2 Answers 2

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.

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

6
  • I added caption before, pls see the update, but the result is this: s22.postimg.org/dnz0h4l0h/cap.png
    – misteryes
    Sep 11, 2013 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. Sep 11, 2013 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, 2013 at 8:59
  • @misteryes: Install or update the »caption« bundle by the package manager of your TeX distribution. The »subcaption« package is part of that bundle. Sep 12, 2013 at 9:46
  • how to install or update caption in texstudio? thanks
    – misteryes
    Sep 12, 2013 at 14:40

You must log in to answer this question.

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