Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}

\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}
share|improve this question
    
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
add comment

2 Answers

up vote 5 down vote accepted

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):

Correct bookmark organization with the inclusion of bookmark package

share|improve this answer
    
Thanks a lot... I had been trying to understand the problem for a while.... –  Yves Jan 29 '12 at 16:48
add comment

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

\usepackage{etoolbox}
\makeatletter
\let\@makechapterhead\@makeschapterhead
\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
<to be read again> 
                   \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.

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.