0

I am writing an Exercise book and would like to achieve the following structure:

1. First chapter: algebra
   Exercise 1.1
   Exercise 1.2
   ...
2. Indipendenza:
   ...

Using this code I get the following about which I'm happy about.

\documentclass{book}
\renewcommand{\thesection}{\arabic{section}}
\renewcommand{\thesubsection}{\arabic{subsection}}
\renewcommand{\thechapter}{\arabic{chapter}}
\usepackage{titlesec}
\titleformat{\section}{\normalfont\Large\bfseries}{Esercizio~\thechapter.\thesection}{1em}{}
\titleformat{\subsection}{\normalfont\large\bfseries}{Soluzione~\thechapter.\thesection}{1em}{}

\usepackage{titletoc}
\usepackage{etoolbox}

\setcounter{tocdepth}{1}

\begin{document}

\tableofcontents

\chapter{algebre}

\section{} % First 
\subsection{}
test
\section{} % Second 
\subsection{}
\section{} % Third 
\subsection{}


\chapter{indipendenza}

\section{} % First 
\subsection{}
\section{} % Second 
\subsection{}
\section{} % Third 
\subsection{}


\end{document}

enter image description here However it's not reflected in the ToC enter image description here

Plus. What if I wanted to do a "First part: Exercises"/"Second part: Solutions", still using the same logic?

1 Answer 1

0

Hope it works as you want! Give a \titleformat gives a format for your sections and subsections but taking it apart of the title of your section. This is why you only get the section number as an output on your toc.

\documentclass{book}
\renewcommand{\thesection}{\arabic{section}}
\renewcommand{\thesubsection}{\arabic{subsection}}
\renewcommand{\thechapter}{\arabic{chapter}}
\usepackage{titlesec}
\titleformat{\section}{\normalfont\Large\bfseries}{}{0em}{}
\titleformat{\subsection}{\normalfont\large\bfseries}{}{0em}{}

\usepackage{titletoc}
\usepackage{etoolbox}

\setcounter{tocdepth}{1}

\newcommand{\Section}{\section{Esercizio~\thechapter.\thesection}}
\newcommand{\Subsection}{\subsection{Soluzione~\thechapter.\thesection}}

\begin{document}

\tableofcontents

\chapter{algebre}

\Section % First 
\Subsection{}
test
\Section{} % Second 
\Subsection{}
\Section{} % Third 
\Subsection{}


\chapter{indipendenza}

\Section{} % First 
\Subsection{}
\Section{} % Second 
\Subsection{}
\Section{} % Third 
\Subsection{}


\end{document}
1
  • very interesting solution! thank you so much
    – huncletheo
    May 27, 2020 at 21:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .