# How to apply \cftafterpnum to specific entries (and add labels for columns of the TOC)

I'm trying to make a 3 column table of contents, which includes chapter name, page number, and a blank line for grading for a homework assignment. A previous question gave me the answer as to how to prepare this extra blank line using tocloft:

\documentclass[12pt]{report}
\usepackage{tocloft}
\setlength{\cftbeforesecskip}{10pt}
\setlength{\cftbeforesubsecskip}{10pt}
\newcommand{\mychapter}[2]{
\setcounter{chapter}{#1}
\setcounter{section}{0}
\chapter*{#2}
}
\setcounter{secnumdepth}{0}
\begin{document}
\tableofcontents
\subsection*{Acknowledgements:}
Problem 1c: Jack Smith helps me with deriving this and that.
\clearpage
\mychapter{1}{Section 1.1 Problems}
\section{Problem 1}
\subsection{Part C}
\section{Problem 1d}
\mychapter{2}{Section 1.2 Problems}
\mychapter{3}{Problem A}
\mychapter{4}{Problem B}
\end{document}


However, I want \quad\rule{2cm}{0.4pt} to appear after the page number of problems A and B, but not the other chapters. E.g. I want to apply \cftchapafterpnum to specific entries if that's possible. If the way I've been doing this is inconvenient please let me know, especially if there's a way to get a title on each section, (i.e. label the vertical columns "chapter", "page", and "grade".) Also, elementary question I know, but how do you get chapters to appear on the same page? E.g. avoid automatically making chapters on separate pages in the report class?

-
Although I've never had a reason to use it, the package etoc should be able to do this. – jon Jan 24 '14 at 3:59
For your last "elementary question", see Start new chapter on same page. – Werner Jan 24 '14 at 4:30

Since you're dealing with ToC-related content, you have to manage the insertion of changes very strategically. The following addition to your MWE provides \addchapsorerule and \removechapscorerule which inserts conditionals into the ToC that would either include/exclude a chapter-rule.

\documentclass[12pt]{report}
\usepackage{tocloft}% http://ctan.org/pkg/tocloft
\newif\ifchaprule
\setlength{\cftbeforesecskip}{10pt}
\setlength{\cftbeforesubsecskip}{10pt}
\newcommand{\mychapter}[2]{
\setcounter{chapter}{#1}
\setcounter{section}{0}
\chapter*{#2}
}
\setcounter{secnumdepth}{0}
\begin{document}
\tableofcontents
\subsection*{Acknowledgements:}
Problem 1c: Jack Smith helps me with deriving this and that.

\clearpage

\mychapter{1}{Section 1.1 Problems}
\section{Problem 1}
\subsection{Part C}
\section{Problem 1d}
\mychapter{2}{Section 1.2 Problems}
\addchapscorerule% Start inserting chapter-rules from this point
\mychapter{3}{Problem A}
\removechapscorerule% Remove chapter-rules from this point
\mychapter{4}{Problem B}
\end{document}

-
A better solution, though I think optionally adding an 'after page rule' to the other sections would be useful too. – jon Jan 24 '14 at 5:07
I've applied this method because it looked shorter, but I'm also gonna try Jon's later. I've also gotten the new chapter thing to work and am learning about lists of figures. Ya'll are awesome! – Latexpet Jan 27 '14 at 21:59

(Turns out I don't have time to learn etoc's complicated, but powerful, approach. Hopefully someone else posts an answer.)

You could define a new 'chapter' command along the lines of:

% need \cftCHAPafterpnum for 'chapters'...
\newcommand{\probchapter}[2]{
\setcounter{chapter}{#1}
\setcounter{section}{0}
\chapter*{#2}
}


This would switch the extra post-page number space to only chapters called by \probchapter. A full example:

\documentclass[12pt]{report}
\usepackage{tocloft}
% \renewcommand{\cftsubsecafterpnum}{\quad\rule{2cm}{0.4pt}} % <-- these are for subsections
% \renewcommand{\cftsecafterpnum}{\quad\rule{2cm}{0.4pt}}    % <-- and sections
\setlength{\cftbeforesecskip}{10pt}
\setlength{\cftbeforesubsecskip}{10pt}
\newcommand{\mychapter}[2]{
\protect\marklinetrue
\setcounter{chapter}{#1}
\setcounter{section}{0}
\chapter*{#2}
}
% need \cftCHAPafterpnum for 'chapters'...
\newcommand{\probchapter}[2]{
\setcounter{chapter}{#1}
\setcounter{section}{0}
\chapter*{#2}
}
\setcounter{secnumdepth}{0}
\begin{document}
\tableofcontents
\subsection*{Acknowledgements:}
Problem 1c: Jack Smith helps me with deriving this and that.
\clearpage
\mychapter{1}{Section 1.1 Problems}
\section{Problem 1}
\subsection{Part C}
\section{Problem 1d}
\mychapter{2}{Section 1.2 Problems}
\probchapter{3}{Problem A}
\probchapter{4}{Problem B}
\end{document}


As for the other questions, there already exist answers on this site. E.g.:

-