7

General question

I need to redefine how starred version of \chapter command (that is \chapter*) works in book class.

I found definition of not-starred version of \chapter command in book class:

\def\@makechapterhead#1{%
  \vspace*{50\p@}%
  {\parindent \z@ \raggedright \normalfont
    \ifnum \c@secnumdepth >\m@ne
      \if@mainmatter
        \huge\bfseries \@chapapp\space \thechapter
        \par\nobreak
        \vskip 20\p@
      \fi
    \fi
    \interlinepenalty\@M
    \Huge \bfseries #1\par\nobreak
    \vskip 40\p@
  }}

According to this SO answer there should be @ifstar somewhere inside that definition, but I can not find it.

How and where is starred version of \chapter defined then?


My specific case

To give general idea why I need this here is explaination:

I have document which require me that chapter headings consist of two parts: (1) Descriptive chapter number (Chapter One etc. so it can't use regular \chapter command) and (2) descriptive title below number that can be long. I was able to push descriptive title below chapter number and style it according to my needs with following macro:

\documentclass[final]{book}
\usepackage{lipsum}

\def \mylongchapter#1#2{
\chapter*{\centering{\LARGE #1} \\* \textnormal{\Large #2}}
\addcontentsline{toc}{chapter}{#1: #2}
}

\begin{document}

\mylongchapter{Chapter One}{This Chapter Have Very Interesting and Long Title Below Chapter Number}

\lipsum[11-30]

\end{document}

Which gives:

I want to control spacing between two lines of chapter headings (space marked with red lines on screenshot):

  • To debug, go back to book.cls find the definition of \chapter, it ends with \secdef\@chapter\@schapter, so one of these are the normal, the other is the starred. Actually you will find \@makechapterhead just below the mabove line, and a little further down you will bind the starred equivalent to the code you posted. – daleif Jun 2 '14 at 13:46
  • I think, it is \@schapter – user31729 Jun 2 '14 at 13:47
  • BTW: If you do not know your way around a class file, why are you rewriting like this anyway instead of using a package like titlesec? – daleif Jun 2 '14 at 13:47
  • What should your \chapter* command do? – user31729 Jun 2 '14 at 13:48
  • @ChristianHupfer I need to control (decrease) spacing between lines of \chapter* heading and I figured out that I should use \onehalfspacing command from setspace package. So I am trying to re-define \chapter* so I can use that command inside of it. – Rafal Jun 2 '14 at 13:59
3

I changed the definition of \@makeschapterhead, by adding \centering inside and the custom spacing command\mycustomspacing[factor]`, all applied in a group, so outside spacing is not affected!

I my code I used a factor of 0.8, it works, but it does not look good, from a typographical point of view.

\documentclass{book}

\usepackage{blindtext}
\usepackage{etoolbox}
\usepackage{calc}
\usepackage{setspace}
\makeatletter


\newrobustcmd{\mynewstarredchapter}{%
\@ifnextchar[{\mynewstarredchapter@opt}{\mynewstarredchapter@noopt}%
}%

\newrobustcmd{\mynewunstarredchapter}{%
\@ifnextchar[{\mynewunstarredchapter@opt}{\mynewunstarredchapter@noopt}%
}%

\let\LaTeXStandardChapter\chapter%

\newrobustcmd{\mycustomspacing}[1][1.0]{%
\let\originalbaselineskip\baselineskip
\setlength{\baselineskip}{#1\originalbaselineskip}%
}%


\def\@makeschapterhead#1{%  
  \vspace*{50\p@}%
  {\parindent \z@ \raggedright
    \normalfont
    \interlinepenalty\@M
    {  
    \Huge \bfseries \centering\mycustomspacing[0.8]#1 \par\nobreak
    }
    \vskip 40\p@
  }}




\newrobustcmd{\mynewunstarredchapter@opt}[2][]{%
\LaTeXStandardChapter[#1]{#2}%
}%

\newrobustcmd{\mynewunstarredchapter@noopt}[1]{%
\LaTeXStandardChapter{#1}%
}%

\newrobustcmd{\mynewstarredchapter@opt}[2][]{%
\LaTeXStandardChapter*{#2}%
}%

\newrobustcmd{\mynewstarredchapter@noopt}[1]{%
\LaTeXStandardChapter*{#1}%
}%




\renewcommand{\chapter}{%
\@ifstar{\mynewstarredchapter}{\mynewunstarredchapter}%
}%


\begin{document}
\tableofcontents
\chapter{First}
\chapter*{Starred First}
\blindtext
\chapter[Second]{2nd Chapter}
\blindtext

\chapter*[Well, useless so far]{2nd starred chapter}
\blindtext





\chapter*{This Chapter Have Very Interesting and Long Title Below Chapter Number}%

%\chapter*[Well, useless so far]{3nd starred chapter}
\blindtext

\end{document}

enter image description here

Requested reduced version, without starred redefinition ...

\documentclass{book}

\usepackage{blindtext}
\usepackage{calc}
\usepackage{setspace}

\makeatletter
\newcommand{\mycustomspacing}[1][1.0]{%
\let\originalbaselineskip\baselineskip%
\setlength{\baselineskip}{#1\originalbaselineskip}%
}%


\def\@makeschapterhead#1{%  
  \vspace*{50\p@}%
  {\parindent \z@ \raggedright
    \normalfont
    \interlinepenalty\@M
    {%  
    \Huge \bfseries \centering\mycustomspacing[0.8]#1 \par\nobreak
    }%
    \vskip 40\p@
  }}%
\makeatother


\begin{document}
\chapter*{This Chapter Have Very Interesting and Long Title Below Chapter Number}%

\blindtext

\end{document}
  • My original comment under question was unclear what spacing I meant. I have added information to question for clarity. What you presented in first part of your answer is spacing above and below chapter heading. I need to manipulate spacing between lines of chapter headings. – Rafal Jun 2 '14 at 14:24
  • 1
    I think, that you should rather use \singlespacing instead of \onehalfspacing – user31729 Jun 2 '14 at 14:46
  • I figured it out too, three minutes ago :) \onehalfspacing doesn't change anything (I guess it is default). `\singlespacing`` decreases this space, though not to extent I would like it to, unfortunately. So I still don't have perfect solution. One would think there should be some easy way to control line spacing in headings, but there doesn't seem to be one. – Rafal Jun 2 '14 at 14:49
  • Thanks! It looks like you have solved my problem. One quesiton though - is this really minimal possible amount of code/definitions needed for it to work? I am not sure if all those \newrobustcmd commands are needed there. I tried to comment parts of code to figure it out, but I still do not have any success in compressing this code to minimal size required for it to work. – Rafal Jun 2 '14 at 15:15
  • 1
    Updated, blindtext can be removed too, if needed ;-) – user31729 Jun 2 '14 at 15:20
9

The definition of \chapter doesn't have \@ifstar:

% book.cls, line 360:
\newcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi
                    \thispagestyle{plain}%
                    \global\@topnum\z@
                    \@afterindentfalse
                    \secdef\@chapter\@schapter}

The \secdef macro has \@ifstar; it's a general purpose macro used also for \part; what happens when \chapter is found is that some action are performed (a possible \cleardoublepage, the setting of the page style, disallowing top floats for the page and declaring no indentation for the first paragraph after the chapter title) and then

\secdef\@chapter\@schapter

is executed. The definition of \secdef is

% latex.ltx, line 5731:
\def\secdef#1#2{\@ifstar{#2}{\@dblarg{#1}}}

so here is \@ifstar. Basically, when \chapter*{Title} appears, LaTeX will find

\secdef\@chapter\@schapter*{Title}

which becomes

\@ifstar{\@schapter}{\@dblarg{\@chapter}}*{Title}

Since * follows, this becomes

\@schapter{Title}

Now what's \@schapter? Here it is

% book.cls, line 400:
\def\@schapter#1{\if@twocolumn
                   \@topnewpage[\@makeschapterhead{#1}]%
                 \else
                   \@makeschapterhead{#1}%
                   \@afterheading
                 \fi}

so this makes pretty clear that the bulk of the work is done by \@makeschapterhead.

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.