Suppose that we have three .tex files in one folder called PhDThesis.tex, Synopsis.tex and conclusion.tex. There is also one bib-file called my_bibio.bib

In Synopsis we have a short description of PhDThesis. The conclusion is added both in Synopsis and in PhD_thesis.

We need to cite in Synopsis some total counts from PhD_thesis:

  1. chapters
  2. references (generated by biber)
  3. figures
  4. tables
  5. pages of full text (the last page of the PhD)
  6. pages of appendix (difference between 1st and last pages)
  7. pages of full text without appendix (the last page of conclusion)

At the same time it would be great to cite some Equations and Propositions in PhDThesis from Synopsis. Hyperref package using is desirable to refer on the PhDThesis from a beamer presentation. Some questions are described here

To avoid some unexpected further difficulties with hyperref I would prefer to see both a variant without hyperref and with this package.

I guess that we can use somehow xr package.

Here is a link about application of this package to cite some labeled equations, propositions e.c.t. It works good in MWE.

Here is a link about totalcount and totcount for counting of total numbers of tables&figures, and references, respectively.

totalcount package works good with xr, however I can not reference total value like \ref{I-totalfigures}, \ref{I-totalpropositions} or \ref{I-totaltables}.

xr package doesn't want to work with totcount package at all! xr-hyperref doesn't want to work either, see please this page

One general solving is described here however I do not prefer to create a great number of counters and to have a complex way of theirs using.

Moreover I can't imagine how to save a difference of two \pagerefs to form a total count of pages in appendix.

Current view of Synopsis with highlighted desirable values of counters. How to fill these values? highlighted desirable values of counters




    %total count of figures and tables
    % works good with xr package, however how to use this with xr package?!
    % different from totcount, and not on CTAN. Found at
    % http://www.mrunix.de/forums/showpost.php?p=257537&postcount=10
    % Reference: http://www.latex-community.org/forum/viewtopic.php?f=5&t=9028


    \chapter{Approaches to the PhD problems} \label{chapt1}

      \caption{First thesis figure} 

        \caption{Second thesis figure} 

        \caption{First thesis table} 

        \caption{Second thesis table} 

    \chapter{The core of PhD thesis} \label{chapt2}

        $A \setminus B = C$

        $A\cup B = C$

    A = \overline{\overline{A}}

    A\cap B = C

    Here we should mention two interesting papers \cite{firstPaper} and \cite{secondPaper}.

    This document contains \totalfigures{} figures, \totaltables{} tables, and
    %\total{citenum} reference (possibly with multiple citations). % does not want to work with xr package



    \chapter{Appendix} \label{AppendixRef}

    This is appendix



    \usepackage{amsmath, amsthm, amssymb}


    %unfortunately hyperref variant does not want to work
    %this example is taken from: https://tex.stackexchange.com/questions/41539/does-hyperref-work-between-two-files
    %\externaldocument[I-]{docPhDThesis}[PhDThesis.pdf]% <- full or relative path 


    Here we need to mention that there are XXX chapters, XXX references, XXX figures, and XXX tables, XXX propositions in PhDThesis. PhDThesis consists of \ref{I-thesis-app-last-page} total pages, and XXX pages of Appendix, and \ref{I-common-concl-last-page} pages without Appendix.

    The following proposition has \ref{I-thesis-prop-cup} number in PhDThesis.

        $A\cup B = C$

    Here we need to mention, that \eqref{syn-eq-cap} equation is equal to equation, which has \eqref{I-common-concl-eq-cap}  number in common conclusion on page \pageref{I-common-concl-eq-cap} in PhDThesis. However the same equation has also \eqref{common-concl-eq-cap} number in common conclusion on page \pageref{common-concl-eq-cap} in Synopsis.

    A\cap B = C




    This is a short description of PhDThesis results. The current part of the text is from the common conclusion of  PhDThesis and Synopsis.

    A\cap B = C



        author = {FirstAuthor, Name},
        title = {Interesting first paper}

        author = {FirstAuthor, Name},
        title = {Interesting second paper}

UPT Finally, I cope with problems in real-life complex tex-file! Many thanks to Heiko Oberdiek, Werner, Piet van Oostrum and Ulrich Diez.

