Page LayoutToC Entries, Section Headings, running Headers

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
texasAUtiger
Posts: 4
Joined: Wed Nov 23, 2011 12:15 am

ToC Entries, Section Headings, running Headers

Post by texasAUtiger »

I am using the standard book documentclass, and am using setting up section in the standard way:

Code: Select all

\section{A Big Section}
I am happy for this title, A Big Section, to be used as the running head, so I do not use a short section name.

However, now I want the ToC entry for this section to be starred, without affecting the section name itself (in the body of the book) or the running head in that section. So I do this:

Code: Select all

\section[A Big Section*]{A Big Section}
but of course, it makes the running head becomes starred, which I don't want.

I hope I am missing something obvious where one make these three distinct: between, e.g., a long section name, a short section name, and the ToC section name.

For a little more specificity, here's a minimal working example showing my use of fancyhdr and titlesec. Closer, but not there yet...

Code: Select all

\documentclass[10pt,openright]{book}

%\usepackage[toctitles]{titlesec}

\usepackage{fancyhdr}
\pagestyle{fancy}
%\usepackage{calc}
%\fancyheadoffset[LE,RO]{\marginparsep+\marginparwidth}
\fancyheadoffset{0in}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
\fancyhf{}
\fancyhead[LE,RO]{\thepage}
%\newcommand{\helv}{%
%\fontfamily{phv}\fontseries{b}\fontsize{9}{11}\selectfont}
\fancyhead[LO]{\sf\rightmark}
\fancyhead[RE]{\sf\leftmark}
\fancypagestyle{plain}{%
\fancyhead{} % get rid of headers
\renewcommand{\headrulewidth}{0pt} % and the line
}

\begin{document}

\tableofcontents

\chapter{Something}

\section{Nothing to See}

blah

\newpage

blah blah

\newpage

\section[toc only]{section title}

blah

\newpage

blah blah

\newpage

\end{document}
Thanks for any input.
Last edited by texasAUtiger on Mon Nov 28, 2011 8:01 am, edited 2 times in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

ToC Entries, Section Headings, running Headers

Post by localghost »

If I understand you right, the below code should do what you want. It uses the combination of the packages titlesec and titletoc.

Code: Select all

\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage[pagestyles,raggedright]{titlesec}
\usepackage{titletoc}
\usepackage{lipsum}

\newpagestyle{main}{%
  \headrule
  \sethead[\thepage][][\sffamily\chaptertitle]{\sffamily\thesection\ \sectiontitle}{}{\thepage}
}
\pagestyle{main}

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

\titlecontents{section}[3.8em]{}{\contentslabel[\thecontentslabel]{2.3em}}{\hspace*{-2.3em}}{\secmark\titlerule*[0.8pc]{.}\contentspage}

\begin{document}
  \tableofcontents

  \chapter{Chapter Title}

    \marked
    \section{Marked Section}
      \lipsum[1-12]

      \newpage

    \unmarked
    \section{Normal Section}
      \lipsum[1-12]
\end{document}
Note that the fancyhdr package was dropped in favor of titlesec because the latter one also provides pages styles with customized headers and footers. Your code has been translated correspondingly.


Thorsten
texasAUtiger
Posts: 4
Joined: Wed Nov 23, 2011 12:15 am

Re: ToC Entries, Section Headings, running Headers

Post by texasAUtiger »

That worked wonderfully. Thank you!

Quick follow up: replacing my fancyhdr setting with yours has resulted in a page number being printed on the bottom center of a new chapter page.

I need for there to be no page number on the bottom of a new chapter page.

Can you tell me how to accomplish this in your implementation?
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

ToC Entries, Section Headings, running Headers

Post by localghost »

One simple line in the preamble of your document should do.

Code: Select all

\assignpagestyle{\chapter}{empty}
Must have overlooked that in your example.
texasAUtiger
Posts: 4
Joined: Wed Nov 23, 2011 12:15 am

Re: ToC Entries, Section Headings, running Headers

Post by texasAUtiger »

Exactly what I needed. Thanks again for your help.
texasAUtiger
Posts: 4
Joined: Wed Nov 23, 2011 12:15 am

ToC Entries, Section Headings, running Headers

Post by texasAUtiger »

localghost wrote:One simple line in the preamble of your document should do.

Code: Select all

\assignpagestyle{\chapter}{empty}
Must have overlooked that in your example.
Ok, I got to the end of my project and included the index via

\printindex

and it has a page number on the bottom center. Ugh!

I thought that setting new chapter pages to have an empty style would do this for the first page of the index as well, but it doesn't.

I have tried several things to no avail. Any help would be greatly appreciated!
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

ToC Entries, Section Headings, running Headers

Post by localghost »

That's odd. I suggest to use the imakeidx package and study Section 3 of its manual. Drop any other index related package that you used before.
Post Reply