An example book style
Wednesday, June 20th, 2007 | LaTeX
Now that we have made our way through how to style a document, it is time to look at how we can actually use some of this knowledge in practice, by typesetting an actual book. Since all that Lorem Ipsum can get a tad boring in the long run, we will create a book with some works that have passed into the public domain, namely some by H. P. Lovecraft, a significant American horror author of the early 20th century. None other than the man behind Cthulhu.
Much like with the last four blog posts, we will take a look at styling the book in the same order, namely: chapter, table of contents, sections, and footers/headers. Remembering the plain chapter style, we have something like this, for our book:
As I’ve written before: while this is certainly acceptable, it’s not really too unique of fascinating, so let us think up a way to get it to feel more 1920′s and horror-ish. The last part is of course hard to quantify unless you pick some cheesy font that’s impossible to read, so let’s just stick to making it look a bit like a book on good literature. We will try to accomplish this by just writing the chapter number as a word (one, two, three, etc.), and omit the ‘Chapter’ prefix, centered, and put the chapter title in italics, also centered. We can do that with the following code:
\makechapterstyle{bookstyle}{ % Yes it's a very imaginative name \setlength{\beforechapskip}{0em} \setlength{\midchapskip}{1em} \renewcommand{\chapnumfont}{\normalfont\large\bfseries\fscshape} \renewcommand{\chaptitlefont}{\normalfont\huge\bfseries\itshape} \renewcommand{\printchaptername}{} \renewcommand{\printchapternum}{% \centering\chapnumfont\numtoname{\thechapter} } \renewcommand{\printchaptertitle}[1]{\centering\chaptitlefont ##1} } \chapterstyle{bookstyle}
This verily will take a bit further description. The \fscshape command introduces fake small-caps, and its existence depends on what font package you may or may not be using. If you have a commercial grade font, or one of the built-in fonts, then you will want to use \scshape instead. The \fscshape I am using here is provided by the mathdesign package together with the URW Garamond typeface. The only other surprise here should be the \numtoname command that is provided by memoir, and this command converts a number into a corresponding name, for instance \numtoname{13} will be turned into ‘thirteen’.
With this modest change in place, our chapter page suddenly looks like this:
This seems a tad more classic literature-ish to me, at least. So we will chalk one up for success on the chapter style. We could, of course, add something to the fancy and automatically insert an image for each chapter to complement the story, but since my freehand drawing skills aren’t what I’d like them to be, we shall skip this step for now.
With this out of the world, let us take a look at the existing table of contents:

From this we see that our book is divided in two parts: one for some of Lovecraft’s essays, and another for a very few of his poems. Since most of his essays aren’t subdivided, we probably have no need to indicate any of these, so let us turn them off and simplify the table of contents a bit. This may be done using:
\settocdepth{chapter}
Now, as long as you only want to tweak the distance between table of content entries, perhaps remove the dots on the line to the page numbers and move the page numbers a bit back and forth on the page, then everything is easy to do with memoir, but as soon as you move beyond that, things start to get really complicated, unfortunately. Not one to shy away from hard things, let us look at what it takes to center the part and draw lines around it and to typeset all the chapters in italics.
The first part is, unfortunately, rather hard. It requires us to override two different commands: \l@part and \partnumberline. The reason for this is two-fold. When we issue a \part command, the following is written to the .aux-file: \@writefile{toc}{\contentsline{part}{\partnumberline {I}Essays}{1}}, for instance, for part 1 called Essays. When this is going to be typeset then \l@part is called with the last two {}‘s above as arguments.
Using the tikz package that we have covered earlier to draw the lines about the part title, we will give the entire definition of the two commands here and then proceed with an explanation of the key points. The overall structure has been ‘borrowed’ from memoir.cls:
\newlength\sb@partheight \renewcommand*{\l@part}[2]{% \ifnum \c@tocdepth > -2\relax \addpenalty{-\@highpenalty}% \addvspace{\cftbeforepartskip}% \begingroup{ \centering \settoheight{\sb@partheight}{\Large\bfseries\MakeUppercase{#1}} \setlength{\sb@partheight}{.5\sb@partheight} \addtolength{\sb@partheight}{5pt} \begin{tikzpicture} \draw (0,0) node { \Large\bfseries\MakeUppercase{#1} }; \draw (-.25\textwidth,\sb@partheight) -- (.25\textwidth,\sb@partheight); \draw (-.25\textwidth,-\sb@partheight) -- (.25\textwidth,-\sb@partheight); \end{tikzpicture} \par }\endgroup \fi } \renewcommand{\partnumberline}[1]{}
So, I guess this requires some explanation. The test on \c@tocdepth tests for whether the part should actually be displayed in the table of contents, and -2 is the code for the part in this instance. The \addpenalty command here makes TeX prefer to create a page break \emph{before} the part rather than after, so we don’t have a part title dangling alone at the bottom of a page, since that doesn’t look particularly nice. Then we use \begingroup to localise our changes so they don’t seep into the remaining document, and inside this group, we do a bit of slight trickery to compute how heigh the part title is, using the \settoheight. Then we calculate the half height and add some space, and this we use as a measurement in the following tikzpicture. The tikzpicture code should be familiar, as we have already seen it here. The redefinition of \partnumberline merely discards the part number as we aren’t really interested in that.
Our changes to the actual chapters are a lot easier to accomplish. Indeed, it only requires the following two lines:
\setlength{\cftbeforechapterskip}{.2em} \renewcommand{\cftchapterfont}{\normalfont\small\itshape}
Taking all this together and using it with our book, we get the following table of contents for it:


This looks a good deal more like some of the older fictional works. So far so good. The next thing to turn pretty is the section titles. For the most part Lovecraft’s essays don’t have actual sections, but a few of them have sections named I, II, III, etc., and even fewer have actual section titles. One of the essays that do, is ‘Herbert West: Reanimator’.
First off, the numbering of the section doesn’t really make any sense in a fictional work as the title is usually sufficient in and of itself, so let’s do away with that. Apart from that, the standard section title layout looks quite decent. This is an extremely easy change then:
\maxsecnumdepth{chapter} \setsecnumdepth{chapter}
And we get the following:
This leaves us with just the page headers and footers. As we can see below, and as I have written previously, the standard page headers are just ugly.
So, to rectify this, we will place the part title on the left page and the chapter title on the right page, both centered in the header, and we’ll place the page number on the page edge in the footer. And this is easily accomplished with the following code:
\makepagestyle{mybookstyle} \makeoddhead{mybookstyle}{}{\itshape\rightmark}{} \makeevenhead{mybookstyle}{}{\itshape\leftmark}{} \makeoddfoot{mybookstyle}{}{}{\thepage} \makeevenfoot{mybookstyle}{\thepage}{}{} \makepsmarks{mybookstyle}{% \def\partmark##1{\markboth{##1}{}} \def\chaptermark##1{\markright{##1}} \def\sectionmark##1{} } \pagestyle{mybookstyle}
And presto, we get a much nicer output:
Throughout all these examples, we have used the @-sign repeatedly in commands. This is ok if you’re implementing this in a package file, but if you’re pasting them into your document’s preamble, the @ will not be interpreted as a character and a lot of errors will follow. To rectify this, surround the code in the preamble with the commands \makeatletter and \makeatother. This will make everything right. In a future post, I will try to talk about implementing packages to better hide this functionality away in a reusable component.
This concludes the styling example for today. If you’re in a need for a lot of sensible material to try out different stylings on, then I suggest that you head over to WikiSource or Project Gutenberg and grab some works that have entered the public domain and try to make your own compilation of them. And for your viewing pleasure, here is the book typeset with the style above.
2 Comments to An example book style
There is a minor problem in your first example:
\makechapterstyle{bookstyle}{ …. }
\pagestyle{bookstyle}
The \pagestyle should be \chapterstyle. Thanks for the guide on how to style chapters, headers and avoid the LaTeX look!
Thanks for noticing. I have rectified the post with the proper command.
Leave a comment
Categories
Archives
- February 2012
- July 2011
- June 2011
- November 2010
- October 2010
- April 2010
- November 2009
- October 2009
- June 2009
- May 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- December 2006
- November 2006
- October 2006
- September 2006
- June 2006
- April 2006
- March 2006
- February 2006
- January 2006
- December 2005
- November 2005
- October 2005
- September 2005
- May 2005
- April 2005
- March 2005
- February 2005
- January 2005
- December 2004
- June 2004
- April 2004
- February 2004
- November 2003
- January 2003
- November 2002
April 19, 2008