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 am working on a booklet for my wife who is a grade school teacher. The booklet is field guide about the plants in the fairly large playground area at Gemini Elementary. Tufte-Latex is my "go-to" template for everything these days - especially thanks to this fine group showing me the code to make a change to the color of chapter headings! I am befuddled by another chapter/color task. What I would like to do is assign a little tab of color to associate each chapter with the color of a flower, or green for trees and shrubs. Introductory chapters could just have a white tab so nothing shows up. The colored tabs would be in the table of contents and then at the top, maybe a cm or two from outer corner of each page. Am I nuts for even thinking about doing this?

share|improve this question
    
Welcome to TeX.SX! What have you tried? –  Jubobs Mar 2 at 17:37

2 Answers 2

up vote 5 down vote accepted

Here's an option meeting all your requirements:

  1. Color marking can be activated/deactivated at any point of your document and as many times as required.

  2. When color marking is active, each chapter entry in the ToC will have a tab to the left with the corresponding color; the chapter heading will also have this color and all pages of the chapter will also have a colored tab at the top (to the left for even-numbered pages and to the right for odd-numbered pages).

  3. The original settings of tufte-book for ToC entries and chapter headings are preserved.

Simplified version:

\documentclass[dvipsnames]{tufte-book}
\usepackage{background}
\usepackage{lipsum}

\newif\ifcolor
\colorfalse
\backgroundsetup{
angle=0,
scale=1,
opacity=1,
contents={}
}

\makeatletter
\AddEverypageHook{%
\backgroundsetup{
contents={
  \ifcolor
    \textcolor{\chaptercolor}{\rule{3em}{3em}}
  \fi}
}
\ifodd\value{page}
  \backgroundsetup{
    position={current page.north east},
    hshift=-1.5cm,vshift=-1cm
    }
\else  
  \backgroundsetup{position={current page.north west},
    hshift=1.5cm,vshift=-1cm
    }
\fi  
\BgMaterial}

\def\chaptercolor{black}
\newcommand\normalchapter{%
\colorfalse%
\titleformat{\chapter}[display]
  {\relax\ifthenelse{\NOT\boolean{@tufte@symmetric}}{\begin{fullwidth}}{}}
  {\itshape\huge\thechapter}
  {0pt}
  {\huge\rmfamily\itshape}
  [\ifthenelse{\NOT\boolean{@tufte@symmetric}}{\end{fullwidth}}{}]
}

\newcommand\colorchapter{%
\colortrue%
\titleformat{\chapter}[display]
  {\relax\color{\chaptercolor}\ifthenelse{\NOT\boolean{@tufte@symmetric}}{\begin{fullwidth}}{}}
  {\itshape\huge\thechapter}
  {0pt}
  {\huge\rmfamily\itshape}
  [\ifthenelse{\NOT\boolean{@tufte@symmetric}}{\end{fullwidth}}{}]
}

