# Loss of figure subsection numbers when using mainmatter

I recently added \frontmatter, \mainmatter, etc. with the \numberwithin setting for my figures and tables into a document, but now my figures are no longer numbered by subsection on export. Inside LyX, they still show the correct numbering, but I lose the subsection number upon export. I am using the memoir package. Here is part of my preamble:

\setsecnumdepth{subsubsection}
\maxtocdepth{subsubsection}
\numberwithin{figure}{subsubsection}
\numberwithin{table}{subsubsection}


All numbering was working before inserting the \...matter statements.

Internally, memoir does

\newcommand\@memmain@floats{%
\counterwithin{figure}{chapter}
\counterwithin{table}{chapter}
}


which means the figures and tables in the main-matter will be numbered subordinated to the chapter counter; to override this, you can add to the preamble

\makeatletter
\renewcommand\@memmain@floats{%
\counterwithin{figure}{subsubsection}
\counterwithin{table}{subsubsection}
}
\makeatother


A complete example:

\documentclass{memoir}
\usepackage{amsmath}

\setsecnumdepth{subsubsection}
\maxtocdepth{subsubsection}
\numberwithin{figure}{subsubsection}
\numberwithin{table}{subsubsection}

\makeatletter
\renewcommand\@memmain@floats{%
\counterwithin{figure}{subsubsection}
\counterwithin{table}{subsubsection}
}
\makeatother

\begin{document}

\mainmatter
\chapter{Test chapter}
\vfill% just for the example
\section{Test section}
\subsection{Test subsection}
\subsubsection{Test subsubsection}
\begin{figure}
\caption{test}
\end{figure}

\end{document}


By the way, since memoir internally uses chngcntr, you can directly use \counterwithin instead of \numberwithin:

\counterwithin{figure}{subsubsection}
\counterwithin{table}{subsubsection}


As a side, personal note, I'd suggest you to reconsidering this numbering schema; having a string so long for the numbers is not very reader-friendly.

• Thank you, Gonzalo. I will try your code. As for the numbering, I'm adapting text from another document that numbered figures/tables by subsection, but it used whole numbers ("105.", "106.") for subsection numbering. – jebersole Jul 16 '13 at 2:16
• @jebersole You're welcome. Don't forget that you can accept the answer (if you consider it solved your problem) by clicking the checkmark to its left. For more information: How do you accept an answer?. – Gonzalo Medina Jul 16 '13 at 12:51