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.

When I define two new level using titlesec, the reference doesn't work correctly.

This is an example:

\documentclass{article}

\usepackage{titlesec}

% First level
\titleclass{\exemple}{straight}[\subsection]
\newcounter{exemple}[section]
\titleformat{\exemple}[runin]{}{\theexemple}{0em}{Exemple \ }[\quad]
\titlespacing{\exemple}{0pt}{\baselineskip}{1em}

\renewcommand{\theexemple}{\thesection.\roman{exemple}}

% -------------------------------------------------------------------
% second one
\titleclass{\suiteexemple}{straight}[\subsection]
\newcounter{suiteexemple}[section]

\titleformat{\suiteexemple}[runin]{}{\thesuiteexemple}{0em}{Suite de l'exemple \ }[\quad]

\titlespacing{\suiteexemple}{0pt}{\baselineskip}{1em}
\renewcommand{\thesuiteexemple}{\thesection.\roman{suiteexemple}}
% -------------------------------------------------------------------


\begin{document}

\section{one} \label{sec:one}

...

\exemple{First exemple} 
\label{ex:one}

\exemple{Second example}

\section{two}

...

Reference to exemple : \ref{ex:one}

\end{document}

The reference is displayed as "1", but it should be "1.1" (the exemple counter is not displayed).

If you comment the code between the % ------ the reference is correctly displayed.

Do you know any workaround on this problem?

share|improve this question
    
I get "Reference to exemple : 1" (just copied an pasted from the PDF file). –  egreg Apr 27 '13 at 15:06
    
Yep, but it should be "Reference to exemple : 1.1" –  Paul Pichaureau Apr 27 '13 at 17:08
    
Sorry I don't know how to include the result of a compilation. –  Paul Pichaureau Apr 27 '13 at 17:08
add comment

1 Answer

up vote 1 down vote accepted

The problem is in how \titleclass works.

With \titleclass{\exemple}{straight}[\subsection] you're inserting a new numbering level between \subsection and \subsubsection. So \example becomes level 3 and \subsubsection is shifted to level 4.

With the following \titleclass{\subexemple}{straight}[\subsection] you do the same, so \subexemple becomes level 3 and \exemple is shifted to level 5.

Therefore, with the usual value of 3 for secnumdepth, \exemple loses its numbering and the \label{ex:one} command will refer to the last "refstepped" command which happened at \section{one}.

You probably have better to define \suiteexemple in terms of \example* or saying

\titleclass{\suiteexemple}{straight}[\exemple]
share|improve this answer
    
Ok, I get it! I thought \titleclass...[\subsection] define something "at the same level" than \subsection I should define both command in term of \subsection –  Paul Pichaureau May 1 '13 at 6:57
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.