1

I would like to write a book in which I put the solutions to some problems. I want to write the texts of the problem in some chapters at the beginning of the book and their solutions in other chapters at the end. Suppose I use the same title for the chapter with the texts and the chapter with the solutions: I would like to have, in the TOC, the following structure

                                  Texts         Solutions 
1 Chapter_Title...................Pag.x.............Pag.y

2 Chapter_Title...................Pag.z.............Pag.t

How can I get it?

1
  • 2
    The easy solution is to not use \tableofcontents. Instead create your own (tabular) table of contents. Put a \label after the \chapter and \section and use \pageref to get the page numbers. The chapter numbers and titles are also stored in the aux file, but it will take a bit of effort to extract them. Feb 12, 2019 at 16:27

1 Answer 1

1

The following builds on John Kormylo's comment about manually setting the ToC

enter image description here

\documentclass{book}

\usepackage{hyperref}

\newlength{\textpagewidth}
\newcommand{\settextpagewidth}{\setlength{\textpagewidth}}
\newlength{\solspagegap}
\newcommand{\setsolspagegap}{\setlength{\solspagegap}}
\newlength{\solspagewidth}
\newcommand{\setsolspagewidth}{\setlength{\solspagewidth}}
\newlength{\chaptocgap}
\newcommand{\setchaptocgap}{\setlength{\chaptocgap}}

\settextpagewidth{2em}
\setsolspagegap{4em}
\setsolspagewidth{2em}
\setchaptocgap{3pt plus 1pt minus 1pt}

\newlength{\saveparindent}
\AtBeginDocument{\setlength{\saveparindent}{\parindent}}
\newcommand{\noparindent}{\setlength{\parindent}{0pt}}
\newcommand{\restoreparindent}{\setlength{\parindent}{\saveparindent}}

\newcommand{\setchapandsol}[2]{%
  \par\addvspace{\chaptocgap}\noindent
  \ref{#1}\quad\nameref{#1}\dotfill
  \makebox[\textpagewidth][r]{\pageref{#1}\,}%
  \makebox[\solspagegap][r]{\dotfill}%
  \makebox[\solspagewidth][r]{\pageref{#2}\,}%
}

\begin{document}

\showthe\chaptocgap

\noparindent
\leavevmode\hfill\makebox[\textpagewidth][r]{Texts}%
  \makebox[\solspagegap][r]{}%
  \makebox[\solspagewidth][r]{Solutions}

\medskip

\setchapandsol{ch:first}{ch:first:sol}
\setchapandsol{ch:second}{ch:second:sol}

\restoreparindent

\chapter{First chapter}\label{ch:first}

\chapter{Second chapter}\label{ch:second}

% ========= SOLUTIONS =========

\chapter*{First chapter solutions}\label{ch:first:sol}

\chapter*{Second chapter solutions}\label{ch:second:sol}

\end{document}

I've added some customisation, but there's plenty you can add yourself.

Your Answer

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