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 really in love with the TOC one gets using the accepted answer at Adding a per-chapter image along with group of entries in ToC.

However, instead of having sections in my TOC, I'd like to include brief descriptions of the chapter contents. But try as I might, I can't get these descriptions to not overwrite the images. I've tried the following, yet none work:

Is there a way to get this text to behave nicely, and stay away from the images? Here's an example of what I'm talking about:

\documentclass{scrbook}

\usepackage{geometry}% http://ctan.org/pkg/geometry
\usepackage{titletoc}% http://ctan.org/pkg/titletoc
\usepackage[export]{adjustbox}% http://ctan.org/pkg/adjustbox
\usepackage{xparse}% http://ctan.org/pkg/xparse
\usepackage{titlesec}
\usepackage{tocloft}


\NewDocumentCommand{\rtocstuff}{O{10pt} m O{80pt}}{% \rtocstuff[<gap>]{<content>}[<width>
    \titlecontents{chapter}
      [0pt]% left margin indent
      {\bigskip\bfseries}% chapter ToC formatting
      {\makebox[1.5em][l]{\thecontentslabel}}% chapter label (numbered)
      {\hspace*{1.5em}}% chapter label (unnumbered)
      {\titlerule*[1pc]{.}% dotted contents line
       \thecontentspage% ToC page number
       \hspace*{#1}% gap between page number & <content>
       \smash{% remove vertical height of image
         \raisebox{1.5ex}{% align with top of character
           \hspace*{#3}% space for <content>
           \llap{% left overlap
             #2\hspace*{#1}% actual <content>
      }}}}%
      \titlecontents{section}
      [0pt]% left margin indent
      {\normalfont}% section ToC formatting
      {\hspace*{1.5em}\makebox[2.3em][l]{\thecontentslabel}}% section label (numbered)
      {\hspace*{3.8em}}% section label (unnumbered)
      {\titlerule*[1pc]{.}% dotted contents line
       \thecontentspage% ToC page number
       \hspace*{#1}% gap between page number & <content>
       \hspace*{#3}% gap for <content>
      }
}
\NewDocumentCommand{\ltocstuff}{O{80pt} m O{10pt}}{% \ltocstuff[<width>]{<content>}[<gap>]
    \titlecontents{chapter}
      [0pt]% left margin indent
      {\bigskip\bfseries}% chapter ToC formatting
      {\smash{% remove vertical height of image
         \raisebox{1.5ex}{% align with top of character
           \rlap{% right overlap
             #2% actual content
           }\hspace*{#1}% space for <content>
       }}%
       \hspace*{#3}% gap between <content> and ToC entries
       \makebox[1.5em][l]{\thecontentslabel}}% chapter label (numbered)
      {\smash{% remove vertical height of image
         \raisebox{1.5ex}{% align with top of character
           \rlap{% right overlap
             #2% actual <content>
           }\hspace*{#1}% space for <content>
       }}%
       \hspace*{1.5em}}% chapter label (unnumbered)
      {\titlerule*[1pc]{.}% dotted contents line
       \thecontentspage% ToC page number
      }
     \titlecontents{section}
      [0pt]% left margin indent
      {\normalfont}% section ToC formatting
      {\hspace*{#1}% space for <content>
       \hspace*{#3}% gap between <content> and ToC entries
       \hspace*{1.5em}\makebox[2.3em][l]{\thecontentslabel}}% section label (numbered)
      {\hspace*{3.8em}}% section label (unnumbered)
      {\titlerule*[1pc]{.}% dotted contents line
       \thecontentspage% ToC page number
      }
}

\usepackage{lipsum}% http://ctan.org/pkg/lipsum

\newcommand{\ccpt}[1]{\cftchapterprecistoc{#1}}

\begin{document}

\setcounter{tocdepth}{0}
\contentsmargin{0pt}% Remove right margin in ToC
\tableofcontents

\rtocstuff{\includegraphics[valign=T,width=70pt]{tiger}}
\chapter{Coordinates of points}
\ccpt{We will explore how to find the coordinates of various points in the 2-dimensional and 3-dimensional Euclidean spaces.}

\section{Rectangular coordinates} \lipsum[1]
\section{Projections of a segment on the axes} \lipsum[2]
\section{Distance between two points} \lipsum[3]
\section{The mid-point of a segment} \lipsum[4]
\section{Division of a segment in any ratio} \lipsum[5]
\section{Oblique coordinates} \lipsum[6]

\ltocstuff{\includegraphics[valign=T,width=70pt]{tiger}}
\chapter{The locus of an equation}
\ccpt{We will explore how to find the coordinates of various points in the 2-dimensional and 3-dimensional Euclidean spaces.}

\section{First illustrations} \lipsum[1]
\section{Curve plotting} \lipsum[2]
\section{Test that a point lie on a curve} \lipsum[3]
\section{Intercepts} \lipsum[4]
\section{Points of intersection of two curves} \lipsum[5]
\section{Oblique coordinates} \lipsum[6]

\rtocstuff{\includegraphics[valign=T,width=70pt]{tiger}}
\chapter{The straight line}

\section{Equation in terms of point and slope} \lipsum[1]
\section{Line through two points} \lipsum[2]
\section{The general equation of first degree} \lipsum[3]
\section{Parallel and perpendicular lines} \lipsum[4]
\section{Angle between two lines} \lipsum[5]
\section{Distance from a point to a line} \lipsum[6]

\end{document}
share|improve this question
    
I think the best solution is to typeset everything in a single box next to the figure. See my answer. I am still not satisfied with the typesetting aspects, however: could you please give me an example of the types of images you intend to use? Depending on their shape, it may be better to let the numbers hang out of the margins. –  mforbes May 8 '12 at 20:22

1 Answer 1

up vote 5 down vote accepted

Here is a partial solution. I basically typeset the entire entry in a box of the appropriate width and then stack the image and this box next to each other. The downside of this approach is that it does not make use of the titletoc features: i.e. you must manually deal with positioning the page number and chapter number.

Solutions adhering more to the titletoc format work too, but if the entries in a particular section do not take up enough space, then the image will overlap with the following section. One change in interface I made was to require \ccpt before the chapter so that the information is available when the chapter is typeset (otherwise it is difficult to get it inside the box for maintaining the vertical spacing).

Finally, I am not sure what the best typographic choices are here: should the chapter numbers hang in the left-aligned sections? (Probably if the image has a sharp border: probably not if the image has weak lines.) Likewise, should the page numbers stick out to the right? Both the page numbers and chapter numbers can cause trapped whitespace that looks bad.

Anyway, these are all fine-tuning details that I will try to get back to, but I wanted to give you a sketch of how this can work.

\documentclass{scrbook}

\usepackage{geometry}% http://ctan.org/pkg/geometry
\usepackage{titletoc}% http://ctan.org/pkg/titletoc
\usepackage[export]{adjustbox}% http://ctan.org/pkg/adjustbox
\usepackage{xparse}% http://ctan.org/pkg/xparse
\usepackage{etoolbox}
\usepackage{titlesec}
%\usepackage{calc}
%\usepackage{tocloft}

\newkomafont{precisentry}{\mdseries\itshape}
\setkomafont{chapterentry}{\bfseries}

\newsavebox{\mytocbox}
\newsavebox{\myfigbox}
\newlength{\mytext}
\newcommand{\myleftskip}{1.5em}  % Space for chapter numbers
\newcommand{\myrightskip}{1.5em} % Space for page numbers

\newif\ifmyrightfig
\newcommand{\titlebox}[4][1em]{%
  %\titlebox[<sep>]{<figure>}{<content>}
  \savebox{\myfigbox}{%
    \raisebox{0.9ex} % Adjust to match fig to letter height.
             {#2}}%
  \settowidth{\mytext}{\usebox{\myfigbox}}%
  \addtolength{\mytext}{-2\mytext}% -\widthof{\myfigbox}
  \addtolength{\mytext}{\textwidth}%
  \addtolength{\mytext}{-#1}%
  \addtolength{\mytext}{-\myleftskip}%
  \addtolength{\mytext}{-\myrightskip}%
  \savebox{\mytocbox}{\parbox[t]{\mytext}{%
      {\usekomafont{chapterentry}%
        \contentslabel{\myleftskip}%
        #3%
        \titlerule*[1pc]{.}\thecontentspage}\\*
      {\usekomafont{precisentry}\csuse{precis}}}}%
  \hbox{%
    \ifmyrightfig
      \hspace{\myleftskip}%
      \usebox{\mytocbox}%
      \hspace{#1}%
      \usebox{\myfigbox}%
    \else
      \usebox{\myfigbox}%
      \hspace{#1}%
      \hspace{\myleftskip}%
      \usebox{\mytocbox}
      \fi}}

\newcommand{\tocstuff}[2][30pt]{
  \titlecontents{chapter}
  [0.0pt]% left margin indent
  {\bigskip}% chapter ToC formatting
  {\titlebox[#1]{#2}}
  {}% chapter label (unnumbered)
  {}% ToC page number
}
\newcommand{\ltocstuff}[2][30pt]{
  \addtocontents{toc}{\protect\myrightfigfalse}
  \tocstuff[#1]{#2}
}
\newcommand{\rtocstuff}[2][30pt]{
  \addtocontents{toc}{\protect\myrightfigtrue}
  \tocstuff[#1]{#2}
}

\usepackage{lipsum}% http://ctan.org/pkg/lipsum

%\newcommand{\ccpt}[1]{\cftchapterprecistoc{#1}}
\newcommand{\defprecis}[1]{\gdef\precis{#1}}
\newcommand{\ccpt}[1]{\addtocontents{toc}{\protect\defprecis{#1}}}


\begin{document}

\setcounter{tocdepth}{0}
\contentsmargin{0pt}% Remove right margin in ToC
\tableofcontents

\rtocstuff{\colorbox{cyan}{\includegraphics[valign=T,width=70pt]{tiger}}}
\ccpt{We will explore how to find the coordinates of various points in the 2-dimensional and 3-dimensional Euclidean spaces.}
\chapter{Coordinates of points with a long title that does not wrap properly and
causes problems}

\section{Rectangular coordinates} \lipsum[1]
\section{Projections of a segment on the axes} \lipsum[2]
\section{Distance between two points} \lipsum[3]
\section{The mid-point of a segment} \lipsum[4]
\section{Division of a segment in any ratio} \lipsum[5]
\section{Oblique coordinates} \lipsum[6]

\ltocstuff{\colorbox{cyan}{\includegraphics[valign=T,width=70pt]{tiger}}}
\ccpt{We will explore how to find the coordinates of various points in the 2-dimensional and 3-dimensional Euclidean spaces.}
\chapter{The locus of an equation}

\section{First illustrations} \lipsum[1]
\section{Curve plotting} \lipsum[2]
\section{Test that a point lie on a curve} \lipsum[3]
\section{Intercepts} \lipsum[4]
\section{Points of intersection of two curves} \lipsum[5]
\section{Oblique coordinates} \lipsum[6]

\rtocstuff{\colorbox{cyan}{\includegraphics[valign=T,width=70pt]{tiger}}}
\chapter{The straight line}

\section{Equation in terms of point and slope} \lipsum[1]
\section{Line through two points} \lipsum[2]
\section{The general equation of first degree} \lipsum[3]
\section{Parallel and perpendicular lines} \lipsum[4]
\section{Angle between two lines} \lipsum[5]
\section{Distance from a point to a line} \lipsum[6]

\end{document}

enter image description here

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.