Additionally to this question we discussed a question about total literature counter, a question about saving the values of zref counter on the side of a client tex-file, and a question about counting appendices and chapters

  • 1
    A reasonable question, but not really a minimal working example! :) It would be better if you cut down the files so that they only contain what is necessary to demonstrate the problem and each file should compile. See minimal working example for more details as to what is expected.
    – user30471
    Nov 2, 2016 at 23:35
  • @Andrew I forgot to mention that total counting of references should be compatible with biber. Perhaps, that's why we have some extra code lines, i.e. bib file and some extra code in PhDThesis. Other lines of code seems to be short, even figures and tables are with empty content. Nov 3, 2016 at 13:14

1 Answer 1


Package zref supports user-defined properties, which can added to labels. Module zref-lastpage creates a label LastPage at the end of the document. The properties of this label are managed in a property list LastPage. It contains the page number of the last page. Module zref-abspage adds property abspage, the absolute page number, to LastPage. This serves as total number of pages.

In addition, the following example defines a new property counter with contains the current chapter number. It is added to the property list LastPage and makes the last chapter number available for cross-referencing.

% mybook.tex
\usepackage{zref-abspage, zref-lastpage}


% Label "LastPage" contains the following properties:
% * page: page number of last page
% * abspage: absolute page number
% * chapter: last chapter number


The mybook.aux file contains the label data, as explained above:


Referencing from a different document

Package zref contains module zref-xr for cross-referencing between documents. The .aux file is read by \zexternaldocument with an optional argument as prefix for the imported label names to avoid label name clashes.

\usepackage{zref-xr, zref-user}


The book has \zref[chapter]{book-LastPage} chapters
and \zref[abspage]{book-LastPage} pages.


Further properties

The question contains a long list of properties to be remembered. Example sketches:

  • Figure counting. It heavily depends on, how are figures specified in the document, does they contain a numbered caption per figure, how are they numbered, are there more than one caption in a figure environment. The simplest case are consecutive plainly numbered figures so that the last figure number is also the number of figures. This is implemented as chapter in the example above.

    Otherwise a new figure counter can be created. The figures are then counted by hooking into environment figure or macro \caption or whatever depending on the document. A new property takes the value of this counter than as number of figures for label LastPage.

  • Page ranges. Set a zref label at the begin and end of the interesting document part.

    \usepackage{zref-abspage, zref-user}

    Make sure that the labels go to the correct pages. If the part starts with a chapter, then add the start label right after \chapter to avoid that the label might move to the previous page. The end label could be added at the end of the last paragraph, if there aren't floating objects following, or in the last floating object or at the start of the next page.

    The calculation can be done the following way:

    % Mark labels as used to get LaTeX warnings for changed label values.
    % Calculation, which can be used as property value
      - \zref@extract@default{page-range-begin}{abspage}{0}
      + 1 % if the begin label is on the first and the end label on the last page

I suggest that you make different questions, if you have problems with the counting of some document elements. The links to the followup questions can be added to the corresponding items in this question. IMHO, this makes the questions and answers more clear.

  • @ Heiko, thank you so much for the letter. I'll try to implement your approach for my book and ask you some additional questions. First question is how to reimplement \default value in \zref@newlabel (perhaps, this is not good for me, however I can try) or to reimplement your approach to count chapter numbers. Unfortunately, I have here \default{B}, so the total number of chapters is B for me and this is not true, there are 4 chapters in my book. Nov 3, 2016 at 15:53
  • 1
    @VladimirParkhomenko Ignore the property default in LastPage. It does not serve a purpose here. It contains the value, what \ref would be using and it is not well-defined at this place. For the number of chapters use the property chapter instead. The examples of the answer show how it is defined, assigned and used. Nov 3, 2016 at 15:57
  • @ Heiko, your approach works very well with MWE! Unfortunately almost all my counters in a book were hacked (except for page numbers), i.e. thefigure and other standard counter names do not work. However I can count total number of figures, tables and cites exactly in the same way as it is described here. May we somehow put these values into \zref? Where should we paste the block of code to make calculations of page ranges and how to send the result to another document (article) by means of \zref? Nov 3, 2016 at 22:32
  • 1
    @VladimirParkhomenko I have no idea, what you mean with hacked figure numbers. If you can count the figures, then create a new property \zref@newprop{figure}[0]{<number of figures>} and add it to the label LastPagevia \zref@addprops{LastPage}{figure}. Make a new MWE (new question), which shows, how the figures are counted. Nov 3, 2016 at 22:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .