3

I am trying to use titleclass to define two new classes : savoir and subsavoir.

In the TOC, I would like to get something like this :

  • Savoir 1 -- First knowkledge title
  • Savoir 1.a -- First "subknowledge" of the first knwolege.

I have instead :

  • Savoir 1 -- First knowkledge title
  • Savoir a -- First "subknowledge" of the first knwolege.

It lacks the 1. in savoir 1.a

Here is a minimal exemple :

\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage{lipsum}
\usepackage[explicit]{titlesec}
\usepackage[rightlabels]{titletoc}
\titlecontents{savoir}[0pt]{\addvspace{2pt\filright}}
  {\contentspush{\bf Savoir \thecontentslabel\ --\ }}
  {}{\titlerule*[0.8em]{.}\thecontentspage}
\titlecontents{subsavoir}[0pt]{\addvspace{2pt\filright}}
  {\contentspush{\bf Savoir \thecontentslabel\ --\ }}
  {}{\titlerule*[0.8em]{.}\thecontentspage}
  \contentsfinish

\makeatletter
  \renewcommand\@pnumwidth{0em}
\makeatother

\titleclass{\savoir}{straight}[\section]
\titleclass{\subsavoir}{straight}[\savoir]
\newcounter{savoir}
\newcounter{subsavoir}[savoir]
\renewcommand{\thesavoir}{\arabic{savoir}}
\renewcommand{\thesubsavoir}{\alph{subsavoir}}
\titleformat{\savoir}[hang]{\large\sf}{Savoir \thesavoir}{0.7em}{#1}
\titlespacing{\savoir}{0pt}{10pt}{5pt}
\titleformat{\subsavoir}{\large\sf}{Savoir \thesavoir\,\thesubsavoir}{0.7em}    {#1}
\titlespacing{\subsavoir}{0pt}{10pt}{5pt}

\begin{document}
\renewcommand{\contentsname}{Liste des savoirs}
\tableofcontents
\savoir{Premier savoir}
\lipsum[1]
\subsavoir{premier sous-savoir}
\lipsum[2]
\end{document}

The TOC I get so far

Thanks

2

It is customary to define a hierarchy in terms of the numbering scheme. That is, \thesubsection includes part of \thesection; \thesection includes part of \thechapter; and so on. In your case, you're using two different ways of representing the sectioning numbers. Correct these to be uniform:

enter image description here

\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage{lipsum}
\usepackage[explicit]{titlesec}
\usepackage[rightlabels]{titletoc}
\titlecontents{savoir}[0pt]{\addvspace{2pt\filright}}
  {\contentspush{\bfseries Savoir \thecontentslabel\ --\ }}
  {}{\titlerule*[0.8em]{.}\thecontentspage}
\titlecontents{subsavoir}[0pt]{\addvspace{2pt\filright}}
  {\contentspush{\bfseries Savoir \thecontentslabel\ --\ }}
  {}{\titlerule*[0.8em]{.}\thecontentspage}
  \contentsfinish

\makeatletter
  \renewcommand\@pnumwidth{0em}
\makeatother

\titleclass{\savoir}{straight}[\section]
\titleclass{\subsavoir}{straight}[\savoir]
\newcounter{savoir}
\newcounter{subsavoir}[savoir]
\renewcommand{\thesavoir}{\arabic{savoir}}
\renewcommand{\thesubsavoir}{\thesavoir.\alph{subsavoir}}
\titleformat{\savoir}[hang]{\large\sffamily}{Savoir \thesavoir}{0.7em}{#1}
\titlespacing{\savoir}{0pt}{10pt}{5pt}
%\titleformat{\subsavoir}{\large\sffamily}{Savoir \thesubsavoir}{0.7em}{#1}
\titleformat{\subsavoir}{\large\sffamily}{Savoir \thesavoir\,\alph{subsavoir}}{0.7em}{#1}
\titlespacing{\subsavoir}{0pt}{10pt}{5pt}

\begin{document}
\renewcommand{\contentsname}{Liste des savoirs}
\tableofcontents
\savoir{Premier savoir}
\lipsum[1]
\subsavoir{premier sous-savoir}
\lipsum[2]
\end{document}

Above I've commented out the \subsavoir title format that should be used.

  • Thank you really much to both of you Werner and Touhami. It was obvious now that I have the answer, but I have spent a lot of time on this one. – Regis C. Feb 2 '15 at 22:44
2

try do this

\renewcommand{\thesubsavoir}{\thesavoir.\alph{subsavoir}}
\titleformat{\subsavoir}{\large\sf}{Savoir \thesubsavoir}{0.7em}    {#1}

complete code

\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage{lipsum}
\usepackage[explicit]{titlesec}
\usepackage[rightlabels]{titletoc}
\titlecontents{savoir}[0pt]{\addvspace{2pt\filright}}
  {\contentspush{\bf Savoir \thecontentslabel\ --\ }}
  {}{\titlerule*[0.8em]{.}\thecontentspage}
\titlecontents{subsavoir}[0pt]{\addvspace{2pt\filright}}
  {\contentspush{\bf Savoir \thecontentslabel\ --\ }}
  {}{\titlerule*[0.8em]{.}\thecontentspage}
  \contentsfinish

\makeatletter
  \renewcommand\@pnumwidth{0em}
\makeatother

\titleclass{\savoir}{straight}[\section]
\titleclass{\subsavoir}{straight}[\savoir]
\newcounter{savoir}
\newcounter{subsavoir}[savoir]
\renewcommand{\thesavoir}{\arabic{savoir}}
\renewcommand{\thesubsavoir}{\thesavoir.\alph{subsavoir}}
\titleformat{\savoir}[hang]{\large\sf}{Savoir \thesavoir}{0.7em}{#1}
\titlespacing{\savoir}{0pt}{10pt}{5pt}
\titleformat{\subsavoir}{\large\sf}{Savoir \thesubsavoir}{0.7em}    {#1}
\titlespacing{\subsavoir}{0pt}{10pt}{5pt}

\begin{document}
\renewcommand{\contentsname}{Liste des savoirs}
\tableofcontents
\savoir{Premier savoir}
\lipsum[1]
\subsavoir{premier sous-savoir}
\lipsum[2]
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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