1

At Start theorem numbering after the last theorem in another document question I asked how to start theorem numbering after the last theorem in another document.

Now I ask how to do the same for figures: I want to start figure numbering after the last figure in another document. How?

I tried to replace thm with figure everywhere in the answer but this does not work.


Both documents are amsbook like this:

\documentclass[a4paper,oneside,english,reqno]{amsbook}
\begin{document}

...

\begin{figure}[ht]
\caption{\label{...}}
...
\end{figure}

...

\end{document}
  • Can you make a MWE that shows the documentclass and how the figures are numbered? Is the label of the last figure of the first document known? – user36296 Oct 17 '18 at 20:54
  • @samcarter The label of the last figure of the first document is considered not known (I mean that it may change unexpectedly) – porton Oct 17 '18 at 22:01
  • @samcarter an example added – porton Oct 17 '18 at 22:04
2

End the first document with

\addtocounter{figure}{-1}
\refstepcounter{figure}\label{LASTFIGURE}
\end{document}

Then use xr and refcount in the second document. Here's a full example.

File porton-first.tex

\documentclass{article}

\begin{document}

\begin{figure}
\caption{A}
\end{figure}

\begin{figure}
\caption{B}
\end{figure}

\begin{figure}
\caption{C}
\end{figure}

\begin{figure}
\caption{D}
\end{figure}

Some text

\addtocounter{figure}{-1}
\refstepcounter{figure}\label{LASTFIGURE}
\end{document}

File porton-second.tex

\documentclass{article}
\usepackage{xr}
\usepackage{refcount}

\externaldocument{porton-first}

\AtBeginDocument{\setcounter{figure}{\getrefnumber{LASTFIGURE}}}

\begin{document}

\begin{figure}
\caption{X}
\end{figure}

\end{document}

Output of the second file

enter image description here

Caveat

The second file should be compiled only if also the first file has and changes in labels are resolved.

  • I tried to add your code (with added book- prefix because \externaldocument argument) to my actual LaTeX sources (volume-1.tex and addons.tex). This does not work (the numbering starts from one). See github.com/vporton/algebraic-general-topology/tree/… for the exact sources. – porton Oct 17 '18 at 22:35
  • 2
    @porton No, I won't go through a complex tree of documents. Of course, if figures are numbered by chapter, the concept of “restarting the figure number” doesn't make sense. I guess it's a problem of using \include, anyway. – egreg Oct 17 '18 at 22:42
  • Figures are not numbered by chapter – porton Oct 17 '18 at 22:59
  • The weird thing is that it does work for theorem numbers but does not for figure numbers – porton Oct 17 '18 at 23:02

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.