(这个问题与在章节标题中使用 totcount 包的 \total)
我想跟踪我审阅的论文,并且我编写了一个代码(如下所示的 MWE)。该代码会记录来自不同期刊的论文数量,然后计算期刊和会议论文总数和待审论文数量,如代码后的屏幕截图所示。
\documentclass[11pt,landscape]{article}
\usepackage[margin=.5in,top=0.75in]{geometry}
\usepackage{booktabs}
\usepackage[table,dvipsnames]{xcolor}
\definecolor{AleeRed}{rgb}{0.5,0,0}
\usepackage[colorlinks=true,
linkcolor=AleeRed,
pdfborder={0 0 0}]{hyperref}
\usepackage{etoolbox}
\usepackage{totcount}
\newtotcounter{TPWRD}\newtotcounter{TPWRDpending}
\newtotcounter{TPWRS}\newtotcounter{TPWRSpending}
\newtotcounter{APEC}\newtotcounter{APECpending}
\newcommand{\duedate}[2]{\stepcounter{#2}\color{magenta} Due: #1}
\let\oldsubsection\subsection
\renewcommand{\subsection}[3]{%
\oldsubsection{#1%
~\texorpdfstring{(\protect\total{#2})}{}%
\ifnumcomp{\totvalue{#3}}{=}{0}%
{}%
{~\texorpdfstring{\fbox{Pending:~\protect\total{#3}}}{}}}%
}
\newcounter{reversedummy}
\newcounter{reversecounter}
\newenvironment{articlelist}[1]{% Don't show counter for the first row, which is the title row
\setcounter{reversedummy}{0}
\begin{center}\small
\rowcolors{2}{white}{gray!35}
\begin{tabular}{%
c<{\ifnumcomp{\value{reversedummy}}{=}{0}% Show decreasing counter
{}% Don't show counter for the title row
% Calculate the reverse counter as total-i+1
{\defcounter{reversecounter}{\totvalue{#1}-\value{reversedummy}+1}\arabic{reversecounter}}%
\stepcounter{#1}\stepcounter{reversedummy}}% Increment total papers, i
p{3.8cm} p{12cm} m{3.5cm} p{3.4cm}}
\toprule
No & ID & Title & My Decision (Date) & Decision (Date) \\
\midrule
}
{ \bottomrule
\end{tabular}
\end{center}
}
\begin{document}
% Prepare counters
\newcounter{JournalsTotal}\defcounter{JournalsTotal}{\totvalue{TPWRD} + \totvalue{TPWRS}}
\newcounter{JPendingsTotal}\defcounter{JPendingsTotal}{\totvalue{TPWRDpending} + \totvalue{TPWRSpending}}
\newcounter{ConferencesTotal}\defcounter{ConferencesTotal}{\totvalue{APEC}}
\newcounter{CPendingsTotal}\defcounter{CPendingsTotal}{\totvalue{APECpending}}
\newcounter{PapersTotal}\defcounter{PapersTotal}{\value{JournalsTotal} + \value{ConferencesTotal}}
\newcounter{PendingsTotal}\defcounter{PendingsTotal}{\value{JPendingsTotal} + \value{CPendingsTotal}}
\begin{center}
\textbf{\Large Reviewed Papers}\\
Last Updated \today; Last Count \thePapersTotal; Pending \thePendingsTotal.
\end{center}
\tableofcontents
\section{Journals (\theJournalsTotal)}
\subsection{IEEE Transactions on Power Delivery}{TPWRD}{TPWRDpending}
\begin{articlelist}{TPWRD}
&
TPWRD-000-2011 &
Pizza delivery vs. power delivery: top 10 differences you always missed &
\duedate{3-May-2012}{TPWRDpending} &
\\
&
TPWRD-001-2011.R1 &
Recent advances in the IEEE website &
Reject (24-Mar-2012) &
Reject (22-Apr-2012)
\\
\end{articlelist}
\subsection{IEEE Transactions on Power Systems}{TPWRS}{TPWRSpending}
\begin{articlelist}{TPWRS}
&
TPWRS-001-2012 &
How to have your own DYI power system &
\duedate{18-May-2012}{TPWRSpending} &
\\
&
TPWRS-002-2011.R1 &
How power corrupts any system, including power system itself &
Revise (15-Mar-2012) &
Revise (12-Apr-2012)
\\
\end{articlelist}
\section{Conferences (\theConferencesTotal)}
\subsection{APEC 2012}{APEC}{APECpending}
\begin{articlelist}{APEC}
&
APEC-000 &
Divide and conquer: How to produce two conferences out of one &
Accept (23-Aug-2011) &
\\
\end{articlelist}
\addtocounter{TPWRD}{-1}
\addtocounter{TPWRS}{-1}
\addtocounter{APEC}{-1}
\end{document}
该代码完成了我需要它做的事情,但是有两点我不喜欢我的代码:
- 当我拨打电话时,我必须手动包含“待处理”计数器
\duedate
。 - 我必须在代码的最后手动减少计数器。
也许我可以在环境定义的最后部分使用\NewDocumentEnvironment
并包含\addtocounter{#1}{-1}
来解决第二个问题。但我不知道如何解决第一个问题。“待处理”计数器信息已传递给\begin{articlelist}
。
有什么方法可以修改\duedate
以便可以使用的参数\begin{articlelist}
?我也欢迎任何改进代码的建议。
答案1
您可以将计数器的名称“保存”在\subsection
:
\newcommand\pendingcountername{}
\renewcommand{\subsection}[3]{%
\renewcommand\pendingcountername{#3}%
...
进而
\newcommand{\duedate}[1]{\stepcounter{\pendingcountername}\color{magenta} Due: #1}
这就是你要找的东西吗?
答案2
你可以在环境\duedate
中重新定义articlelist
。
\newenvironment{articlelist}[1]{%
\renewcommand{\duedate}[1]{\stepcounter{#1pending}\color{magenta} Due: ##1}
.... rest of environment ....
现在你\duedate
只用一个参数来调用(但是仅有的在环境中articlelist
),相应的计数器将会增加。
笔记
- 正如 Stephan Lehmke 指出的那样,在
\renewcommand{\duedate}
第一次使用中#1
, 指的是环境的参数articlelist
,但第二次使用需要引用参数\duedate
,因此需要##
。