\newcommand\ContentColor[1]{%
\titlecontents{chapter}[0em]
    {\vspace{1.5\baselineskip}\begin{fullwidth}\LARGE\rmfamily\itshape%
      \makebox[0pt]{\textcolor{#1}{\rule{1em}{1em}}\hspace{2em}}
    }
    {\hspace*{0em}\thecontentslabel{2em}}
    {\hspace*{0em}}
    {\rmfamily\upshape\qquad\thecontentspage}
    [\end{fullwidth}]
}

\newcommand\ContentNoColor{%
\titlecontents{chapter}%
    [0em]
    {\vspace{1.5\baselineskip}\begin{fullwidth}\LARGE\rmfamily\itshape}
    {\hspace*{0em}\thecontentslabel{2em}}
    {\hspace*{0em}}
    {\rmfamily\upshape\qquad\thecontentspage}
    [\end{fullwidth}] 
}
\renewcommand\mainmatter{%
  \cleardoublepage%
  \@mainmattertrue%
  \colorchapter
  \fancyhf{}%
  \ifthenelse{\boolean{@tufte@twoside}}%
    {% two-side
      \renewcommand{\chaptermark}[1]{\markboth{##1}{}}%
      \fancyhead[LE]{\thepage\quad\smallcaps{\newlinetospace{\plaintitle}}}% book title
      \fancyhead[RO]{\smallcaps{\newlinetospace{\leftmark}}\quad\thepage}% chapter title
    }%
    {% one-side
      \fancyhead[RE,RO]{\smallcaps{\newlinetospace{\plaintitle}}\quad\thepage}% book title
    }%
}

\renewcommand\backmatter{%
  \if@openright%
    \cleardoublepage%
  \else%
    \clearpage%
  \fi%
  \@mainmatterfalse%
  \normalchapter%
  \ContentNoColor%
}
\makeatother

\newcommand\ChapColor[1]{%
  \def\chaptercolor{#1}
  \ContentColor{#1}
}

\begin{document}

\frontmatter
\tableofcontents
\cleardoublepage
\chapter{Introduction}
\lipsum[1-2]
\cleardoublepage

\mainmatter
\ChapColor{Maroon!80}
\chapter{Test chapter one}
\lipsum[1-4]
\cleardoublepage
\ChapColor{MidnightBlue!70}
\chapter{Test chapter two}
\lipsum[1-4]
\cleardoublepage
\ChapColor{Dandelion}
\chapter{Test chapter three}
\lipsum[1-4]
\cleardoublepage

\backmatter
\chapter{Appendix}
\lipsum[1-4]

\end{document}

An image of the ToC:

enter image description here

An image of the document, showing normal chapters and chapters with the color specification:

enter image description here

Most of the work now is delegated to \frontmatter, \mainmatter and \backmatter; in this version, \frontmatter activates the color marking for headings, ToC entries and for the tabs on each page of a chapter. \backmatter deactivates these settings. The only thing that has to be done now is to use \ChapColor{<color>} before each \chapter in which a color change is required.

First version:

The code:

\documentclass[dvipsnames]{tufte-book}
\usepackage{background}
\usepackage{emptypage}
\usepackage{lipsum}

\newif\ifcolor
\colorfalse
\backgroundsetup{
angle=0,
scale=1,
opacity=1,
contents={}
}

\makeatletter
\AddEverypageHook{%
\backgroundsetup{
contents={
  \ifcolor
    \textcolor{\chaptercolor}{\rule{3em}{3em}}
  \fi}
}
\ifodd\value{page}
  \backgroundsetup{
    position={current page.north east},
    hshift=-1.5cm,vshift=-1cm
    }
\else  
  \backgroundsetup{position={current page.north west},
    hshift=1.5cm,vshift=-1cm
    }
\fi  
\BgMaterial}


\def\chaptercolor{black}
\newcommand\normalchapter{%
\colorfalse%
\titleformat{\chapter}[display]
  {\relax\ifthenelse{\NOT\boolean{@tufte@symmetric}}{\begin{fullwidth}}{}}
  {\itshape\huge\thechapter}
  {0pt}
  {\huge\rmfamily\itshape}
  [\ifthenelse{\NOT\boolean{@tufte@symmetric}}{\end{fullwidth}}{}]
}
\newcommand\colorchapter{%
\colortrue%
\titleformat{\chapter}[display]
  {\relax\color{\chaptercolor}\ifthenelse{\NOT\boolean{@tufte@symmetric}}{\begin{fullwidth}}{}}
  {\itshape\huge\thechapter}
  {0pt}
  {\huge\rmfamily\itshape}
  [\ifthenelse{\NOT\boolean{@tufte@symmetric}}{\end{fullwidth}}{}]
}

\newcommand\ContentColor[1]{%
\titlecontents{chapter}[0em]
    {\vspace{1.5\baselineskip}\begin{fullwidth}\LARGE\rmfamily\itshape%
      \makebox[0pt]{\textcolor{#1}{\rule{1em}{1em}}\hspace{2em}}
    }
    {\hspace*{0em}\thecontentslabel{2em}}
    {\hspace*{0em}}
    {\rmfamily\upshape\qquad\thecontentspage}
    [\end{fullwidth}]
}
\newcommand\ContentNoColor{%
\titlecontents{chapter}%
    [0em]
    {\vspace{1.5\baselineskip}\begin{fullwidth}\LARGE\rmfamily\itshape}
    {\hspace*{0em}\thecontentslabel{2em}}
    {\hspace*{0em}}
    {\rmfamily\upshape\qquad\thecontentspage}
    [\end{fullwidth}] 
}
\makeatother
\newcommand\ChapColor[1]{%
  \def\chaptercolor{#1}
  \ContentColor{#1}
}

\begin{document}

\tableofcontents
\cleardoublepage
\chapter{Introduction}
\lipsum[1-2]
\cleardoublepage
\colorchapter
\ChapColor{Maroon}
\chapter{Test chapter one}
\lipsum[1-4]
\cleardoublepage
\ChapColor{MidnightBlue}
\chapter{Test chapter two}
\lipsum[1-4]
\cleardoublepage
\ChapColor{Dandelion}
\chapter{Test chapter three}
\lipsum[1-4]
\cleardoublepage
\ContentNoColor
\normalchapter
\chapter{Appendix}
\lipsum[1-4]

\end{document}

From the point where you want the color specifications to be active, add

\colorchapter

to your document. For each chapter in this section, select the color with

\ChapColor{<color>}

You can deactivate the color specification at any point using

\normalchapter 

To place the colored marks in chapters with color specification, the background package wes used; this allows you to have complete freedom in the location of the marks.

share|improve this answer
    
When I run that I get about 60 "undefined control sequence} errors and some code up by the tabs on each page: contents= 1.5cm,vshift=-1cm position=current page.north east, hshift=- I can't figure out why it won't compile the way yours does. –  Tim Mar 2 at 20:03
    
@Tim you need an updated version of the background package. Following the link I provided, download the .zip file, run latex on background.ins and move the generated background.sty file either to your local TDS tree or to your working directory (where your .tex file resides). –  Gonzalo Medina Mar 2 at 22:13
    
@Tim let me know if you have any problems with the installation process and I can give you directly the .sty file. –  Gonzalo Medina Mar 2 at 22:17
    
Works beautifully! That's a wonderful little package. Thanks for your help. –  Tim Mar 3 at 0:02
    
@Tim I added a simplified version of the code that might be of interest for you. –  Gonzalo Medina Mar 3 at 0:24

The tufte bundle loads the titletoc and fancyhdr packages, so we can access all of their powerful commands.

In particular, in the code below I have used

% format the toc entries for chapter
\titlecontents{chapter}
[0cm]             % left margin
{}             % above code
{%             % numbered format
    {\llap{\color{\chaptercolor{\thecontentslabel}}\rule{.5cm}{.5cm}}\thecontentslabel\hskip .5cm\Large}%
}%
{}         % unnumbered format
{\titlerule*[.5pc]{.}\contentspage}%

to format the chapter entry in the toc.

toc

I have also used

\fancyhead[R]{\color{\chaptercolor{\the\value{chapter}}}\rule{1cm}{1cm}}

to add a little coloured box to the top of each page.

chapters

Both of these commands use the command

\newcommand{\chaptercolor}[1]{%
    \ifcase#1\relax
    \or
        blue%
    \or
        red%
    \fi%
}

to select the color. You'll need to add more colors as you add more chapter.

I took the liberty of numbering your chapters using

\setcounter{secnumdepth}{0}

If your document is different, we'll need to see a MWE.

% arara: pdflatex
% arara: pdflatex
% !arara: animate: {delay: 80}
\documentclass[a4paper,twoside]{tufte-book}

\setcounter{secnumdepth}{0}
\usepackage{xcolor} % for colour
\usepackage{lipsum} % just for sample text

\newcommand{\chaptercolor}[1]{%
    \ifcase#1\relax
    \or
        blue%
    \or
        red%
    \fi%
}

% fancy head
\fancyhead[R]{\color{\chaptercolor{\the\value{chapter}}}\rule{1cm}{1cm}}

% format the toc entries for chapter
\titlecontents{chapter}
[0cm]             % left margin
{}             % above code
{%             % numbered format
    {\llap{\color{\chaptercolor{\thecontentslabel}}\rule{.5cm}{.5cm}}\thecontentslabel\hskip .5cm\Large}%
}%
{}         % unnumbered format
{\titlerule*[.5pc]{.}\contentspage}%

\begin{document}

\tableofcontents

\chapter{Chapter}
\lipsum[1]
\section{Section}
\lipsum[1]
\subsection{Sub section}
\lipsum[1]
\chapter{Chapter}
\lipsum[1]
\section{Section}
\lipsum[1]
\subsection{Sub section}
\lipsum[1]

\end{document}
share|improve this answer

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.