TransWikia.com

Problem with subcaption package - undefined command

TeX - LaTeX Asked by B Legrand on April 7, 2021

I am currently writing my own document class (which is very inspired by the book class) and I am facing a problem when using the caption and subcaption packages.

Here’s a part of my classemphasized text:

RequirePackage{caption}
RequirePackage{subcaption}

newcounter{figure}

newenvironment{figure}{%
    @float{figure}%
}
{end@float}

renewcommandthefigure{%
    @arabicc@figure%
}

renewcommandthesubfigure{%
    arabic{subfigure}%
}

newcommandfigurename{Fig}

deffps@figure{tbp}
defftype@figure{1}
defext@figure{lof}
deffnum@figure{figurenamenobreakspacethefigure}

DeclareCaptionLabelFormat{format}{textbf{textsc{#1.~#2. -- }}}

captionsetup[figure]{
    name={Fig},
    labelsep=none,
    labelformat=format,
    textformat=simple,
    justification=justified,
    singlelinecheck=true,
    font=footnotesize,
    textfont=it,
    position=bottom,
}

captionsetup[subfigure]{
    name={Fig},
    labelsep=none,
    labelformat=format,
    textformat=simple,
    justification=justified,
    singlelinecheck=true,
    font=footnotesize,
    textfont=it,
    position=bottom,
}

For the simple figures, no problem, everything goes perfectly well. But when I try to insert subfigures I get the following error concerning the document class:

Command thesubfigure undefined

Do you know where this mistake came from? I’ve read the documentation of both packages but I’m not very advanced. . .

This is the first time I write my own document class, it’s quite different from a “classical” use of LaTeX, so please excuse me if my class is a makeshift job. Thanks

PS : Here is link for the document class : MyClass.cls

The figure environment is defined on lines 382 to 410 and the caption on lines 452 to 510.

And here is the link for .tex file : Test.tex

One Answer

  • When loading subcaption, it automatically calls DeclareCaptionSubType{figure} if counter figure is defined.
  • Inside DeclareCaptionSubType{figure},
    • command ext@figure is expanded. (Actually this happens inside the expansion of caption@@@@declaresublistentry, defined in caption3.sty)
    • new counter subfigure is defined, hence the corresponding command thesubfigure is defined.

For counter table, similar things happen.

So the key is to provide counter <float type> and command ext@<float type> before calling DeclareCaptionSubType[*]{<float type>}.

A full example

documentclass{minimal}

newcounter{figure}
newcounter{table}

makeatletter
defext@figure{lof}
defext@table {lot}
makeatother

RequirePackage{subcaption}

renewcommand{thesubfigure}{...}
renewcommand{thesubtable} {...}

begin{document}
abc
end{document}

Answered by muzimuzhi Z on April 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP