# Fixing the document structure created with hyperref

I am new to Latex, tentatively using it to prepare a complicated industrial document (laboratory test report). This document contains numerous test groups, and I have found convenient , for both the writer and the reader, to number the section of the test results of each group (and the tables and figures) with the group number. I have managed to find a way that suits my need. However, when I use a starred version of the chapters, the resulting structure of the .pdf document is altered, in a way that on the attached sample, the chapter "test results" is shown as a branch of section 1 and not on the same level as other chapters... Is there a way to correct this behavior? Thanks.

\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}

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

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

\chapter*{Test results}

%-[BEGIN ASSOCIATE TABLE AND FIGURE NR TO SECTION NR]----
\makeatletter
\renewcommand{\thefigure}{\ifnum \c@section>\z@ \thesection.\fi
\@arabic\c@figure}
\makeatletter
\renewcommand{\thetable}{\ifnum \c@section>\z@ \thesection.\fi
\@arabic\c@table}
%-[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}

-
The problem lies with you resetting the \setcounter{section}{-1}. Can you please post a sample of what you want to achieve? –  Yiannis Lazarides Jan 29 '12 at 16:36

This is fixed with the addition of the bookmark package

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


to your document preamble (no load order restriction with hyperref, so before or after):

-
Thanks a lot... I had been trying to understand the problem for a while.... –  Yves Jan 29 '12 at 16:48

The easiest way is to use \chapter and avoid printing "Chapter n"; however, this needs also fixing the table of contents:

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


Then the simple \chapter{Summary of test results}, without adding \addcontentsline will do.

The package bookmark is recommended anyway. However, loading it and leaving your code unchanged will produce warnings and possible incorrect links:

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


This doesn't happen with the patches I suggest.

The line \let\@makechapterhead\@makeschapterhead makes \chapter behave, as far as printing is concerned, like its unnumbered sibling (but the chapter number will be stepped nevertheless).

The \patchcmd line tells LaTeX to ignore the \numberline{n} bit in the ToC entry (n stands for the actual chapter number) by exploiting the fact that the entry is typeset inside a group: so in that group we redefine \numberline to be the same as \@gobble that makes its argument disappear.

-
Thanks a lot. I had also noticed the warning, but had not understood how to get rid of it. I must admit I do not understand everything in your code either, but I am going to study. Your code brings the additional benefit of keeping the chapters numbered, and this is preferred in such a document..... –  Yves Jan 29 '12 at 19:48