我想使用 \includepdf 将一些证书添加到我的文档中,并为它们创建某种目录。但是,由于我已经有一个目录,我不想让它们出现,所以我不能依赖添加内容行{toc}{...。
这是我暂时想到的方案,不过不是特别美观,手工活比较多,出错风险也很大。
\documentclass[fontsize=10pt]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{pdfpages}
\newcommand{\includecertificate}[2][1]{%
\includepdf[pages=#1,frame,pagecommand={\label{#2.#1}},scale=0.5]{#2}%
}
\newcommand{\certificateentry}[3][1]{%
\ifthenelse{\equal{#1}{1}}{%
Page \pageref{#2.1}:\quad #3\newline
}{%
Pages \pageref{#2.1}--\pageref{#2.#1}:\quad #3\newline
}}
\begin{document}
\noindent%
\certificateentry[3]{doc1}{Here you find document 1}
\certificateentry[1]{doc2}{Here you find document 2}
\certificateentry[5]{doc3}{Here you find document 3}
\includecertificate[1]{doc1}
\includecertificate[2]{doc1}
\includecertificate[3]{doc1}
\includecertificate[1]{doc2}
\includecertificate[1]{doc3}
\includecertificate[2]{doc3}
\includecertificate[3]{doc3}
\includecertificate[4]{doc3}
\includecertificate[5]{doc3}
\end{document}
第一个命令获取文档的页数、文档名称及其说明。第二个命令获取要加载的页面和文档名称。因此,必须对每个页面单独调用它。我这样做有两个原因:
- 当我加载多页文档时页数=1-5,标签最终出现在最后一页,这显然不是我想要的。
- 因为我更希望(尽管必要时我可以放弃这个想法)让数字显示为页面开始结束, 不只是页面开始。
最后,我更喜欢
\tableofcertificates
\includecertficate[optional page range]{doc1}{Here you find document 1}
\includecertficate{doc2}{Here you find document 2}
\includecertficate{doc3}{Here you find document 3}
有人可以帮助我实现这样的目标吗?
提前谢谢您!
答案1
您可以使用以下方式定义自己的证书列表\DeclareNewTOC
:
\DeclareNewTOC[%
nonfloat,
type=certificate,
listname={List of Certificates}
]{crt}
即使您不使用这些选项定义的环境,也需要选项float
或选项nonfloat
,但您需要一个证书计数器和用于将给定类型的条目添加到证书列表中的命令。
此后,您可以使用例如\addcontentsline{crt}{certificate}{…}
将条目添加到证书列表中。pdfpages
提供addtolist
执行此操作的选项:
\documentclass[fontsize=10pt]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{pdfpages}
\usepackage{mwe}% using the example pdfs of this package
\DeclareNewTOC[%
nonfloat,
type=certificate,
listname={List of Certificates}
]{crt}
\newcommand{\includecertificate}[4]{%
\includepdf[pages=#1-#2,frame,pagecommand={},scale=0.5,addtolist={#1,certificate,#4,crt:#3.start}]{#3}%
}
\begin{document}
\listofcertificates
\includecertificate{1}{3}{example-image-a4-numbered}{Here you find document 1}
\includecertificate{1}{1}{example-image-a4}{Here you find document 2}
\includecertificate{4}{10}{example-image-a4-numbered}{Here you find
document 3}
\end{document}
这已经导致:
但是,如果您想要的是证书列表中的页码范围而不是起始页码,则必须做更多的事情。以下快速破解仅适用于阿拉伯语页码:
\documentclass[fontsize=10pt]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{pdfpages}
\usepackage{mwe}% using the example pdfs of this package
\DeclareNewTOC[%
nonfloat,
type=certificate,
listname={List of Certificates}
]{crt}
\usepackage{refcount}
\makeatletter
\newcommand{\includecertificate}[4]{%
\newpage
\begingroup
\edef\@currentlabel{\the\numexpr\value{page}+#2-#1\relax}%
\label{pgend:\thepage}%
\endgroup
\includepdf[pages=#1-#2,frame,pagecommand={},scale=0.5,addtolist={#1,certificate,#4,crt:#3.start}]{#3}%
}
\BeforeStartingTOC[crt]{%
\renewcommand*{\@pnumwidth}{3em}%
\renewcommand*{\@tocrmarg}{3em}%
\let\crt@contentsline\contentsline
\renewcommand*{\contentsline}[3]{%
\ifnum #3=\getrefnumber{pgend:#3}\relax
\crt@contentsline{#1}{#2}{#3}%
\else
\crt@contentsline{#1}{#2}{#3--\ref{pgend:#3}}%
\fi
}%
}
\begin{document}
\listofcertificates
\includecertificate{1}{3}{example-image-a4-numbered}{Here you find document 1}
\includecertificate{1}{1}{example-image-a4}{Here you find document 2}
\includecertificate{4}{10}{example-image-a4-numbered}{Here you find
document 3}
\end{document}
此解决方案确实可以使用简单的算术来计算页面序列的最后一页页码。但您也可以使用一些标签技巧并使用\protected@immediate@write
来scrlfile
创建一个也适用于非阿拉伯语页码的版本:
\documentclass[fontsize=10pt]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{pdfpages}
\usepackage{mwe}% using the example pdfs of this package
\DeclareNewTOC[%
nonfloat,
type=certificate,
listname={List of Certificates}
]{crt}
\usepackage{refcount}
\makeatletter
\newcommand{\includecertificate}[4]{%
\newpage
\edef\thestartpage{\thepage}%
\includepdf[pages=#1-#2,frame,pagecommand={},scale=0.5,addtolist={#1,certificate,#4,pgstart:\thestartpage}]{#3}%
\begingroup
\addtocounter{page}{-1}%
\let\protected@write\protected@immediate@write% do write labels immediately
\label{pgend:\thestartpage}
\stepcounter{page}%
\endgroup
}
\BeforeStartingTOC[crt]{%
\renewcommand*{\@pnumwidth}{3em}%
\renewcommand*{\@tocrmarg}{3em}%
\let\crt@contentsline\contentsline
\renewcommand*{\contentsline}[3]{%
\typeout{\getpagerefnumber{pgstart:#3}=\getpagerefnumber{pgend:#3}?}%
\ifstr{\getpagerefnumber{pgstart:#3}}{\getpagerefnumber{pgend:#3}}{%
\crt@contentsline{#1}{#2}{#3}%
}{%
\crt@contentsline{#1}{#2}{#3--\pageref{pgend:#3}}%
}
}%
}
\begin{document}
\listofcertificates
\includecertificate{1}{3}{example-image-a4-numbered}{Here you find document 1}
\includecertificate{1}{1}{example-image-a4}{Here you find document 2}
\cleardoublepage\pagenumbering{roman}
\includecertificate{4}{10}{example-image-a4-numbered}{Here you find
document 3}
\end{document}