2

I have a lot of short chapters so I would like the Chapter to go at the top of a page and text to immediately follow it. In other words, not so much blank space. Second, I would like to define a lab macro that just put the word Lab in front of the chapter name.

For example:

\lab {Blink}

should turn into:

\Chapter{Lab: Blink}

I therefore wrote a command:

\newcommand{\lab}[1]{\chapter{Lab: {#1}}}

I am just trying to understand if this should work. It is not working, which could be due to something subtle. I had a previously defined lab command and tried to comment it out. If the above command is in fact correct, then I will start another question with a MWE for that purpose.

  • It will work, but it will add Lab: in the ToC as well. Isn't changing \chaptername the better way? – user31729 May 11 '16 at 15:36
1

Your macro is probably breaking because \chapter is a "fragile" command. Add \protected and it should work (notice I had to change \newcommand to a plain \def):

\protected\def\lab#1{\chapter{Lab: {#1}}}

For spacing, I would suggest using the titlesec package. The following removes all vertical space before a chapter heading:

\titleformat{\chapter}[display]
            {\sffamily\bfseries}% formatting applied to all chapters
            {\chaptertitlename\ \thechapter} % Used for numbered chapters only 
            {\baselineskip} % Vertical space between ``Chapter N'' and name of chapter
            {}
\titlespacing*{\chapter}{0pt}{0pt}{\baselineskip}

Note that the display option puts vertical space between the chapter label ('Chapter 1') and the title ('Foo'). Remove it and change \baselineskip to 1em (or another horizontal dimension) if you want them on the same line.

MWE:

\documentclass{book}
\usepackage{titlesec}

\protected\def\lab#1{\chapter{Lab: {#1}}}

\titleformat{\chapter}[display]
            {\sffamily\bfseries}% format
            {\chaptertitlename\ \thechapter} % Sans-serif, bold 
            {\baselineskip} % Vertical space between ``Chapter N'' and name of chapter
            {}
\titlespacing*{\chapter}{0pt}{0pt}{\baselineskip}

\begin{document}

\tableofcontents

\chapter{Foo}

XXX.

\lab{FooBar}

ZZZ.

\chapter{Baz}

QQQ.

\end{document}

which gives (with Lab):

Lab chapter

and without:

Chapter w/o Lab

Note I didn't change the margins at all, so it looks like there is still a lot of vertical space above the chapter. Using the fullpage or geometry packages would recover that space too.

2

Lacking a really working scenario, I suggest to change the \chaptername rather:

\documentclass{book}

\renewcommand{\chaptername}{Lab:~}
\begin{document}

\tableofcontents

\chapter{Foo}
\chapter{FooBar}

\end{document}

enter image description here

  • Other options: Change \@makechapterhead, but I suggest this only if there's more to be done than just changing the title – user31729 May 11 '16 at 15:40

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.