4

I'm working on a sheet of exercises using LaTeX. I've set up my sections to look like Exercise # | <title>.

How can I force the section counter to start from 0, so that I can have an exercise 0 explaining how to set up a working environment.

I'm using the titlesec package to format my section headings. I've set \documentclass to article to avoid having a numbering that looks like Exercise 0.x.

Here is my current formatting:

\newcommand{\hsp}{\hspace{20pt}}
\titleformat{\section}
  [hang]
  {\huge\bfseries}
  {Exercice \thesection\hsp\textcolor{gray}{|}\hsp}
  {0pt}
  {\large\bfseries}
4

You can set your counters to whatever you want with the command \setcounter{}{}.

% arara: pdflatex

\documentclass{article}
\usepackage{titlesec}
\usepackage{xcolor}
\usepackage{blindtext}
\newcommand{\hsp}{\hspace{20pt}}
%%% option 1
%\usepackage[T1]{fontenc}
%\usepackage{lmodern}
%\titleformat{\section}[hang]{\huge\bfseries}{Exercice \thesection\hsp\textcolor{gray}{|}\hsp}{0pt}{\large\bfseries}
%%% option 2
\titleformat{\section}[hang]{\huge\bfseries}{Exercice \thesection\hsp\textcolor{gray}{\textbar}\hsp}{0pt}{\large\bfseries}

\begin{document}
    \setcounter{section}{-1}
    \Blinddocument
\end{document}

enter image description here

| improve this answer | |
  • 1
    With T1 font encoding the | looks as it should be. – Manuel Jun 9 '15 at 11:17
  • 1
    @LaRiFaRi With \textbar instead of | there won't be any encodiong problem at all (I think). – Svend Tveskæg Jun 9 '15 at 11:39

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.