统计报告类别中的图表和引文数量

统计报告类别中的图表和引文数量

我正在使用报告文档类并尝试用于totcount计算图表和参考文献,但存在两个问题:

  1. 每章都会重置图表计数器,因此\total{figure}显示\total{table}0。如何查找整个文档中图表的总数?
  2. totcount计算文档中引用数的解决方案

    \newtotcounter{citesnum}
    \def\oldcite{} \let\oldcite=\cite
    \def\cite{\stepcounter{citesnum}\oldcite}
    

    对我来说不起作用,因为我有多个\cite{}针对单一尊敬的命令。有没有办法解决这个问题?

答案1

您可以使用图形和表格的辅助计数器和补丁\chapteretoolbox例如,使用包)将值\value{figure}(分别为 \value{table})添加到相应的辅助计数器;可以对表格应用类似的过程;然后,在文档末尾再次执行此操作,并将结果写入包含.aux总值的两个宏的文件中:

\documentclass{report}
\usepackage{etoolbox}

\newcounter{totfigures}
\newcounter{tottables}

\providecommand\totfig{} 
\providecommand\tottab{}

\makeatletter
\AtEndDocument{%
  \addtocounter{totfigures}{\value{figure}}%
  \addtocounter{tottables}{\value{table}}%
  \immediate\write\@mainaux{%
    \string\gdef\string\totfig{\number\value{totfigures}}%
    \string\gdef\string\tottab{\number\value{tottables}}%
  }%
}
\makeatother

\pretocmd{\chapter}{\addtocounter{totfigures}{\value{figure}}\setcounter{figure}{0}}{}{}
\pretocmd{\chapter}{\addtocounter{tottables}{\value{table}}\setcounter{table}{0}}{}{}

\begin{document}

\chapter{Test Chapter One}
There are \totfig\ figures and \tottab\ tables in this document.
\begin{figure}FA\caption{test FA}\end{figure}
\begin{table}TA\caption{test TA}\end{table}
\begin{figure}FB\caption{test FB}\end{figure}

\chapter{Test Chapter Two}
\begin{figure}FC\caption{test FC}\end{figure}
\begin{figure}FD\caption{test FD}\end{figure}
\begin{table}TB\caption{test TB}\end{table}
\begin{figure}FE\caption{test FE}\end{figure}

\chapter{Test Chapter Three}
\begin{table}TC\caption{test TC}\end{table}
\begin{figure}FF\caption{test FF}\end{figure}
\begin{table}TD\caption{test TD}\end{table}

\end{document}

在此处输入图片描述

您至少需要运行两次代码。

经过测试,我注意到,出于某种原因,如果某个章节不包含任何图形,计数就会出错。通过附加\setcounter{figure}{0}\pretocmd代码中,我得到了正确的结果。我的猜测是,当当前章节中没有定义任何图形时,图形计数器保存的是上一章的值。不过我可能错了。无论如何,在开始章节时重置计数器不会产生任何意外结果。

答案2

这似乎对我有用:

在此处输入图片描述

\documentclass{report}
% http://texblog.org/2012/04/16/counting-the-total-number-of/
\usepackage{totcount}
\newtotcounter{citenum}
\def\oldcite{}
\let\oldcite=\bibcite
\def\bibcite{\stepcounter{citenum}\oldcite}

\usepackage[figure,table]{totalcount}
% 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

\begin{filecontents}{\jobname.bib}
@article {MCOSW,
author = "Hugh Glaser and Afraz Jafri and Ian Millard",
title = "Managing co-reference on the semantic web",
journal = "WWW2009 Workshop: Linked Data on the Web (LDOW2009)",
month = "April",
year = "April 2009",
}
\end{filecontents}

\begin{document}

\chapter{One}

Some citations: \cite{MCOSW}, \cite{MCOSW}, \cite{MCOSW}.
This document contains \totalfigures{} figures, \totaltables{} tables, and
\total{citenum} reference (possibly with multiple citations).

\begin{table}
\caption{Table caption}
\centering Table content
\end{table}
\begin{figure}
\centering Figure content
\caption{Figure caption}
\end{figure}

\chapter{Two}

\begin{table}
\caption{Table caption}
\centering Table content
\end{table}
\begin{figure}
\centering Figure content
\caption{Figure caption}
\end{figure}

\bibliographystyle{plain}
\bibliography{\jobname}

\end{document}

答案3

totalcount软件包可以轻松处理这个问题

% arara: pdflatex
\documentclass{report}
\usepackage[figure,table]{totalcount}

\begin{document}

\chapter{Test Chapter One}
There are \totalfigures\ figures and \totaltables\ tables in this document.
\begin{figure}FA\caption{test FA}\end{figure}
\begin{table}TA\caption{test TA}\end{table}
\begin{figure}FB\caption{test FB}\end{figure}

\chapter{Test Chapter Two}
\begin{figure}FC\caption{test FC}\end{figure}
\begin{figure}FD\caption{test FD}\end{figure}
\begin{table}TB\caption{test TB}\end{table}
\begin{figure}FE\caption{test FE}\end{figure}

\chapter{Test Chapter Three}
\begin{table}TC\caption{test TC}\end{table}
\begin{figure}FF\caption{test FF}\end{figure}
\begin{table}TD\caption{test TD}\end{table}

\end{document}

相关内容