The following code is adapted from here The idea is to create a book with two parts (containing problems and solutions) which have equal (numbered) chapter and (unnumbered) section headings. In order to keep the toc small, the page numbers for both parts should appear side-by-side in the toc (due to the very similar structure in both parts). Furthermore, the sections (although not numbered) should appear in the toc and the page heads. Here are the problems left based on the MWE below:

  • The page number for solution sections don't appear in the toc (only '??' appear)
  • The page numbers of chapters and sections don't seem to be (vertically) aligned correctly, especially in the case where some solutions are on a page >= 100 (3-digits). This certainly comes from the \hspace between the page numbers of problems and their solutions in \titlecontents below. (It seems that a table-like toc would be the way to go to ensure right-alignment of the page numbers, but I didn't manage to get this to work).

How can these two issues be fixed?



% {section}, [left], {above}, {before with label (left side)}, {before wo label
% (left side)}, {filler and page}, [after]
\newcommand{\addsecsol}[2]{\hypertarget{#2}{\addsec{#1}\label{#2}}}% define solution section, which is shown in toc

\addtocontents{toc}{\vspace{1em}\hfill Problems\hspace*{1.4em}Solutions\par}% header for toc
\tableofcontents% without number; add bookmark on level 0
\chapter{Chapter A problems}\label{chap:1}
\addsec{Section 1}
\addsec{Section 2}

\addtocontents{toc}{\protect\setcounter{tocdepth}{-1}}% remove toc entries after this line
\chapter{Chapter A solutions}\label{2}
\addsecsol{Section 1}{2.1}
\addsecsol{Section 2}{2.2}
\addtocontents{toc}{\protect\setcounter{tocdepth}{2}}% display contents (down to subsections) in toc again
  • Why using titletoc with a KOMA class? Oct 2, 2015 at 0:02
  • Because of the \titlecontents commands (?) Oct 2, 2015 at 4:15
  • Well, of course. My comment was meant to indicate that titletoc might not be fully compatible with KOMA classes (titlesec is not). With KOMA classes, I think, one should use tocstyle (from the same author of the classes). Oct 2, 2015 at 14:10
  • This is also discussed on the KOMA-Script website, see komascript.de/node/1971
    – esdd
    Oct 3, 2015 at 16:41
  • yes, that was me -- I decided to post it there as well, as I know Markus Kohm a bit but am not sure whether he reads tex.stackexchange. Of course I provide a full solution once it's working as expected. Oct 3, 2015 at 18:54

1 Answer 1


Since this problem is quite KOMA-script-specific (and since I didn't receive an answer by then), I also posted it in the komascript forum. Markus Kohm came up with a beautiful solution (thanks a ton, Markus!); see Markus' answer there for the details.

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.