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 use titlesec, hyperref, and algorithm2e together, sections after an \appendix are not numbered properly.

\documentclass{article}
\usepackage{titlesec}
\usepackage{hyperref}
\usepackage{algorithm2e}
\begin{document}
\section{foo}
\appendix
\section{bar}
\end{document}

Compiling this gives the warning

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

Sure enough, the .aux file shows

\@writefile{toc}{\contentsline {section}{\numberline {1}foo}{1}{section.1}}
\@writefile{toc}{\contentsline {section}{\numberline {A}bar}{1}{section.1}}
  • Removing titlesec changes the second section.1 to appendix.1.
  • Removing algorithm2e changes the second section.1 to section.A.
  • Removing both changes the second section.1 to appendix.A.

Unlike last time, I tried all six permutations of the packages but had no luck.

Can this combination of packages be made to work?

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

It's always good to load hyperref last. (But you're right, that won't solve your problem.) I think the main source of the problem is algorithm2e. Based on this discussion (in German) here, it seems that there are a few possible solutions. The simplest two are:

Add

\renewcommand*{\theHsection}{\thesection}

after loading hyperref.

or

add

\let\chapter\undefined

after loading algorithm2e.

\documentclass{article}
\usepackage{titlesec}
\usepackage{algorithm2e}
\let\chapter\undefined % use this line
\usepackage[]{hyperref}
%\renewcommand*{\theHsection}{\thesection} % or this one
\begin{document}
\section{foo}
\appendix
\section{bar}
\end{document}
share|improve this answer
    
Thanks! It seems like the best solution (per a Google translate) is \let\chapter\undefined after loading algorithm2e. As you note, I should have been loading hyperref last, and indeed I normally would. I just happened to start with lexicographic ordering of the packages to make sure I didn't miss any of the 6 permutations. t, h, a was the 6th permutation. =) –  TH. Apr 10 '11 at 1:13
    
Yes, that will work too. I read the post quite quickly and went for the first solution that worked. I'll adjust my answer. –  Alan Munn Apr 10 '11 at 1:27
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.