cleveref and titlesec, \section issues.

I have some problems with cleveref and titlesec, providing a minimal working example below:

\documentclass{report}
\usepackage{titlesec} %% <-- the issue as far as i know, but i need the package
\usepackage{hyperref}
\usepackage{cleveref}
\begin{document}
\chapter{ninjas are okay}
some text \cref{app:ninja_bkg} bla bla and \cref{app:ninja_fail}
\appendix
\chapter{ninja background}
\label{app:ninja_bkg}
ninjas originated from ???
\section{ninja fail}
\label{app:ninja_fail}
usually ninjas dont fail, but sometimes they do
\end{document}


where the line in the middle produces:

some text appendix A bla bla and section A.1

But I want:

some text appendix A bla bla and appendix A.1

If I remove the titlesec package everything works fine, but sadly I need it. Guessing titlesec redefines \section, but I'm not enough of a latex-hacker to fix it =/

-
I was just going to suggest to use hyperrefs \autoref instead, but then figured out that it produces the same text output. –  Martin Scharrer May 10 '11 at 13:31
I'll comment this to show a minimal working solution: Change \label{app:ninja_fail} into \label[appendix]{app:ninja_fail} –  flindeberg May 11 '11 at 6:48

1 Answer

You can use (as described in cleveref's documentation) \crefname, \Crefname, and the optional argument for the \label command to supply a new "type" for the sections in the appendices, ; a little example:

\documentclass{report}
\usepackage{titlesec}
\usepackage{hyperref}
\usepackage{cleveref}

\crefname{secinapp}{appendix}{appendices}
\Crefname{secinapp}{Appendix}{Appendices}

\begin{document}

\chapter{Test chapter}\label{testchap}

\section{test section}\label{testsec}

A reference to a regular section: \cref{testsec}, and a reference to a section in appendix: \cref{testsecapp}

\appendix
\chapter{Test appendix}\label{testapp}

\section{Test section in app}\label[secinapp]{testsecapp}

\end{document}


The cleveref documentation gives a hint about using the aliascnt package to avoid having to use the optional argument for the new type (I haven't tested this approach, though).

-
That works, even though a bit cumbersome. Thanks! –  flindeberg May 10 '11 at 14:06