我想添加两种不同的文本之一,具体取决于它是否出现在最后一页。
我尝试过这个:
\documentclass{article}
\usepackage[angle=0, opacity=1, scale=1,position={0,0}]{background}
\usepackage{lastpage}
\setlength{\parskip}{6cm}
\begin{document}
\SetBgContents{
\ifnum\thepage=\pageref{LastPage} This is the last page\else More pages follow\fi
}
A lot of paragraphs
A lot of paragraphs
A lot of paragraphs
A lot of paragraphs
A lot of paragraphs
A lot of paragraphs
\end{document}
但是当.aux
文件尚未创建时,此操作会失败:
! Missing number, treated as zero. <to be read again> \protect l.22 A lot of paragraphs
我认为是因为那时\pageref{LastPage}
我??
无法用 来进行比较\ifnum
。
我怎样才能让它工作?
答案1
命令\label{mytag}
定义了命令\r@mytag
。这意味着你可以测试该命令是否存在,并做出相应的反应:
\documentclass{article}
\usepackage[angle=0, opacity=1, scale=1,position={0,0}]{background}
\usepackage{lastpage}
\setlength{\parskip}{6cm}
\begin{document}
\makeatletter
\SetBgContents{
\@ifundefined{r@LastPage}{%
RECOMPILE%
}{%
\ifnum\thepage=\pageref{LastPage} This is the last page\else More pages follow\fi
}%
}
\makeatother
A lot of paragraphs
A lot of paragraphs
A lot of paragraphs
A lot of paragraphs
A lot of paragraphs
A lot of paragraphs
\end{document}
答案2
使用包\getpagerefnumber
的命令解决了refcount
:
\usepackage{refcount}
...
\ifnum\thepage=\getpagerefnumber{LastPage} This is the last page\else More pages follow\fi