6

I am using pgfplots to draw plots in memoir. I have a problem for subfigure plots.

\documentclass{memoir}

\usepackage{pgfplots}
\usepackage{tikz}
\usepackage{subfigure}

\begin{document}

\begin{figure}
\centering
\subfigure{
\begin{tikzpicture}
\begin{axis}[grid=major,xmin=0,xmax=1,ymin=0,ymax=0.5]
\addplot[color=black] coordinates {
(0,0.2)
(0.5,0.2)
(1,0)
};
\end{axis}
\end{tikzpicture}}
\subfigure{
\begin{tikzpicture}
\begin{axis}[grid=major,xmin=0,xmax=1,ymin=0,ymax=0.5]
\addplot[color=black] coordinates {
(0,0.5)
(1,0)
};
\end{axis}
\end{tikzpicture}}
\end{figure}

\end{document}

But the code cannot be compiled successfully. Is there anyone know how to modify the code?

5

As a document class, memoir provides the functionality for creating subfloats. As such, using packages that also provide this functionality might cause problems (in general). Here's how you could obtain the desired result by using the interface provided by memoir:

enter image description here

\documentclass{memoir}% http://ctan.org/pkg/memoir
\usepackage{pgfplots,tikz}% http://ctan.org/pkg/{pgfplots,pgf}
\newsubfloat{figure}% Create subfloat in figure environment

\begin{document}

\begin{figure}
  \centering
  \subbottom[First]{%
    \begin{tikzpicture}
      \begin{axis}[grid=major,xmin=0,xmax=1,ymin=0,ymax=0.5]
      \addplot[color=black] coordinates {
        (0,0.2)
        (0.5,0.2)
        (1,0)
      };
      \end{axis}
    \end{tikzpicture}}
  \subbottom[Second]{%
    \begin{tikzpicture}
      \begin{axis}[grid=major,xmin=0,xmax=1,ymin=0,ymax=0.5]
      \addplot[color=black] coordinates {
        (0,0.5)
        (1,0)
      };
      \end{axis}
    \end{tikzpicture}}
\end{figure}

\end{document}

\newsubfloat{<fenv>} creates the appropriate counters/macros for allows subfloats inside <fenv>. \subbottom/\subtop are then used to contain the subfloat with a caption at the bottom/top.

For more detail, read sections 10.3 Multiple floats (p 177) and 10.9 Subcaptions (p 194) or the memoir user manual.

2

The counters \c@lofdepth and \c@lotdepth are defined by subfigure but already defined by memoir, which leads to an error. You can fix it by undefining them before loading subfigure:

\documentclass{memoir}
 ...
\makeatletter
\let\c@lofdepth\relax
\let\c@lotdepth\relax
\makeatother
\usepackage{subfigure}

By the way, I recommend to use the newer subfig package instead, which is from the same author, since subfigure is obsolete. Another very good package for subfigures is subcaption.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.