2

I need to include a toc in the first page of a multiple pages document containing exercises with solutions. I don't know if this should be named table of contents or rather list of exercises (like list of figures)

enter image description here

MME:

\documentclass[a4paper,answers]{exam} 
\usepackage{lipsum}
\qformat{\textbf {Exercise \thequestion} \hfill \thepoints}
\begin{document}
    \begin{questions}
    \question
    \lipsum[1]
    \begin{solution}
    \lipsum
    \end{solution}
    \newpage 

    \question
    \lipsum[2]
    \begin{solution}
    \lipsum
    \end{solution}
    \newpage 

    \question
    \lipsum[3]
    \begin{solution}
    \lipsum
    \end{solution}

    \end{questions}
\end{document}
2
  • 2
    I think it is a question of taste. If it are al questions and answers it would be more useful to have "Table of Exercises" or maybe "List of Exersises"
    – albert
    Commented Nov 30, 2018 at 19:03
  • Try \renewcommand{\contentsname}{List of Exercises} (sorry, I can't test it myself until I get MikTeX working again). Commented Dec 2, 2018 at 0:30

1 Answer 1

4

Suggestion using \tableofcontents:

\documentclass[a4paper,answers]{exam}
\usepackage{lipsum}% only for dummy text

\usepackage{tocbasic}
\DeclareTOCStyleEntry[
  level=1,
  indent=0pt,
  numwidth=2.3em,
  dynnumwidth,
  pagenumberformat=\entryprefix{page~},
  pagenumberbox=\mbox
]{tocline}{exercise}
\newcommand*\entryprefix[2]{#1#2}

\qformat{%
  \textbf{Exercise~\thequestion}%
  \addxcontentsline{toc}{exercise}{Exercise~\thequestion}%
  \hfill\thepoints%
}

\renewcommand*\contentsname{List of Exercises}

\begin{document}
\tableofcontents
\clearpage

\begin{questions}
\question
\lipsum[1]
\begin{solution}
\lipsum
\end{solution}
\clearpage

\question
\lipsum[2]
\begin{solution}
\lipsum
\end{solution}
\clearpage

\question
\lipsum[3]
\begin{solution}
\lipsum
\end{solution}

\end{questions}
\end{document}

Suggestion using a new defined \listofexercises:

\documentclass[a4paper,answers]{exam}
\usepackage{lipsum}% only for dummy text

\usepackage{tocbasic}
\DeclareNewTOC[%
  type=exercise,%
  types=exercises,%
  name=Exercise,%
  listname={List of Exercises},%
  tocentrystyle=tocline,%
  tocentryindent=0pt,%
  tocentrydynnumwidth,%
  tocentrypagenumberformat=\entryprefix{page~},%
  tocentrypagenumberbox=\mbox
]{exr}
\newcommand*\entryprefix[2]{#1#2}

\qformat{%
  \textbf{Exercise~\thequestion}%
  \addxcontentsline{exr}{exercise}{Exercise~\thequestion}%
  \hfill\thepoints%
}

\begin{document}
\listofexercises
\clearpage

\begin{questions}
\question
\lipsum[1]
\begin{solution}
\lipsum
\end{solution}
\clearpage

\question
\lipsum[2]
\begin{solution}
\lipsum
\end{solution}
\clearpage

\question
\lipsum[3]
\begin{solution}
\lipsum
\end{solution}

\end{questions}
\end{document}

Both result in

enter image description here

5
  • The first method using \tableofcontents works fine but the second one using a new defined \listofexercises doesn't produce any list. Commented Dec 12, 2018 at 21:23
  • 1
    See my updated answer: \addxcontentsline{exr}{exercise}{Exercise~\thequestion} for the second method.
    – esdd
    Commented Dec 13, 2018 at 8:32
  • I tried the second method. However, the list of exercises is not clickable. Is there any way to also accomplish this? Commented May 17, 2021 at 1:58
  • 1
    @RodrigoMorales Did you load package hyperref? If I load hyperref after the other packages the entries in list of exercises are clickable for me.
    – esdd
    Commented May 19, 2021 at 7:38
  • I didn't load it, @esdd. By loading it, the list of exercises is clickable. Thanks for pointing that out! Commented May 29, 2021 at 17:20

You must log in to answer this question.

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