Archive for May, 2007
Styling the table of contents
Saturday, May 26th, 2007 | LaTeX | No Comments
Styling the table of contents isn’t quite as trivial as the chapter page, as there are several more things to consider. Before we embark on this, however, let us take a look at how the table of contents are usually set up in a typical LaTeX book.
While this seems to be a fairly tradition-bound way to set up the table of contents, it may feel rather out of pace with the rest of the styling of the document. Or it may just be that you feel more avant-garde than the default LaTeX styles lead people to believe. Either way, restyling the table of contents is just as fascinating as the chapter page!
Something that’s important to keep in mind is that the table of contents, list of figures and other front matter lists are not typeset using the chapter styles we saw in the last post, but using their own setup. The TOC (for instance) is set up as follows in memoir:
\tocheadstart
\printtoctitle{\contentsname}
\tocmark
\thispagestyle{chapter}
\aftertoctitle
And thus, to restyle these front matter lists, you have to also override these commands. For the other lists, replace toc with the appropriate list.
This is, however, not the primary focus of this post, so let’s get on with the show. If we look above at the standard layout of the table of contents we see a couple of recurring items: a page number, a chapter/part/section number, a chapter/part/section title, and a separation between each of these items, which may or may not contain a series of dots. Now, in my personal opinion, the dots are absolutely terrible and ruin the overall aesthetic flow of the page, but that might just be me.
The control over the entries is extremely fine-grained and you can thus define stylings for the following things: part, chapter, section, subsection, subsubsection, paragraph, subparagraph, figure, subfigure, table, and subtable.
To start out we will try something fairly straightforward. We will remove page numbers from the \part entries and typeset them in colour, and we will also move the page numbers for the remaining entries closer to the actual text. This is a bit more involved than just changing the chapter style:
\usepackage{xcolor}
\renewcommand{\cftdotsep}{\cftnodots}
\cftpagenumbersoff{part}
\renewcommand{\cftpartpresnum}{\sffamily\large\bfseries\color{blue}\partname\ }
\renewcommand{\cftpartaftersnumb}{\\}
\cftsetindents{part}{0em}{0em}
\renewcommand{\cftchapterleader}{\hskip1cm}
\renewcommand{\cftchapterafterpnum}{\cftparfillskip}
\renewcommand{\cftsectionleader}{\hskip1cm}
\renewcommand{\cftsectionafterpnum}{\cftparfillskip}
This requires a bit of explanation. The \cftdotsep sets the separator spacing, and \cftnodots is a ‘big enough’ value that we will never see any dots. \cftpartpresnum specifies what goes before the part section number (I, II, etc.). Here we make the font sans-serif, blue and we print \partname (which in English amounts to ‘Part’) and a space after it. \cftpartaftersnumb specifies what happens after the section number block (that’s what the last b is for), and here we print a newline so the part title is displayed below the part name and number. There is also a \cftpartaftersnum where you can, for instance, place a colon so you’ll get something like ‘Part I:’. Lastly we set the indentation for the part lines to 0em leading space to the section number, and 0em subsequential space to the beginning of the title (since we’re printing the title on the following line). The \cftchapterleader contains the code for what happens after the section title and the page number (the default is for it to print the dots or blank space to right-align the page number). We make this empty. If this is all we do we’ll get the title spaced out over the line (like in a bad case of justified paragraphs in Microsoft Word), so we will have to specify that after the page number is printed we want to fill the rest of the line with blank space, we do this using \cftchapterafterpnum and the \cftparfillskip command.
Whew, that was a lot of text. What all this gives us is a table of contents page that looks like this:
While the balance of the page seems a bit more skewed, I actually find this kind of table of contents easier to use as you don’t have to trace across the page to find the right page number, and the dots across the page look even more ugly than this.
As a last practice, let us try another way to setup tables of contents, namely without part, chapter and section numbers. The section number is printed inside a \numberline command for all list types, except for part and chapter, which have their own \partnumberline and \chapternumberline. Thus to create a table of contents that doesn’t contain any of these numbers, we need to override all these commands. Furthermore we’ll keep the page numbers close to the titles like in the previous example, and no page number for the part. This amounts to the following:
\renewcommand{\cftdotsep}{\cftnodots}
\cftpagenumbersoff{part}
\renewcommand{\partnumberline}[1]{}
\renewcommand{\chapternumberline}[1]{}
\renewcommand{\cftchapterleader}{\hskip1cm}
\renewcommand{\cftchapterafterpnum}{\cftparfillskip}
\renewcommand{\numberline}[1]{}
\renewcommand{\cftsectionleader}{\hskip1cm}
\renewcommand{\cftsectionafterpnum}{\cftparfillskip}
This gives us the following output:
Depending on your need the section number-less style can be preferable while retaining part, chapter and section numbers inside the actual document. If none of these are needed you can use the \setsecnumdepth macro instead and just turn off the numbers everywhere. That’s a lot more easy.
As a rule of thumb, it is important to remember to keep fonts consistent between section numbers, section titles and page numbers. Mixing and matching makes for a very jumbled expression and is (for the most part) not what you’re interested in.
Again, for more technical details, consult the memoir manual or class file.
Styling the chapter
Monday, May 21st, 2007 | LaTeX | 4 Comments
When we write larger works, one of the places we have the most stylistic freedom is with chapter pages. The chapter page is meant to break off the flow of pages and present something new. Looking through books on the book-case we see a wide-ranging difference in chapter styles. While the standard chapter style (as seen below) is pretty decent, there’s a long way to the chapter styles of books like Unicode Standard 5.0, A History of Mathematics, or Fundamentals of Human Neuropsychology.
There are plenty of different styles we can think up to create on our own, or by mimicking others’ designs (do note that exactly reproducing someone else’s design is probably a copyright infringement in plenty of places. Yay for copyright law). So instead of showing you just one style, I will try to explain the fundamentals of chapter styling by looking at the commands used, and then giving several examples ranging from the simple to the quite complex.
Before we continue, it would probably be prudent for me to point out that LaTeX contains two kinds of chapters: numbered (the normal chapters) and unnumbered (the table of contents, the bibliography, the index, and chapters placed in the front matter). The main difference is, of course, that numbered chapters contain the text ‘Chapter 1’ (for chapter one, obviously), and unnumbered chapters do not. At least in the default setup.
In memoir, the default numbered chapter is defined as written below (from page 86 of the manual):
\chapterheadstart
\printchaptername \chapternamenum \printchapternum
\afterchapternum
\printchaptertitle{Title goes here}
\afterchaptertitle
In their default definitions the print methods also make use of the following commands that define font settings: \chapenamefont, \chapnumfont, and \chaptitlefont. This information is almost all we need in order to create our own fantastic chapter styles. The last thing before we embard on experimenting with styles is to know how to create and use different chapter styles. This is accomplished using the \makechapterstyle{stylename}{commands} command, where commands is a series of redefinitions of the above-mentioned commands, and in order to use this style, we can use the command \chapterstyle{stylename}.
As a very easy beginning, let’s add some colour to the chapter style, by creating a ‘colour’ chapter style:
\usepackage{xcolor}
\makechapterstyle{colour}{
\renewcommand*{\chapnamefont}{\normalfont\huge\bfseries\color{blue}}
\renewcommand*{\chaptitlefont}{\normalfont\Huge\bfseries\color{blue}}
}
\chapterstyle{colour}
This style only redefines the fonts and leaves the rest of the chapter style intact as default. If we only had numbered chapters then redefining the \chapnamefont would be adequate, as the colour seeps through to the other commands, but since \chapnamefont is never called for unnumbered chapters, we also need to provide the colour for the \chaptitlefont command. For those not deeply into the LaTeX command architecture, then the star after \newcommand and \renewcommand means that the content of the command cannot contain a paragraph change, so for simple inline commands, tag the star on for verification purposes. Adding our new chapter style to our document we get the following page:
This, actually, did little to make the chapter style prettier, if I have to be a bit self-critical for a moment. Let us instead try to be a tad more artistic with our usual black and white palette. Using the tikz package that I have written about before, we can draw a black box with the chapter number inside and then have the title below, and this time let us make it right-aligned.
\usepackage{tikz}
\makechapterstyle{box}{
\renewcommand*{\printchaptername}{}
\renewcommand*{\chapnumfont}{\normalfont\sffamily\huge\bfseries}
\renewcommand*{\printchapternum}{
\flushright
\begin{tikzpicture}
\draw[fill,color=black] (0,0) rectangle (2cm,2cm);
\draw[color=white] (1cm,1cm) node { \chapnumfont\thechapter };
\end{tikzpicture}
}
\renewcommand*{\chaptitlefont}{\normalfont\sffamily\Huge\bfseries}
\renewcommand*{\printchaptertitle}[1]{\flushright\chaptitlefont##1}
}
This probably requires a bit more explanation. We disable printing ‘Chapter’ for the chapter style by overriding the \printchaptername command with an empty body. Then we change the font for the chapter number to be sans-serif (\sffamily), and the same for the chapter title. Also we ensure that the chapter title is flushed right, that is it aligns to the right margin. Lastly we have the tikzpicture in the \printchapternum. Inside that we draw a black triangle that’s a 2cm square, and after that we print the chapter number in the middle of it. Fairly straightforward, eh? Using this chapter style in your document yields the following output:
This is, indeed, a lot better, but there are plenty of other options for chapter styles to try out. We can combine some of the concepts in the last few chapter styles we’ve tried:
\usepackage{xcolor,calc}
\makechapterstyle{combined}{
\setlength{\midchapskip}{-60pt}
\setlength{\afterchapskip}{2.5cm}
\renewcommand*{\printchaptername}{}
\renewcommand*{\chapnumfont}{\normalfont\sffamily\bfseries\fontsize{80}{0}\selectfont}
\renewcommand*{\printchapternum}{\flushright\chapnumfont\textcolor[rgb]{.64,.79,.87}{\thechapter}}
\renewcommand*{\chaptitlefont}{\normalfont\sffamily\Huge\bfseries}
\renewcommand*{\printchaptertitle}[1]{%
\raggedright\chaptitlefont\parbox[t]{\textwidth-3cm}{\raggedright##1}}
}
\chapterstyle{combined}
First we set up some distances. The -60pt fits approximately on eye measurement the amount that you need to back up for the chapter number and title to align at the top. Normally it would be better to redefine more of the chapter style to create explicit boxes for the two things that could be top-aligned, but that’s a lot more work and would actually obscure how to use the chapter styles easily, so eye measurement it is. We make the chapter number really big (80 pt to be exact), and we print it in the RGB value (0.64, 0.79, 0.87) where colours are in [0;1] for those of mathematical inclination. Lastly we print the chapter title inside a paragraph box that is 3 cm smaller than the text width in order not to have the chapter title written on top of the chapter number as that doesn’t look particularly smashing. Adding this to our document gives us the following output:
We have now seen several different kinds of chapter styles that can be (more or less) easily customised using memoir’s functionality. Creating your own chapter style is thus just a matter of overriding a couple of methods and inserting some code. Doing this gives a tremendous difference between a cookie-cutter template of a document and a customised, personal document of high quality. For those of you who need even more examples of different chapter styles, you can refer to the Memoir Chapter Style Samples document by Lars Madsen from Århus universitets institut for matematiske fag. But the most important aspect is, of course: experiment.
In closing, these are the relevant items to override in the standard setup. You may change commands so some of them become irrelevant or not used.
- Lengths:
\beforechapskip,\midchapskip, and\afterchapskip - Fonts:
\chapnamefont,\chapnumfont, and\chaptitlefont - Printing text:
\printchaptername,\printchapternum, and\printchaptertitle - More technical surrounding blocks:
\chapterheadstart,\afterchapternum,\printchapternonum, and\afterchaptertitle
For more technical details, consult the memoir manual or class file.
Styling the document
Monday, May 21st, 2007 | LaTeX | No Comments
Over the next few blog posts we will be looking at how we can restyle an entire document without changing its contents. This is one of the key strengths of LaTeX: separating content from style. There are, of course, several aspects of a document that can be interesting to restyle, but we will focus on some of the primary elements: the table of contents, chapter headings, part, section, subsection, etc. headings, and finally the page headers and footers. As usual, we will do this by investigating the memoir document class.
Post 0: This post
Post 1: Styling the chapter
Post 2: Styling the table of contents
Post 3: Styling the other document divisors
Post 4: Styling the page footer and header
Bibliographic software
Friday, May 18th, 2007 | Academe | No Comments
A big, and important, part of academic works is to describe the foundation of your work. That is, you need to cite previous works, create bibliographies and all sorts of things that has a tendency to be a bit annoying for most people. Now, a large portion of people have a tendency to use Microsoft Word or OpenOffice to write texts in (be it assignments, theses, or dissertations), and a frightening portion of people I know using these tools manage their bibliographies in hand without using any tools to ease their work.
For a while there have been some commercial tools in this area, such as RefWorks, and EndNote, which seem to be the two most popular choices. These tools allow you to manage your bibliography in a big database, and more importantly, it integrates with Word so you can pull in a reference from your database and it will format it in accordance with some citation style (APA, MLA, etc.) so you don’t have to sit and double-check whether you’ve remembered all the details of your selected/dictated style. Furthermore, these tools allow you to easily grab material from online publication databases such as PubMed, CiteSeer, and many others, so you don’t have to manually write up all the information about each bibliographic item.
While commercial tools are all fine and well, we have actually had this functionality in LaTeX for a long while using BiBTeX. The catch here is, of course, that you need to maintain your BiBTeX database yourself. So, wouldn’t it be nice if we could get both things? An application that can easily fetch bibliography information from the web, something that can integrate with Word for those who need that, something that can export to BiBTeX so it can be readily used with LaTeX, and even something that can help you keep track of where you put all the articles you need for your thesis? And would it hurt if this thing was actually open source? I think not!
Yesterday my fiancée was complaining about managing bibliographies in Word (I have, unfortunately, been unable to persuade her to change to LaTeX exclusively), and as the kind person I am, I immediately put the followship of the ring, extended edition, on pause and went to look for something that’d help her maintain a database of bibliographies. Something which, preferably, is a tad easier and faster to use than BiBTeX. Now, I’m aware of things like pybliographer that gives BiBTeX a more userfriendly exterior, but I was aiming for something a little more userfriendly and more like RefWords and EndNote with integration to Word.
And lo and behold, after a short while of searching, I came upon one of the most nifty extensions to Firefox that I have seen to date: Zotero. This extension integrates your bibliographic database management directly into the application most of us use to find literature with: the browser. As an added bonus it also offers integration with Word, it works across platforms, it’s open source. Basically it fulfills all the needs I listed above to perfection. Count me amazed. I will definitely be using this for myself as well and just export to BiBTeX when I need to cite works from my LaTeX documents.
For the more technically minded of us who have a tendency to prefer our own variations on bibliographies and citations (when we aren’t otherwise bound by journals or other draconian requirements) and thus create our own .bst-styles for BiBTeX, then Zotero uses the Citation Style Language, which is an XML-based format for formatting citations and bibliographies. Lastly, Zotero has been funded and developed by the Center for History and New Media, so this is a tool by the academe for the academe with a commercial tool’s polish. Give it a try today.
Categories
Archives
- 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