2

Using \newfloat, new float environments can be created and as exemplified in this post, I created a new float called suppfig but I want to add subfigures in it. When I simply add subfigures inside it I get the message:

No counter subsuppfig defined.

When I add a counter called subsuppfig with \newcounter{subsuppfig} then I get

Illegal unit of measure (pt inserted).

How do I define a new subfloat environment?


Code:

\documentclass{article}
\usepackage{float,subcaption,graphicx}

\begin{document}

\newfloat{suppfig}{tbh}{supp}
\floatname{suppfig}{Supplementary Figure}
\begin{suppfig}[H]
  \centering
  \begin{subfigure}{\textwidth}
    \centering
    \caption{ }
    \includegraphics[width=\textwidth]{example-image-a}
  \end{subfigure}

  \begin{subfigure}{\textwidth}
    \centering
    \caption{ }
    \includegraphics[width=\textwidth]{example-image-b}
  \end{subfigure}
  \caption{...figurecaptions...}
\end{suppfig}
\end{document}
4
  • 1
    It's fine, but next time read the links posted. A minimal example should use images that are available to anyone. Either use the draft package option for graphicx or use some of the images provided by the mwe package.
    – Werner
    May 1 '15 at 18:42
  • @Werner thanks.. I did not know about the mwe package.
    – WYSIWYG
    May 1 '15 at 18:44
  • @Werner Isn't caption necessary for subcaption? I always believed so.
    – WYSIWYG
    May 1 '15 at 19:02
  • 1
    subcaption loads caption. If you look at the subcaption code you'll see a call to \RequirePackage{caption}[..].
    – Werner
    May 1 '15 at 19:06
2

Use package newfloat, a package designed to work well with caption and friends.

\documentclass{article}
\usepackage{newfloat}
\usepackage{subcaption}
\DeclareFloatingEnvironment[name={Supplementary Figure}]{suppfigure}
\begin{document}
\begin{suppfigure}
    \begin{subsuppfigure}{.45\textwidth}
        \centering\rule{.9\linewidth}{2cm}
    \caption{a small supplementary figure}
\end{subsuppfigure}\hfill%
    \begin{subsuppfigure}{.45\textwidth}
        \centering\rule{.9\linewidth}{2cm}
    \caption{another small supplementary figure}
\end{subsuppfigure}
\caption{And a captin for all of them}
\end{suppfigure}
\end{document}
1

subcaption works well (in an automated way) when using newfloat for float creation. However, if you're using float or floatrow, you're going to have to do the legwork yourself.

The following is taken from the subcaption documentation (section 5 The \DeclareCaptionSubType command):

For using the sub-caption feature of the caption package some commands and counters must be prepared. This is done with

\DeclareCaptionSubType[<numbering scheme>]{<type>}
\DeclareCaptionSubType*[<numbering scheme>]{<type>}

For the environments figure & table, and all the ones defined with \DeclareFloatingEnvironment offered by the newfloat package, this will be done automatically, but for other environments (e.g. the ones defined with \newfloat offered by the float package or \DeclareNewFloatType offered by the floatrow package) this has to be done manually.

enter image description here

\documentclass{article}
\usepackage{float,graphicx,subcaption}


\newfloat{suppfig}{tbh}{supp}
\floatname{suppfig}{Supplementary Figure}
\DeclareCaptionSubType{suppfig}
\renewcommand{\thesubsuppfig}{\Alph{subsuppfig}}

\begin{document}

\begin{suppfig}[H]
  \centering
  \begin{subfigure}{\textwidth}
    \centering
    \caption{First subcaption}
    \includegraphics[width=.6\linewidth]{example-image-a}
  \end{subfigure}

  \begin{subfigure}{\textwidth}
    \centering
    \caption{Second subcaption}
    \includegraphics[width=.6\linewidth]{example-image-b}
  \end{subfigure}
  \caption{Figure caption}
\end{suppfig}

\end{document}

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.