[Tex/LaTex] How to create the own caption type with \DeclareCaptionType on memoir class

captionsenvironmentsfloatsmemoir

On the question How to create a box with caption and label like a float?, they teach how to create your own caption with the caption package command \DeclareCaptionType, but it not seems to be working with memoir class: memoir class with subcaption and hyperref packages

Then I tried loading \usepackage{capt-of} instead of caption:

\documentclass[10pt,a5paper,twoside]{memoir}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{capt-of}
\usepackage{graphicx,newfloat}

\DeclareCaptionType{InfoBox}

\begin{document}

    \fboxsep=8pt\relax
    \fboxrule=2pt\relax
    \begin{center}
    \fbox{\centering
      \includegraphics[width=2in]{example-image-A}}\par
      \captionof{InfoBox}{Here is my caption\label{fg:A}}
    \end{center}

    \begin{InfoBox}[ht]
    \centering
    \fbox{\centering\medskip
      \includegraphics[width=2in]{example-image-B}}\par
      \caption{Here is my caption\label{fg:B}}
    \end{InfoBox}

\end{document}

But still creating errors:

test3.tex:9: Undefined control sequence 
Here is how much of TeX's memory you used:
...

On line 14 there is the \DeclareCaptionType command for the caption package. How can it be used with the memoir class?

Best Answer

Based on the questions:

  1. Table of code listings
  2. How to silence memoir class warning against the use of caption package?
  3. How to create a box with caption and label like a float?

You can use the following code for suppressing the warning, as the warning is only documentation on how to use the memoir's class, instead of something you should be fixing.

Class memoir Warning: You are using the caption package with the memoir class. To prepare we will now reset all captioning macros and configurations to kernel defaults, and then let the caption package take over. Please remember to use the caption package interfaces in order to configure your captions.

Noticing know on you need to ignore the caption documentation from the memoir's class and use the caption documentation from the caption package.

\documentclass[10pt,a5paper,twoside]{memoir}

\usepackage{silence}
\WarningFilter*{memoir}{You are using the caption package with the memoir class}

\usepackage{caption}
\DeclareCaptionType{code}[Code Listing][List of Code Listings]

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{capt-of}
\usepackage{listings}

\begin{document}

\listofcodes

    \begin{code}
        \begin{lstlisting}
            Some source code
        \end{lstlisting}
        \caption[This here is a caption]{caption}
    \end{code}

\end{document}

enter image description here