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 have a question about a problem that I am facing. I have a document composed by two different and independent parts in two where the second parts refers to just some elements of the first one. Both the parts shares a common information as for example bibliography.

What I would like to generate is a document where the numbering of each parts start from 1 (also Figures, Table etc. follow the same numbering...). For example:

Part I

Chapter 1 Section 1.x Sub Section 1.x.y

Chapter 2 Section 2.x Sub Section 2.x.y -->Fig. 2.x.1

etc.

Part II

Chapter 1 Section 1.x Sub Section 1.x.y

Chapter 2 Section 2.x Sub Section 2.x.y -->Fig. 2.x.1

etc.

As I said, the second part refers somehow to elements in the first one. Therefore, inside the Part II -Chapter 2 -Section 2.x, I can have for example, a reference to Section 2.x of Part I (lets say Fig. 2.x.1)

Is it possible to do?

share|improve this question
    
Did you check tex.stackexchange.com/q/17127 or tex.stackexchange.com/q/2445 ? Do the solutions provided there solve your problem? If so, this is a possible duplicate. –  Count Zero Sep 4 '12 at 14:31

1 Answer 1

Compared to the class book, chapters are reset at the begin of a new part and figures and tables are reset at the start of a new section. There are several methods to do that, see the links in the comment of Count Zero above.

It remains the problem, that the numbering is not unique and it is not clear, to which part figure 2.1.1 belong to, for example. The following example adds the part, if the reference points outside the current part:

References

Each reference is prefixed by \p@<counter> that is redefined to expand to \RefPart with the current part number. \RefPart is defined using \DeclareRobustCommand, because it must not be expanded, when the label is written to the .aux file. This way the \RefPart is executed at time of \ref that can be called in both parts generating different references (with and without part prefix).

Additionally the example is tested with hyperref.

\documentclass{book}

\usepackage{hyperref}
\usepackage{bookmark}

\makeatletter
% numbering of chapters inside part:
\@addtoreset{chapter}{part}
\@ifpackageloaded{hyperref}{%
  \renewcommand*{\theHchapter}{%
    \theHpart.\arabic{chapter}%
  }%
}{}
% numbering of figure/table inside section:
\@addtoreset{figure}{section}
\renewcommand*{\thefigure}{\thesection.\arabic{figure}}
\@addtoreset{table}{section}
\renewcommand*{\thetable}{\thesection.\arabic{table}}
\DeclareRobustCommand*{\RefPart}[1]{%
  \begingroup
    \def\x{#1}%
    \protected@edef\y{\thepart}%
    \ifx\x\y
    \else
      \x.%
    \fi
  \endgroup
}
\renewcommand*{\p@table}{\RefPart{\thepart}}
\renewcommand*{\p@figure}{\RefPart{\thepart}}
\makeatother

\begin{document}
\tableofcontents

\part{First part}
\chapter{Chapter A}
Reference inside part: \ref{figE}\\
reference to other part: \ref{figEE}
\chapter{Chapter B}
\section{Section C}
\subsection{Subsection D}
\begin{figure}
\caption{Figure E}
\label{figE}
\end{figure}

\part{Second part}
\chapter{Chapter AA}
Reference to other part: \ref{figE}\\
reference inside part: \ref{figEE}   
\chapter{Chapter BB}
\section{Section CC}
\subsection{Subsection DD}
\begin{figure}
\caption{Figure EE}
\label{figEE}
\end{figure} 

\end{document}
share|improve this answer

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.