2

This question is an exact duplicate of:

I am trying to find out how latex decides how to number figures when numbering is done by chapters. My problem is that the numbering of figures within the same chapter is discontinuous, e.g. after figure 2.1 it jumps to figure 2.3 without there being a figure 2.2 (all my figures are numbered). I am not trying to change the numbering to continuous as in Figure 1, Figure 2 etc., I want them numbered by chapters, but I would like to have 2.1 followed by 2.2. What's the problem here? My preamble looks like this:

        \documentclass[12pt,twoside]{report}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\graphicspath{ {Images/} }
\usepackage{caption}
\usepackage{subcaption}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{titlesec}

\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm,bindingoffset=6mm]{geometry}

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancypagestyle{MyStyle}{
    \fancyhead{} %Clean headers
    \fancyhead[LE,RO]{\leftmark}
    \fancyfoot[C]{\thepage}
    \renewcommand{\chaptermark}[1]{\markboth{\MakeUppercase{\thechapter. {\slshape{##1}}}}{}}
    \renewcommand{\headrulewidth}{0.4pt}
    \renewcommand{\footrulewidth}{0.4pt}
}

\usepackage[sorting=none]{biblatex}
\addbibresource{references.bib}

\usepackage{listings}
\usepackage{color}

\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}

\lstdefinestyle{mystyle}{
    backgroundcolor=\color{backcolour},   
    commentstyle=\color{codegreen},
    keywordstyle=\color{magenta},
    numberstyle=\tiny\color{codegray},
    stringstyle=\color{codepurple},
    basicstyle=\scriptsize,
    breakatwhitespace=false,         
    breaklines=true,                 
    captionpos=b,                    
    keepspaces=true,                 
    numbers=left,                    
    numbersep=5pt,                  
    showspaces=false,                
    showstringspaces=false,
    showtabs=false,                  
    tabsize=2
}

\lstset{style=mystyle}

\title{Master report}
\author{J}
\date{7 June 2016}

\titleformat{\chapter}[block]
  {\normalfont\huge\bfseries}{\thechapter.}{1em}{\huge}
\titlespacing*{\chapter}{0pt}{0pt}{20pt}

\begin{document}
\renewcommand{\bibname}{References}

\pagestyle{MyStyle}

\addcontentsline{toc}{chapter}{Abstract}
\addcontentsline{toc}{chapter}{Acknowledgements}
\pagestyle{plain}

\tableofcontents


%\listoftables
\pagestyle{MyStyle}

\chapter{Introduction}
\begin{figure}[h]
\centering
%\includegraphics[scale=0.58]{original_model_picture}
\caption{A schematic of the model}
\subcaption*{\footnotesize{}}
\label{fig:originalmodel}
\end{figure}

\chapter{Methods} \label{Methods}
\section{Changes to the model}

\begin{equation}
    V \propto M=n_r(r+\rho m_r)+n_r(1+\rho)(c_r+zm_r)+\sum_{y \in \{t,m,q\}}(n_r+\rho n_y)(c_y+zm_y)+n_y(y+\rho m_y)
\end{equation}

\begin{equation}
    [a]=\frac{a}{M}, \qquad [s_i]=\frac{s_i}{M}, \qquad [m_y]=\frac{m_y}{M} \qquad \text{etc.}
\end{equation}

\vspace{5mm}

\begin{table}[h]
\centering
\begin{tabular}{l | l}
Variable & Description\\
\hline \hline
\end{tabular}
\caption{List of variables}
\label{tab:variables}
\end{table}

\begin{table}
\centering
\begin{tabular}{l | l | l}
Reaction & Rate & Description\\
\hline \hline

\end{tabular}
\caption{List of reactions and rates}
\subcaption*{\footnotesize{}}
\label{tab:reactions}
\end{table}

\begin{table}
\centering
\begin{tabular}{l | l | l | l }
Parameter & Description & Unit & Value in  \\
\hline \hline
\end{tabular}
\caption{List of parameters}
\label{tab:parameters}
\end{table}

\section{Reactions and their rates}

\begin{equation} \label{eq:vimp}
v_{\text{imp}}=e_t\frac{v_ts}{K_t+s}
\end{equation}

\begin{equation} \label{eq:metabolism}
    v_{\text{cat}}=e_m\frac{v_m[s_i]}{\frac{K_m}{\sigma}+[s_i]}
\end{equation}

\vspace{5mm}

\begin{equation} \label{eq:roleofsigma}
    \sigma k_br[m_y]=k_brm_y\frac{\sigma}{M} \qquad y \in \{t,m,r,q\}
\end{equation}

\begin{equation} \label{eq:translation}
    v_y(c_y,[a])=\frac{c_y}{n_y}\gamma([a]) \qquad y \in \{t,m,r,q\}
\end{equation}

\begin{equation}
    \gamma([a])=\gamma_{max}\frac{[a]}{\frac{K_{\gamma}}{\sigma}+[a]}
\end{equation}

\begin{equation} \label{eq:thresholds}
    w_y([a])=w_y\frac{[a]}{\frac{\theta_y}{\sigma} + [a]} \qquad y \in \{t,m,r\}
\end{equation}

\begin{equation}
    w_q([a])=w_q\frac{[a]}{\frac{\theta_q}{\sigma} + [a]}I([q]) \qquad I([q])=\frac{(\frac{K_q}{\sigma})^{h_q}}{(\frac{K_q}{\sigma})^{h_q}+[q]^{h_q}}
\end{equation}

\section{The role of the transcriptional thresholds $\theta_y$} \label{roleofthresholds}

\begin{figure}
\centering
%\includegraphics[scale=0.8]{relative_transcription_rates}
\caption{Relative transcription rates depend on energy concentration}
\subcaption*{\footnotesize{}}
\label{fig:thresholds}
\end{figure}

\begin{figure}
\centering
%\includegraphics[scale=0.6]{energy_concentration}
\caption{Energy concentration increases exponentially with growth rate}
\subcaption*{\footnotesize{}} 
\label{fig:energyconcentration}
\end{figure}

\appendix
\chapter{Appendices}
\addcontentsline{toc}{section}{Appendix 1 - Full system of ODEs}
\addcontentsline{toc}{section}{Appendix 2 - Cost function for MCMC fitting}

\listoffigures
\vspace{2cm}
\begingroup
\let\clearpage\relax
\listoftables
\endgroup
\addcontentsline{toc}{chapter}{List of Figures and Tables}
\clearpage


\end{document}

Since I did not specify numbering I assume it uses the default by chapters... The list of figures displays: enter image description here

Thanks in advance and apologies if this has been asked before, I could not find it on here.

marked as duplicate by Axel Sommerfeldt, Przemysław Scherwentke, Mensch, Zarko, Stefan Kottwitz Jun 5 '16 at 22:44

This question was marked as an exact duplicate of an existing question.

  • 4
    Please show us the code you use to call the missing figure and table ... – Mensch Jun 4 '16 at 21:00
  • 3
    This could be the result of the recent titlesec bug. Have you updated titlesec? And yes, chapter resets the figure counter. Are you sure you haven't a \stepcounter{figure} in your \caption codes? – user31729 Jun 4 '16 at 21:01
  • 2
    Please provide a complete minimal working example (MWE). Right now, this is neither minimal nor working and cannot be considered as an example since it can't be compiled to reproduce the issue. – cfr Jun 5 '16 at 2:40
  • I updated the MWE, but could not reproduce the figure numbering problem. However the list of tables still shows the same problem: there is no table 2.3. Just to emphasize: all my figures and tables are numbered, and I include them all in the same way via: \includegraphics[scale=1]{figurename} (they are stored in a folder called images) Similarly to the tables, there are no missing tables, the ones shown in the table are all I have, just the numbering is strange. Thanks for the help! – Julius vk Jun 5 '16 at 14:18
  • 1
    What does subcaption do? – Johannes_B Jun 5 '16 at 14:25
5

The error is the usage of \subcaption* outside its own box or environment.

The subcaption manual explicitly states that \subcaption needs a box or an environment, i.e.

\begin{table}
  \begin{minipage}{0.4\textwidth}
   % some content
  \subcaption{Foo}
  \end{minipage}
\end{table}

In principle, it's better to use the subfigure and subtable environments with \caption, to overrule this restriction.

However, \subcaption*{\footnotesize{}} is useless here anyway.

There are some other 'stylistic' issues in the OP code, but I focused on the numbering stuff only.

3

As Christian already mentioned, \subcaption has to be placed inside a group (or a box) since it's very much \caption and therefore interferes with the specific caption type counter. To see how this is a problem, use \subcaption before \caption inside one of your figures.

Depending on the spread of your current non-grouped used of \subcaption, one can fix this using xparse. That is, redefine \subcaption to always be placed inside a group:

enter image description here

\documentclass{article}

\usepackage{subcaption,xparse}

\let\oldsubcaption\subcaption
\RenewDocumentCommand{\subcaption}{s o m}{%
  \begingroup
  \IfBooleanTF{#1}
    {\oldsubcaption*{#3}}
    {\IfValueTF{#2}
       {\oldsubcaption[#2]{#3}}
       {\oldsubcaption{#3}}}%
  \endgroup
}

\begin{document}

\listoffigures

\begin{figure}
  \caption{First figure}
\end{figure}

\begin{figure}
  \caption{Second figure}
  \subcaption*{Second subcaption}
\end{figure}

\begin{figure}
  \caption{Third figure}
\end{figure}

\end{document}
0

I see now. It is the subcaption that increases the counter every time, thanks for pointing that out, Christian. Embedding the \subcaption command in a group or minipage or changing it as Werner suggested did resolve the warning for "subcaption our of box", however the numbering issue remained. The solution for me was to not use the \subcaption command at all (I guess I just misused it in the first place due to lack of knowledge) but instead add subcaptions like this:

\begin{minipage}{\textwidth}
\footnotesize{<description>} 
\end{minipage}

Thanks!

  • 1
    Off-topic: \footnotesize{<description>} verges on being misleading: \footnotesize is a switch and doesn't take an argument; its scope ends with the current group (here: the minipage environment). Better (and certainly clearer) to write \begin{minipage}{\textwidth} \footnotesize <stuff> \end{minipage}. – Mico Jun 5 '16 at 17:56

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