代码-主文件

代码-主文件

我正在编写一些练习的答案,但在生成的 pdf 文件中生成的书签方面遇到了问题。在我使用的文档中\section(略作修改)和\exercise(基于\subsection) - 我希望这些出现在书签中确切地与文档中显示的方式相同,包括编号。如果没有编号,则\exercise显示为空白书签...

\section我知道我可以使用和命令的可选参数\exercise来手动指定书签中使用的文本,但我想避免这样做!

代码-主文件

\documentclass[answers]{exam}

\addtolength{\textwidth}{1cm}
\addtolength{\hoffset}{-0.5cm}
\addtolength{\textheight}{1cm}
\addtolength{\voffset}{-0.5cm}

\usepackage{xcolor} % Use colour!
\usepackage{titlesec} % Allow creation of new sectioning commands
\usepackage{amsmath} % Needed for splitting equations over multiple lines
\usepackage{ulem} % Underlining effects
\usepackage{environ} % Tinkering with environments
\usepackage{gensymb} % Degree symbol
\usepackage[pdfstartview=FitH,bookmarks=true]{hyperref} 
\usepackage{bookmark} %PDF Bookmarks

\titleformat{\section}{\normalfont\large\bfseries}{Chapter }{0em}{\thesection: }

\titleclass{\exercise}{straight}[\section]  % Create new 'section' command for exercises - this replaces \subsection
\newcounter{exercise}
\titleformat{\exercise}{\normalfont\large\bfseries}{Exercise }{0em}{\theexercise}
\titlespacing*{\exercise}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\newcommand{\exerciseautorefname}{exercise}
\makeatletter
\providecommand*{\toclevel@exercise}{2} % Make sure exercises appear below sections in bookmarks
\makeatother

\pagestyle{headandfoot} % Let's have both
\header{\oddeven{Exercise \theexercise}{Chapter \thesection: \rightmark}}{Core 1}{\oddeven{Chapter \thesection: \rightmark}{Exercise \theexercise}}
\headrule
\footer{\oddeven{}{\thepage}}{}{\oddeven{\thepage}{}}
\footrule

\renewcommand\sectionmark[1]{\markright{#1}} % Set up \rightmark

\begin{document}

\unframedsolutions % Print solutions as plain text
\SolutionEmphasis{\color{blue}} % Print solutions in blue
\renewcommand{\thepartno}{\roman{partno}} % Format part numbers as lower-case roman numerals
\renewcommand\theexercise{\thesection\Alph{exercise}} % Print exercise numbers as 1A, etc...
\renewcommand{\solutiontitle}{\noindent} % Format solution - just print solution as entered
\newcommand{\ans}[1]{\uuline{#1}} % Double underline final answer

\NewEnviron{sol}{ % Align solutions sensibly
    \begin{solution}
        $\begin{aligned}
            \BODY
        \end{aligned}$
    \end{solution}
}

\include{Chapter1}

\end{document}

代码 - Chapter1.tex

\section{Basic Algebra}

\exercise{}
Some text...

答案1

numbered书签按包装选项编号bookmark

\usepackage{bookmark}
\bookmarksetup{numbered}

沒有bookmarkhyperref只有:

\hypersetup{bookmarksnumbered}

添加前缀Chapter可以Exercise通过一个技巧来完成:

\renewcommand*{\thesection}{%
  \texorpdfstring{}{Chapter }%
  \arabic{section}%
  \texorpdfstring{}{:}%
}

\renewcommand*{\theexercise}{%
  \texorpdfstring{}{Exercise }%
  \arabic{section}%
  \Alph{exercise}%
}

相关内容