2

After some attempts with fancyhdr and titlesec I was able to get what I wanted about running heads and first pages of chapters. Honestly I didn't understand every line I put into the code, so many things can probably be done in a better way, but for now I feel satisfied. My last problem would be the table of contents, that I'd like to customize, but I hardly know where to begin. I possibly received some input in a previous answer, but it was focused on another aspect and I'd like to be sure to work on a solution compatible with my new aesthetical requirements and with what I've done up to know. So, here is my MWE:

\documentclass[11pt,twoside]{book}
\usepackage[a5paper,inner=14mm,outer=20mm,top=21mm,bottom=22.5mm]{geometry}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{textcomp}
\usepackage{gensymb}
\usepackage{graphicx}
\usepackage{units}
\usepackage{tcolorbox}

\usepackage{mwe}

\usepackage{titlesec}
\titleformat{\chapter}[display]
{\normalfont\Large\filcenter\rmfamily}
{\LARGE\sf\MakeUppercase{\chaptertitlename} \huge\thechapter}
{0.5pc}
{\color{green}\titleline*[c]{\titlerule[3pt]}\color{black}
\vspace{1pc}%
\Huge\bf}[\vspace{6pt}]
\setlength{\titlewidth}{0.7\textwidth}

\usepackage{fancyhdr}
\pagestyle{fancy}
\headheight=14pt
\fancyhf{}
\fancyhead[LE,RO]{\textsf{\thepage}}
\fancyhead[LO]{\leftmark}
\renewcommand{\chaptermark}[1]{\markboth{\textsf{\textit{\small{\MakeUppercase%
{\chaptername}}\ \normalsize{\thechapter}}\quad\, #1}}{}}
\fancyhead[RE]{\textsf{\textit{John Doe}\quad\, \small{A SHORT ESSAY ON NOTHING}}}
\renewcommand{\headrulewidth}{3pt}
\let\oldheadrule\headrule
\renewcommand{\headrule}{{\color{green}\oldheadrule}}

\fancypagestyle{plain}{
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
}

\begin{document}

\tableofcontents

\setcounter{chapter}{-1}
\renewcommand*{\thechapter}{}% get rid of the number
\makeatletter\renewcommand*{\@chapapp}{Introduction}\makeatother
\chapter{There is a title here too}
\lipsum[1-3]

\renewcommand*{\thechapter}{\arabic{chapter}}% bring back the chapter numbers
\makeatletter\renewcommand*{\@chapapp}{\chaptername}\makeatother% and the chapter name
\chapter{Title of Chapter One}
\lipsum

\chapter{Title of Chapter Two}

\chapter{Title of Chapter Three is longer}

\chapter{Short}

\chapter{Other normal title}
\chapter{Other normal title}
\chapter{Other normal title}
\chapter{Other normal title}
\chapter{Other normal title}
\chapter{Other normal title}
\chapter{Other normal title}
\chapter{Other normal title}

\end{document}

The pages it produces at each chapter beginning are like this:

enter image description here

Accordingly, the table of contents I get without any customization is this:

enter image description here

The result I'd like to reach is this (I did it with Word):

enter image description here

The main details to pay attention to would be:

  • the word "CONTENTS" should be treated as "CHAPTER 1", not as its title, so it should sit above the green line and be capitalized sans serif.

  • the number of the chapters at each entry are purposely a little bigger than the word "CHAPTER" (italic, capitalized, sans serif)

  • the name of the chapter is preferably bold, if the long titles can do it in a single line

  • page numbers are sans serif

  • the separation between the lines, as well as the vertical space above and below "CONTENTS", should be customizable so that I can make sure that up to 15 chapters do no need an additional page

  • bonus question: I must ensure that pages before and after the toc are empty (they have headers, I'm not sure if this is related with the toc itself, possibly it's my fault having messed up with fancyhdr)

I'm not asking the full code, I'm willing to do it myself, but I need some explanations and suggestions about the correct package and its functions to be able to perform all these changes with respect to the default, possibly (this is a plea) saving all I've done so far!

Thank you very much!


Since I was asked, this is the result of the chapter counter stuff: an introduction with a title but not affecting the following chapters numbering. It is something I definitely want to save:

enter image description here

3
  • 1
    Don't use such naugthy words in there: 'Created with WORD` ;-) And there are too many requests in one post, in my point of view. Why \setcounter{chapter}{-1}? – user31729 Oct 24 '17 at 16:57
  • Eh eh, if I were able to do it with LaTeX... – lesath82 Oct 24 '17 at 17:20
  • @ChristianHupfer the counter set to -1 was to have "introduction" as number 0, then start again with regular chapter numbering – lesath82 Oct 24 '17 at 17:22
2

Here is a solution. For the table of contents problem, I use the numberless key of titlesec to define an ad hoc formatting, and the titletoc package. I took the opportunity to make some corrections to your code (things like \bfseries in the place of \bf, which has been deprecated for more than 20 years).

For your unnumbered chapter right after the table of contents, I had to define an adapted page style, nonumber. I defined page styles with  titleps, which I find easier to use than fancyhdr.

As to your ‘bonus question’, deleting footers and headers in pages with no text is verysimple: it's obtained with the clearempty option of titlesec.

\documentclass[11pt,twoside, x11names]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[a5paper,inner=14mm,outer=20mm,top=21mm,bottom=22.5mm]{geometry}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{textcomp}
\usepackage{gensymb}
\usepackage{graphicx}
\usepackage{units}
\usepackage{tcolorbox}

\usepackage{mwe}

\usepackage[clearempty, pagestyles]{titlesec}
\usepackage[rightlabels]{titletoc}
        \titlecontents{chapter}
        [6.55em] %5.3
        {\bigskip}
        {\contentslabel[\textsf{\itshape\footnotesize\MakeUppercase{\chaptername}~\thecontentslabel}]{6.55em}\quad\textbf}%\thecontentslabel
        {\hspace*{-6.55em}\textbf}% unnumbered chapters
        {\hfill\sffamily\contentspage}[\smallskip]%
    %

\titleformat{\chapter}[display]
{\thispagestyle{empty}\normalfont\Large\filcenter\rmfamily}
{\LARGE\sffamily\MakeUppercase{\chaptertitlename} \huge\thechapter}
{0.5pc}
{\color{DarkSeaGreen3}\titleline*[c]{\titlerule[3pt]}\color{black}
%
\Huge\bfseries}[\vspace{6pt}]

 \titleformat{name=\chapter, numberless}[block]
 {\thispagestyle{empty}\vspace*{0.7ex}\normalfont\LARGE\filcenter\sffamily}
 {}
 {0em}
 {\MakeUppercase}[\vspace{-0.8ex}{\color{DarkSeaGreen3}\rule{\titlewidth}{3pt}}]%

 \setlength{\titlewidth}{0.7\textwidth}

\newpagestyle{mystyle}{%
\renewcommand{\makeheadrule}{\color{DarkSeaGreen3}\rule[-1.2ex]{\linewidth}{3pt}}
%%
\sethead[\sffamily\thepage][][\sffamily\textit{John Doe}\quad\small A SHORT ESSAY ON NOTHING]%
{\sffamily\small\textit{\MakeUppercase{\chaptername}}~\thechapter\quad\normalsize\chaptertitle}{}{\sffamily\thepage}%
\setfoot{}{}{}
}
%
\newpagestyle{nonumber}{%
\renewcommand{\makeheadrule}{\color{DarkSeaGreen3}\rule[-1ex]{\linewidth}{3pt}}
%%
\sethead[\sffamily\thepage][][\sffamily\textit{John Doe}\quad\small A SHORT ESSAY ON NOTHING]%
{\sffamily\chaptertitle}{}{\sffamily\thepage}%
\setfoot{}{}{}
}

\begin{document}

\tableofcontents

\clearpage
\pagestyle{nonumber}
{
\titleformat{name=\chapter, numberless}[display]
{\thispagestyle{empty}\vspace*{0.6ex}\normalfont\Large\filcenter\rmfamily}
{\LARGE\sffamily INTRODUCTION}
{0.55pc}
{\color{DarkSeaGreen3}\titleline*[c]{\titlerule[3pt]}\color{black}
\Huge\bfseries}[\vspace{6pt}]
\chapter*{There is a title here too}}
\addcontentsline{toc}{chapter}{\textsf{\mdseries\itshape\footnotesize INTRODUCTION}\quad There is a title here too}
\chaptermark{\textsf{\mdseries\itshape\footnotesize INTRODUCTION}\quad There is a title here too}
\lipsum%[1-3]}
\clearpage
\pagestyle{mystyle}
\chapter{Title of Chapter One}
\lipsum

\chapter{Title of Chapter Two}

\chapter{Title of Chapter Three is longer}

\chapter{Short}

\chapter{Other normal title}
\chapter{Other normal title}
\chapter{Other normal title}
\chapter{Other normal title}
\chapter{Other normal title}
\chapter{Other normal title}
\chapter{Other normal title}
\chapter{Other normal title}

\end{document} 

enter image description here enter image description here enter image description here

9
  • titleps is loaded with the pagestyles option of titlesec if that is what you mean. Next it comes into action for the definition of the two page styles, at the end of the preamble. For the appearance of the characters, there's nothing I've changed. Maybe loading the T1 version of the default fonts? It uses the ec fonts, but I've never noticed any difference with cm. Do you mean what you obtain when you compile my code, or the image I posted? – Bernard Oct 25 '17 at 9:38
  • 1
    Try \clearpage\thispagestyle{empty} , removing the [clearempty] option of titlesec. Note it's up to you, but it is against typographic tradition: when a chapter is ended, it is ended. – Bernard Oct 25 '17 at 10:47
  • 1
    It's a different point of view. Typographic tradition is mainly for non-scientific books. – Bernard Oct 25 '17 at 11:17
  • 1
    The input encoding is denotes the way your TeX code (what you type) is encoded (since ultimately, when you type ‘Hello word’, the file contains only a succession of bits). Initially, TeX used only asciiencoding, where characters are coded from 0 to 127 (e.g. the capital H has (decimal) code 65). This is quite unsufficient for accented letters. Thus a number of encodings emerged through years, more or less depending on the operating system (AppleMac, Windows AnsiNew, Latin1, &c.). – Bernard Oct 26 '17 at 23:46
  • 1
    In 1991, appeared a system named Unicode, designed to encode all possible alphabets for all languages in the world. UTF8 is so called ‘Universal Transformation Format’, which is compatible with ascii (which implies programs, written in ascii, will work without any modification). As to your last question, the main point is that the encoding declared to LaTeX has to be the real encoding of your file. But normally your pdf will be absolutely universal if this rule is respected. – Bernard Oct 26 '17 at 23:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.