![tcolorbox 的文档库覆盖了 hypersetup](https://linux22.com/image/466780/tcolorbox%20%E7%9A%84%E6%96%87%E6%A1%A3%E5%BA%93%E8%A6%86%E7%9B%96%E4%BA%86%20hypersetup.png)
我正在排版一份文档,我想在彩色框中添加边注,还想控制超链接的颜色。显然,我目前的设置无法同时实现这两个功能,而且我还没有找到解决办法,不过我已经缩小了原因范围。
带框的边注是使用tcolorbox
包(具体来说)生成的\tcbdocmarginnote
,这要求我在序言中加载documentation
库。但是,加载此库也会加载 hyperref 设置,这些设置会覆盖我通过 放入的任何内容hypersetup
。
并排比较我通过注释掉(左)和保留该行得到的结果\tcbuselibrary{documentation}
:
梅威瑟:
\documentclass[dvipsnames,11pt]{article}
\usepackage[marginparwidth=4.5cm, inner=2cm, outer=5cm, marginparsep=4mm, bottom=3cm, top=2cm]{geometry}%
\usepackage{xcolor}
\definecolor{HintColor}{RGB}{59, 189, 236}
\usepackage{marginnote} % Make room for margin notes
\usepackage[many]{tcolorbox}
%% Commenting out this line uses the hypersetup colors. Leaving it in yields an option clash with the hyperref package.
% \tcbuselibrary{documentation}
\tcbuselibrary{theorems}
\newcommand{\MarBox}[3][]{
\tcbdocmarginnote[
floatplacement=htb,
box align=center,
title=#3,
width=4.2cm,
left=1.5mm,
right=1.5mm,
top=1.5mm,
bottom=1.5mm,
fontupper=\small,
fonttitle=\bfseries\color{White},
colframe=#2!70,
colback=#2!10]
#1
}
\newcommand{\Hint}[1][]{
\MarBox[#1]{HintColor}{Hint}
}
\usepackage[colorlinks]{hyperref}
\hypersetup{%
breaklinks,
colorlinks=true,
citecolor=yellow,
linkcolor=green,
anchorcolor=blue,
urlcolor=red,
filecolor=magenta,
pdfauthor={AUTHOR},
pdftitle={TITLE}}
\usepackage[nameinlink]{cleveref}
\begin{document}
\title{Clash}
\author{}
\date{}
\maketitle
\setcounter{secnumdepth}{1}
This URL link and the hyperlink in the table of contents should be different colors: \href{https://stackexchange.com/}{Stack Exchange}.
\tableofcontents
\section{This is the wrong color}
I can either get this box, or the right color on the hyperlinks, but not both. \Hint{I can't print this without also overriding the hypersetup colors.}
\end{document}
答案1
tcolorbox 在开始文档时设置颜色,因此您必须延迟一些设置:
\usepackage{hyperref}
\hypersetup{colorlinks}
\AtBeginDocument{
\hypersetup{%
citecolor=yellow,
linkcolor=green,
anchorcolor=blue,
urlcolor=red,
filecolor=magenta,
pdfauthor={AUTHOR},
pdftitle={TITLE}}}