修复使用 hyperref 创建的文档结构

修复使用 hyperref 创建的文档结构

我是 Latex 的新手,尝试使用它来准备一份复杂的工业文档(实验室测试报告)。此文档包含许多测试组,我发现使用组号对每个组的测试结果部分(以及表格和图表)进行编号对作者和读者来说都很方便。我设法找到了一种适合我需要的方法。但是,当我使用带星号的章节版本时,生成的 .pdf 文档的结构会发生改变,在所附的样本中,“测试结果”一章显示为第 1 节的分支,而不是与其他章节处于同一级别... 有没有办法纠正此行为?谢谢。

\documentclass[a4paper, oneside,11pt, english]{report} % Mode production
\usepackage[utf8]{inputenc} % UTF-8 encoding for code editing
\usepackage[T1]{fontenc} % Usual fonts
\usepackage{tgheros,textcomp}% Fonts
\usepackage{lastpage} % Handling last page numbering 
\usepackage{hyperref} %enabling hyper references

% --[SECTION NUMBERING FIRST PAGES]---------------------------------
\renewcommand{\thesection}{\arabic{section}}
\renewcommand{\thetable}{\Alph{table}}
\renewcommand{\thefigure}{\Alph{figure}}
%  --[END SECTION NUMBERING FIRST PAGES]---------------------------------
\renewcommand{\familydefault}{\sfdefault}%selecting default font (clone of helvetica)

\begin{document}

\tableofcontents %  [CREATING TABLE OF CONTENTS]---

\chapter*{Summary of test results}
\addcontentsline{toc}{chapter}{Summary of test results}
A table.

\chapter*{Test specimen}
\addcontentsline{toc}{chapter}{Test specimen}
\section{section 1}
Some text.
\section{Section 2}
Some text.

 \chapter*{Test results}
\addcontentsline{toc}{chapter}{Test results}

%-[BEGIN ASSOCIATE TABLE AND FIGURE NR TO SECTION NR]----
\makeatletter 
\renewcommand{\thefigure}{\ifnum \c@section>\z@ \thesection.\fi 
\@arabic\c@figure} 
\@addtoreset{figure}{section} \makeatother 
\makeatletter 
\renewcommand{\thetable}{\ifnum \c@section>\z@ \thesection.\fi 
\@arabic\c@table} 
\@addtoreset{table}{section} \makeatother 
%-[END ASSOCIATE TABLE AND FIGURE NR TO SECTION NR]-----


\renewcommand{\thetable}{\thesection.\arabic{table}}
\renewcommand{\thefigure}{\thesection.\arabic{figure}}

\setcounter{section}{-1} % setting counter to assign  number 0 to group 0 
\setcounter{figure}{-1} % setting counter to assign  number 0 to figures of group 0
\setcounter{table}{-1} % setting counter to assign  number 0 to figures group 0


\section{Group 0}
\subsection{Visual examination} 
No defect observed. 
\subsection{Examination of dimensions and mass} 
The results meet the requirements stated on the drawings.
\subsection{Magnetic permeability}
The results meet the requirements. 
\subsection{Mating and un-mating forces }
The results meet the requirements.

%----------------          
\section {Group 1} 
%----------------

some text
\subsection{Visual examination}  
some text
\subsection{Measurement of insulation resistance} 
some text
\end{document}

答案1

这是通过添加bookmark包裹

\usepackage{bookmark}% http://ctan.org/pkg/bookmark

到您的文档序言(没有加载顺序限制hyperref,因此之前或之后):

正确组织书签,包含书签包

答案2

最简单的方法是使用\chapter并避免打印“第 n 章”;但是,这也需要修复目录:

\usepackage{etoolbox}
\makeatletter
\let\@makechapterhead\@makeschapterhead
\patchcmd\l@chapter{\begingroup}{\begingroup\let\numberline\@gobble}{}{}
\makeatother

那么简单的\chapter{Summary of test results},不用添加\addcontentsline就可以了。

无论如何,我们推荐使用该软件包bookmark。但是,加载它并保持代码不变会产生警告,并且可能出现错误链接:

pdfTeX warning (ext4): destination with the same identifier 
(name{section.0.1}) has been already used, duplicate ignored
<to be read again> 
                   \relax 
l.79 \section {Group 1}

使用我建议的补丁后,这种情况不会发生。

就打印而言,该行\let\@makechapterhead\@makeschapterhead的行为就像其未编号的兄弟一样(但章节编号仍然会分步)。\chapter

\patchcmd行告诉 LaTeX 忽略\numberline{n}目录条目中的位(n代表实际章节编号),利用条目在组内排版的事实:因此在该组中我们重新定义为与使其参数消失\numberline相同的位。\@gobble

相关内容