hyperref 包 - 更改书签的样式 - 添加文本标签

hyperref 包 - 更改书签的样式 - 添加文本标签

使用\hyperref包我想添加这个词章节在章节号之前,如下图所示。例如,我想用“第 1 章:希望它”来代替“1 希望它”。这可能吗?我在下面添加了我的起始代码。

向书签添加文本

启动代码:

\documentclass[]{scrbook}

\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage[]{hyperref}

\hypersetup
{
    hidelinks, % Remove red boxes
    bookmarksnumbered=true,
    pdfauthor={Brian Griffin},
    pdftitle={Wish it, Want it, Do it},
    pdfsubject={Self help},
    pdfkeywords={therapy,healing,chicken soup},
    pdfproducer={Penguin Publishing}
}

\begin{document}

\chapter{Wish It}
What are all the things you want most in the world?

Use the following pages to write down all of your dreams and desires.

\blindtext

\chapter{Want It}    
\blindtext

\chapter{Do It}
\blindtext


\end{document}

答案1

以下技巧重新定义\thechapter输出书签的前缀:

\renewcommand*{\thechapter}{%
  \texorpdfstring{}{\chaptername\space}\arabic{chapter}%
  \texorpdfstring{}{: }%
}

\texorpdfstring仅当字符串准备好用于书签(PDF 字符串)时,才会处理第二个参数。

完整示例:

\documentclass[]{scrbook}

\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage[]{hyperref}

\hypersetup
{
    hidelinks, % Remove red boxes
    bookmarksnumbered=true,
    pdfauthor={Brian Griffin},
    pdftitle={Wish it, Want it, Do it},
    pdfsubject={Self help},
    pdfkeywords={therapy,healing,chicken soup},
    pdfproducer={Penguin Publishing}
}

\renewcommand*{\thechapter}{%
  \texorpdfstring{}{\chaptername\space}\arabic{chapter}%
  \texorpdfstring{}{: }%
}
% Section numbers without prefix or the place for adding a prefix
% "Section".
\renewcommand*{\thesection}{%
  \arabic{chapter}.\arabic{section}%
}

\begin{document}

\tableofcontents

\chapter{Wish It}
What are all the things you want most in the world?

\section{Test section}

Use the following pages to write down all of your dreams and desires.

\blindtext

\chapter{Want It}
\blindtext

\chapter{Do It}
\blindtext

\end{document}

结果

相关内容