Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
\renewcommand{\cftsubsecafterpnum}{\quad\rule{2cm}{0.4pt}}
\renewcommand{\cftsecafterpnum}{\quad\rule{2cm}{0.4pt}}
\setlength{\cftbeforesecskip}{10pt}
\setlength{\cftbeforesubsecskip}{10pt}
\newcommand{\mychapter}[2]{
    \setcounter{chapter}{#1}
    \setcounter{section}{0}
    \chapter*{#2}
    \addcontentsline{toc}{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?

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

2 Answers

up vote 2 down vote accepted

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.

enter image description here

\documentclass[12pt]{report}
\usepackage{tocloft}% http://ctan.org/pkg/tocloft
\newif\ifchaprule
\newcommand{\addchapscorerule}{\addtocontents{toc}{\protect\chapruletrue}}
\newcommand{\removechapscorerule}{\addtocontents{toc}{\protect\chaprulefalse}}
\renewcommand{\cftchapafterpnum}{\ifchaprule\quad\rule{2cm}{0.4pt}\fi}
\renewcommand{\cftsecafterpnum}{\quad\rule{2cm}{0.4pt}}
\renewcommand{\cftsubsecafterpnum}{\quad\rule{2cm}{0.4pt}}
\setlength{\cftbeforesecskip}{10pt}
\setlength{\cftbeforesubsecskip}{10pt}
\newcommand{\mychapter}[2]{
    \setcounter{chapter}{#1}
    \setcounter{section}{0}
    \chapter*{#2}
    \addcontentsline{toc}{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}
share|improve this answer
    
A better solution, though I think optionally adding an 'after page rule' to the other sections would be useful too. –  jon Jan 24 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 at 21:59
add comment

(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'...
\renewcommand{\cftchapafterpnum}{\quad\rule{2cm}{0.4pt}}
\def\markline{\quad\protect\rule{2cm}{0.4pt}}
\newcommand{\probchapter}[2]{
    \setcounter{chapter}{#1}
    \setcounter{section}{0}
    \chapter*{#2}
%    \addcontentsline{toc}{chapter}{#2}
    \cftaddtitleline{toc}{chapter}{#2}{\thepage\markline}
}

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}
    \addcontentsline{toc}{chapter}{#2}
}
% need \cftCHAPafterpnum for 'chapters'...
\renewcommand{\cftchapafterpnum}{\quad\rule{2cm}{0.4pt}}
\def\markline{\quad\protect\rule{2cm}{0.4pt}}
\newcommand{\probchapter}[2]{
    \setcounter{chapter}{#1}
    \setcounter{section}{0}
    \chapter*{#2}
%    \addcontentsline{toc}{chapter}{#2}
    \cftaddtitleline{toc}{chapter}{#2}{\thepage\markline}
}
\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.:

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.