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.

Suppose I am writing a book in which some sections are especially important. I would like those sections to be identified by a * after the page number in the table of contents. How do I get it there?

I can get extra stuff into the table of contents by putting \addtocontents into my text at appropriate places. So in this case I'd presumably write something like \addtocontents{\protect\marginpar{*}} in my text in appropriate places.

But that's not right, because \marginpar tries to put its contents into the outside margin. I always want to put the * into the right margin, regardless of whether I'm on an even or odd page.

It seems like it should be extremely easy to do this, but I can't see how. Suggestions?

share|improve this question
    
    
It helps partly. However, I don't really want to put the symbol along with the section number; I want to put it after the page number so that it sticks out into what would otherwise be the margin of the table of contents. Also, ideally I would not want to have to decide as part of the section macro whether to use the special symbol; I'd like it to appear if and only if I invoke a particular macro at any time within the section body (which is part of why I'd like the symbol to appear at the end rather than the beginning of the table-of-contents line). –  Andrew Koenig Feb 5 '12 at 2:59
add comment

1 Answer 1

Using \marginpar may not be the best way to do this, but it is in fact not too difficult to set up (assuming there aren't any other \marginpars within the scope of the TOC, but then there wouldn't be any normally).

So what what needs doing? Basically when the \marginpar is encountered we have to prevent LaTeX from choosing the outside margin. Instead we have to make it do what it it does when the option twoside isn't choosen. And that is basically setting the switch @mparswitch to false before typesetting the TOC and to true afterwards (if \marginpars within the document should switch margins. This could then look like this:

\documentclass[twoside]{article}
\usepackage{fixltx2e}
\MakeRobust\marginpar

\makeatletter
   \def\marginparright{\@mparswitchfalse}
   \def\marginparoutside{\@mparswitchtrue}
\makeatother

\usepackage{lipsum}

\begin{document}
\marginparright \tableofcontents \marginparoutside

\section{foo}
\lipsum[2]

\section[Important\marginpar{*}]{Important}
test \marginpar{outside?}
\lipsum[1]

\addtocontents{toc}{\protect\newpage} % generate a pagebreak in toc for testing

\section[Again Important\marginpar{*}]{Again Important on page 2 in TOC}
test \marginpar{outside?}
\newpage
\lipsum[1]\marginpar{outside?}
\end{document}

And the result (second page) would be:

enter image description here

share|improve this answer
    
Thank you -- I'll give that a try. –  Andrew Koenig Mar 14 '12 at 23:49
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.