23

I'm currently writing a book, and I'd like some of the sections to be clearly marked as "difficult" or "optional". Not only sections, but also exercises (I'm using the exercise package) and theorems (that I am defining with newtheorem from amsthm)). Something that would work for arbitrary sectioning levels, environments, etc would be great...

edit: I think I should have also said -- I'd like something like a star at the margin, close to the section/theorem/etc, and, if it's a section or chapter, then there should be a star before it in the text and at the table of contents:

1 Introduction
    1.1 blah
    2.3 blah
2 Some Chapter
    2.1 blah
  * 2.2 this is an optional section 
    2.3 blah blah

edit: it would be nice if the star (or a configurable symbol of course) was placed before the section number.

0

6 Answers 6

7

The titletoc manual introduces an interesting method to do what you are after. It's illustrated best with an example.

\documentclass[11pt,a4paper,english]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[pagestyles,raggedright]{titlesec}
\usepackage{titletoc}
\usepackage{blindtext}

\title{A document with stuff for advanced or optional reading}
\author{Jay}

\newcommand{\secmark}{}
\newcommand{\marktotoc}[1]{\renewcommand{\secmark}{#1}}
\newenvironment{advanced}{
  \renewcommand{\secmark}{*}%
  \addtocontents{toc}{\protect\marktotoc{*}}
}
{\addtocontents{toc}{\protect\marktotoc{}}}

\titleformat{\section}{\normalfont\Large}{\makebox[1.5em][l]{\llap{\secmark}\thesection}}{0.4em}{}
\titlecontents{section}[3.7em]{}{\contentslabel[\llap{\secmark}\thecontentslabel]{2.3em}}{\hspace*{-2.3em}}{\titlerule*{}\bfseries\contentspage}

\newpagestyle{front}{%
  \headrule
  \sethead[\thepage][][\subsectiontitle]{\sectiontitle}{}{\thepage}
  \setfoot[][][]{}{}{}
}

\newpagestyle{main}{%
  \headrule
  \sethead[\thepage][][\thesubsection\quad\subsectiontitle]{\llap{\secmark}\thesection\quad\sectiontitle}{}{\thepage}
  \setfoot[][][]{}{}{}
}
\newpagestyle{back}{%
  \headrule
  \sethead[\thepage][][\subsectiontitle]{\sectiontitle}{}{\thepage}
  \setfoot[][][]{}{}{}
}


\begin{document}
  \frontmatter
  \pagestyle{front}
  \maketitle
  \tableofcontents\newpage

  \mainmatter
  \pagestyle{main}
  \blinddocument
  \begin{advanced}
    \blinddocument
  \end{advanced}
  \blinddocument

  \backmatter
  \appendix
  \pagestyle{back}
\end{document}

This example starts with marking selected sections within a chapter. For marked chapters it needs to be modified accordingly.

As always, the blindtext package is only for creating dummy text, thus is not part of the solution.

1
  • Thank you! Now I can also declare \newcommand{\advsection}[1]{\begin{advanced}\section{#1}\end{advanced}}, which gives me a nice \advsection command. :-)
    – Jay
    Jun 19, 2012 at 2:42
5

I don't have an answer for sections, but I do have one for environments. It allows you to tag the environments you want labelled specially.

\documentclass{article}
\usepackage{ifthen}
\usepackage{xargs}
\usepackage{lipsum}

\setlength{\parindent}{0mm}

\newcounter{problem}
\newcommand{\trickysymbol}{$\clubsuit$ }
\newlength{\trickysymbollength}
\settowidth{\trickysymbollength}{\trickysymbol}
\newenvironmentx{problem}[2][1={},2={},usedefault]{%
    \refstepcounter{problem}%
    \ifthenelse{\equal{#2}{}}%
    {%
        % if no second argument
        \ifthenelse{\equal{#1}{}}%
        {% 
            \textbf{Problem \theproblem }\par%
        }%
        {%
            \textbf{Problem \theproblem \, (#1) }\par%
        }%
    }%
    {%
        % tricky problems
        \ifthenelse{\equal{#2}{tricky}}%
        {%
            \ifthenelse{\equal{#1}{}}%
            {% 
                \hspace{-\trickysymbollength}\trickysymbol\textbf{Problem \theproblem }\par%
            }%
            {%
                \hspace{-\trickysymbollength}\trickysymbol\textbf{Problem \theproblem \, (#1) }\par%
            }%
        }{ \textbf{Problem} \theproblem \, (#1) {\bf\huge\color{red}tricky?}\par}%
    }%
    \ignorespaces%
}%
{%
    \par\noindent\ignorespacesafterend
}%

\begin{document}


\begin{problem}[description goes here]
\lipsum[1]
\end{problem}

\begin{problem}[description goes here][tricky]
\lipsum[1]
\end{problem}

\begin{problem}[][tricky]
\lipsum[1]
\end{problem}

\end{document}
2
  • Hey, that works great for environments - thanks! Now I only need the same for sections (and chapters, perhaps) -- with the same symbol appearing by the section in the text and also before it in the table of contents...
    – Jay
    Jul 27, 2011 at 13:40
  • You're welcome! Looks like some of the other folk have answers for the sections- good luck!
    – cmhughes
    Jul 27, 2011 at 16:27
4

I wouldn't use a symbol in section, I would define a command.

Example:

\documentclass[11pt]{scrartcl}
%\Section with capital S for important sections
\newcommand{\Section}[1]{\section[! #1]{(Important) #1}}
%\newcommand{\Section}[1]{\section[#1\hfill!]{(Important) #1}}

\begin{document}
\tableofcontents
\section{First section}
\Section{Second section}

Your text goes here.

\end{document}

Instead of Section you may use ImportantSection or OptionalSection... So you get a clear markup.

Modified example with optional parameters:

\documentclass[11pt]{scrartcl}
\usepackage{color}
\definecolor{optionalgray}{gray}{.75}

\makeatletter
\newcommand\@ImportantSection[2][]{
  %Define the look of Important sections
  \section[#1 (!)]{(*) #2}
  %\section[#1 (!)]{\textcolor{red}{#2}}
}
\newcommand\ImportantSection{\@dblarg\@ImportantSection}

\newcommand\@OptionalSection[2][]{
  %Define the look of Optional sections
  \section[#1 (!)]{(#2)}
  %\section[#1 (!)]{\textcolor{optionalgray}{#2}}
}
\newcommand\OptionalSection{\@dblarg\@OptionalSection}
\makeatother


\begin{document}
\tableofcontents
\section{First section}
\ImportantSection{Second section}


\ImportantSection[3rd]{Third section}

\OptionalSection[4th]{Fourth section}

\end{document}
2
  • Thank you -- but I'd rather use a symbol (a simple star), as it makes it easier for the reader to spot difficult sections or theorems, etc, and uses less space (some section names are a bit long already).
    – Jay
    Jul 26, 2011 at 19:15
  • Perhaps I misunderstood you. I expected you want to define macros like \section! and a redefinition \section*. There I recommend to use more explicit macros like \ImportantSection. In your comment you write about the reader. Should the symbol to be a part in your LaTeX-Input or in the output? Then take a look in my modified example. There I set a (*) for important sections and optional section are in (). You may define your own look.
    – knut
    Jul 26, 2011 at 19:34
3

This is similar to a problem I had, so use something like

\DeclareRobustCommand{\SymbolInRed}{$\textcolor{red}{\times}$}

and then use this symbol in the section as:

\section{Second Chapter\SymbolInRed}

See Undefined color error, if have symbol in Chapter Title for more info on this.

1

As for adding stars to the toc then this might help (as long as it is numbered, in which case the with of the number part is in \@tempdima)

\documentclass[a4paper]{article}
\usepackage{etoolbox}
\newtoggle{activestar}
\makeatletter
\DeclareRobustCommand\mystar{%
  \iftoggle{activestar}{%
    \llap{$*$\kern0.2em\kern\@tempdima}%
  }{}%
  \ignorespaces
}
\makeatother
\begin{document}
\toggletrue{activestar}
\tableofcontents
\togglefalse{activestar}

\section{\mystar{}Test}
\section{Test}
\end{document}

Of course it would be recommend to define a \specialsection or similar as other have mentioned.

As for marking in the text, it might be more helpful to the reader if the author used a marginal note to specify that this is special.

0

Since I can not comment or upvote, I have to post this as an answer. Thanks for all the answers here, especially Thorsten Donig's answer worked like a charm. One small thing, regarding Jay's comment on declaring a new advsection command on this answer.

It is better to declare \newcommand{\advsection}[1]{\section*{}\begin{advanced}\section{#1}\end{advanced}}. This way, it behaves like a normal section. Otherwise, the spacing is too low when you start a new section after ending the special section.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .