当我运行此代码时,出现错误:
“!LaTeX 错误:包 hyperref 的选项冲突。”
代码
\documentclass[11pt,a4paper]{moderncv}
\moderncvtheme[green]{classic}
\usepackage[scale=0.8]{geometry}
\AtBeginDocument{\recomputelengths}
\firstname{Rob}
\familyname{Ward}
\mobile{mobile +64 21 0377 936}
\phone{phone +64 6 212 0549}
\email{[email protected]}
\homepage{www.robward.co.nz}
\usepackage[pdftex,
pdfauthor={Rob Ward},
pdftitle={CV for Rob Ward},
pdfsubject={Detailed CV for Rob},
urlcolor={blue}]{hyperref}
\begin{document}
% EDUCATION
\section{Education}
\cventry{2006--2011}{PhD physics/biophysics}{Massey University}{Palmerston North}{New Zealand}{} % arguments 3 to 6 can be left empty
\cventry{1999--2004}{BSc (hons.) physics}{Victoria University}{Wellington}{New Zealand}{}
\cventry{1999--2002}{BSc mathematics}{Victoria University}{Wellington}{New Zealand}{}
\cventry{1988--1989}{NCEE}{Central Institute of Technology}{Wellington}{New Zealand}{}
\end{document}
答案1
更新: moderncv
hyperref
用自己的 自行加载包hypersetup
。从moderncv.cls
,
因此,您无需hyperref
再次加载。但请像以下代码一样加载hypersetup
using \AfterPreamble
(或) 钩子:\AtBeginDocument
\documentclass[11pt,a4paper]{moderncv}
\moderncvtheme[green]{classic}
\usepackage[scale=0.8]{geometry}
\AtBeginDocument{\recomputelengths}
\firstname{Rob}
\familyname{Ward}
\mobile{mobile +64 21 0377 936}
\phone{phone +64 6 212 0549}
\email{[email protected]}
\homepage{www.robward.co.nz}
\AfterPreamble{\hypersetup{
pdfauthor={Rob Ward},
pdftitle={CV for Rob Ward},
pdfsubject={Detailed CV for Rob},
urlcolor=blue,
}}
\begin{document}
% EDUCATION
\section{Education}
\cventry{2006--2011}{PhD physics/biophysics}{Massey University}{Palmerston
North}{New Zealand}{} % arguments 3 to 6 can be left empty
\cventry{1999--2004}{BSc (hons.) physics}{Victoria
University}{Wellington}{New Zealand}{}
\cventry{1999--2002}{BSc mathematics}{Victoria University}{Wellington}{New
Zealand}{}
\cventry{1988--1989}{NCEE}{Central Institute of Technology}{Wellington}{New
Zealand}{}
\end{document}
pdf 属性将如下所示:
早期尝试:
\PassOptionsToPackage{pdftex,
pdfauthor={Rob Ward},
pdftitle={CV for Rob Ward},
pdfsubject={Detailed CV for Rob},
urlcolor={blue}}{hyperref}
\documentclass[11pt,a4paper]{moderncv}
\moderncvtheme[green]{classic}
\usepackage[scale=0.8]{geometry}
\AtBeginDocument{\recomputelengths}
\firstname{Rob}
\familyname{Ward}
\mobile{mobile +64 21 0377 936}
\phone{phone +64 6 212 0549}
\email{[email protected]}
\homepage{www.robward.co.nz}
%\usepackage[pdftex,
% pdfauthor={Rob Ward},
% pdftitle={CV for Rob Ward},
% pdfsubject={Detailed CV for Rob},
% urlcolor={blue}]{hyperref}
\begin{document}
% EDUCATION
\section{Education}
\cventry{2006--2011}{PhD physics/biophysics}{Massey University}{Palmerston North}{New Zealand}{} % arguments 3 to 6 can be left empty
\cventry{1999--2004}{BSc (hons.) physics}{Victoria University}{Wellington}{New Zealand}{}
\cventry{1999--2002}{BSc mathematics}{Victoria University}{Wellington}{New Zealand}{}
\cventry{1988--1989}{NCEE}{Central Institute of Technology}{Wellington}{New Zealand}{}
\end{document}
笔记:注意到 Heiko Oberdiek 的评论,
为了支持书签字符串和 PDF 文件信息字典条目中的非 ASCII 内容,hyperref 包进行了大量重新定义。如果 LaTeX 在 hyperref 有机会看到这些选项之前就以困难的方式扩展这些选项,则大部分支持都会丢失。因此,最好在加载 hyperref 后设置信息条目。
这并不总是可取的。在这种情况下,它不会产生预期的结果,因为稍后会被自身hypersetup
覆盖moderncv
。
答案2
在这种情况下,可以通过以下方式解决:
\usepackage{hyperref}
\hypersetup{
pdfauthor={...},
pdftitle={...},
pdfsubject={...},
urlcolor=blue,
}
PDF 信息字典的条目最好在软件包加载后设置。其他条目(urlcolor
)也可以在之后设置。pdftex
不需要,hyperref
自动检测 PDF 模式下的 pdfTeX。
解决选项冲突的通用方法是 -\PassOptionsToPackage
在第一次加载包之前。 - 在第一次加载包时添加所需的所有选项(如果包是间接加载的,则并不总是可行的)。
完整示例
\documentclass[11pt,a4paper]{moderncv}
\moderncvtheme[green]{classic}
\usepackage[scale=0.8]{geometry}
\AtBeginDocument{\recomputelengths}
\firstname{Rob}
\familyname{Ward}
\mobile{mobile +64 21 0377 936}
\phone{phone +64 6 212 0549}
\email{[email protected]}
\homepage{www.robward.co.nz}
\usepackage{hyperref}
\hypersetup{
pdfauthor={Rob Ward},
pdftitle={CV for Rob Ward},
pdfsubject={Detailed CV for Rob},
urlcolor=blue,
}
\begin{document}
% EDUCATION
\section{Education}
\cventry{2006--2011}{PhD physics/biophysics}{Massey University}{Palmerston
North}{New Zealand}{} % arguments 3 to 6 can be left empty
\cventry{1999--2004}{BSc (hons.) physics}{Victoria
University}{Wellington}{New Zealand}{}
\cventry{1999--2002}{BSc mathematics}{Victoria University}{Wellington}{New
Zealand}{}
\cventry{1988--1989}{NCEE}{Central Institute of Technology}{Wellington}{New
Zealand}{}
\end{document}
我没有遇到任何选项冲突。