\documentclass[a4paper]{article}
\usepackage[french]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{mathptmx}
\usepackage{pdfpages}
% \usepackage{amssymb}
% \usepackage{amsfonts}
% \usepackage{amsmath}
% \usepackage{graphicx}
\usepackage[margin=1.5cm, left=1.7cm, top=1.2cm, bottom=1.75cm]{geometry}
\begin{document}
% \normalsize logo \hfill \fbox{reçu de versement} \hfill \No :
\includepdf{receipt}
\end{document}
我想要一个重复的模板,其中我动态增加 3 个计数器,如下所述
2 个绿色箭头将始终穿过 001 到 050,之后红色矩形和圆圈中的第二部分将增加 2。
答案1
以下解决方案使用单个计数器receipt
。打印收据后,使用增加计数器\stepcounter{receipt}
。在收据内,您可以使用命令以特殊格式打印计数器的值\TheReceipt
。编号遵循您的方案:第一个数字对于两个连续的收据相同,从 1 到 50。第二个数字在奇数和偶数之间翻转,但其他方面在 50 页内保持不变,然后增加 2。
您的序言中需要以下定义。
\newcounter{receipt}
\newcount\green
\newcount\red
\newcount\tmpa
\newcount\tmpb
\newcommand\TheReceipt{% compute and typeset the numbers
% compute \green and \red from counter receipt
\red=\value{receipt}%
\divide\red by 100
\tmpa=\red
\multiply\tmpa by 100
\green=\value{receipt}%
\advance\green by -\tmpa
\tmpa=\green
\divide\green by 2
\tmpb=\green
\multiply\tmpb by 2
\advance\tmpa by -\tmpb
\multiply\red by 2
\advance\red by \tmpa
\advance\green by 1
\advance\red by 1
% typeset the numbers \green and \red with leading zeros
\ifnum\the\green<100 0\fi
\ifnum\the\green<10 0\fi
\the\green
/%
\ifnum\the\red<1000 0\fi
\ifnum\the\red<100 0\fi
\ifnum\the\red<10 0\fi
\the\red
}
为了说明用法,这里有一个示例代码,可打印虚拟收据,每页两张,共 123 页。
\documentclass{article}
\usepackage[french]{babel}
\usepackage[margin=1.5cm, left=1.7cm, top=1.2cm, bottom=1.75cm]{geometry}
\newcounter{receipt}
\newcount\green
\newcount\red
\newcount\tmpa
\newcount\tmpb
\newcommand\TheReceipt{% compute and typeset the numbers
% compute \green and \red from counter receipt
\red=\value{receipt}%
\divide\red by 100
\tmpa=\red
\multiply\tmpa by 100
\green=\value{receipt}%
\advance\green by -\tmpa
\tmpa=\green
\divide\green by 2
\tmpb=\green
\multiply\tmpb by 2
\advance\tmpa by -\tmpb
\multiply\red by 2
\advance\red by \tmpa
\advance\green by 1
\advance\red by 1
% typeset the numbers \green and \red with leading zeros
\ifnum\the\green<100 0\fi
\ifnum\the\green<10 0\fi
\the\green
/%
\ifnum\the\red<1000 0\fi
\ifnum\the\red<100 0\fi
\ifnum\the\red<10 0\fi
\the\red
}
\newcommand\Receipt{% dummy receipt to demonstrate the use of \TheReceipt
\begin{minipage}{\textwidth}
\hspace*{\fill}%
\fbox{\bfseries REÇU MANUEL DE VERSEMENT}
\hspace*{\fill}%
\makebox[0pt][r]{%
\begin{tabular}[t]{@{}r@{}}
N$^\circ$ \TheReceipt\\
Date: 99/99/9999
\end{tabular}%
}
Begin of form\\[0.4\textheight]
End of form
\end{minipage}%
\stepcounter{receipt}%
}
\newcommand\TwoReceipts{% two receipts with a separator
\clearpage
\Receipt
\vspace{5pt}\par
\dotfill
\vspace{5pt}\par
\Receipt
}
\usepackage{ifthen}% for \whiledo below
\newcounter{pages}
\parindent0pt
\begin{document}
% generate 123 pages, each with two receipts on it
\whiledo{\value{pages}<123}{
\TwoReceipts
\stepcounter{pages}%
}
\end{document}