Archive for March, 2007

LaTeX two column layouts and rubber lengths

Tuesday, March 20th, 2007

Today I gave my advisor the draft of the final chapter of my dissertation, which I have been working on fervently for the last week or so. I decided that I deserved a little break before getting back to the grindstone of implementing comments from my advisor. I decided to spend some time working on the two column layout of my dissertation.

Two columns! You may be thinking that I am crazy. Certainly my institution wouldn’t allow me to use a two column layout for my dissertation! That is indeed correct. The requirements set by the University of Michigan produce a pretty ugly document — one-sided, double-spaced (or 1.5), and running headers aren’t allowed. They actually don’t specify if you can use two columns or not, but I didn’t even bother asking, because I am pretty certain the answer is no. Now, just because the official copy that I hand in has to look boring doesn’t mean that I can’t make a nice copy for myself, and for other people I give a copy, like the members of my committee. And with LaTeX, that is relatively easy to do.

original format two column format
one column layout one column layout

Many scholarly journals, especially scientific journals use a two column layout. There are good reasons for this. When reading text, one of the most difficult tasks is to move down a line. Most languages of the world (but not all) are read either right to left or left to right, which means that moving down a line means moving your eyes all the way across the width of the text. As the width of a text gets wider, so does this task. For this reason, many books use relatively small paper. A common novel usually has paper sized about 6in x 8in. This is fine for books which are professionally printed, but the printing of a dissertation is usually restricted to standard 8.5 x 11 inch paper. Having a one column format (with reasonable margins of 0.5 to 1 inch) on 8.5 x 11 inch paper is very hard to read. A two column layout is much easier for readers.

For the most part, making a two column layout in LaTeX is extremely easy. Simply specify twocolumn in the document class definition:

\documentclass[letterpaper, twosided, twocolumn]{book}

However, one quickly notices that some things need adjusting. First off, equations, figures, and tables which are too wide to fit in one column need to be specified as double column width. For figures and tables, simply use table* and figure* environments. Equations can be a bit trickier, but luckily I didn’t have any really long equations. In addition, using table* in a one-column document doesn’t have any effect, which makes it very easy to switch back and forth between one and two column layouts. (Note that LaTeX only allows two-column floats at the top of the page by default, though some different class files, such as JASAtex, get around this somehow).

Some of the main jobs of LaTeX are:

  1. format text into fully justified paragraphs, hyphenating when necessary
  2. Break pages at appropriate places (i.e. don’t start a new section at the bottom of a page, or leave one line stranded on an otherwise blank page
  3. place tables and figures in appropriate positions

In a two column layout, all of these jobs get a little trickier. LaTeX uses several parameters which controls the behavior of the processes that handle these jobs. LaTeX realizes that hyphenating words at line breaks should be avoided if possible, but sometimes it is necessary in order to have justified text which has approximately equal inter-word spacing. In a two column layout, each column usually has fewer characters than in a one column layout, which means that more words will be hyphenated. If you don’t like this, you can increase the \hypenpenalty, which will cause LaTeX to hyphenate fewer words, and instead be a little sloppier about inter-word spacing

% don't hyphenate so much - default = 200, max (never hyphenate) = 10,000
\hyphenpenalty=800

You may also wish to alter float placement a bit. By default, LaTeX puts figures and tables on their own page if they take up more than 70% of a page, and says that float pages should be at least 70% full of floats. I would prefer to squeeze a bit more onto a page, so I increase these values a bit:

%two column float page must be 90% full
\renewcommand\dblfloatpagefraction{.90}
%two column top float can cover up to 80% of page
\renewcommand\dbltopfraction{.80}
%float page must be 90% full
\renewcommand\floatpagefraction{.90}
%top float can cover up to 80% of page
\renewcommand\topfraction{.80}
%bottom float can cover up to 80% of page
\renewcommand\bottomfraction{.80}
%at least 10% of a normal page must contain text
\renewcommand\textfraction{.1}

There are a few more parameters which you can tweak to save a little space. Now that we have big floats on a page, we might need to make a little more room for text, so we can decrease the textfloatsep from the default value of 20pt

%separation between floats and text
\setlength\dbltextfloatsep{9pt plus 5pt minus 3pt }
%separation between two column floats and text
\setlength\textfloatsep{10pt plus 4pt minus 3pt}

Now those rubber lengths. Notice that the above lengths include plus and minus. What this says is that the dbltextfloatsep should be 9pt, but can be anywhere between 6pt and 14pt. Rubber lengths allow LaTeX to adjust spacing (in this case vertical spacing), to make better page breaks. Looking at the code from the standard book.cls, we will also find rubber lengths in the definition of sectioning commands, e.g.:

\newcommand\section{\@startsection {section}{1}{\z@}%
                                   {-3.5ex \@plus -1ex \@minus -.2ex}%
                                   {2.3ex \@plus.2ex}%
                                   {\normalfont\Large\bfseries}}

While I still have yet to find exactly what all this means, I am pretty sure that the two middle lines specify how much space should come before and after the section heading. This says that there should be between -4.5ex and -3.3ex before the heading, and 2.3ex to 2.5ex after the heading, before the beginning of the section text. It also says that the font of the heading should be Large and bold. While this looks quite nice by default, I found the spacing too large for a two column layout, so I redefined some of these commands:

\renewcommand\section{\@startsection {section}{1}{\z@}%
       {-1.5ex \@plus -.5ex \@minus -.8ex}%
       {1.5ex \@plus.2ex \@minus .2ex}%
       {\raggedright\normalfont\large\bfseries\sffamily}}
    \renewcommand\subsection{\@startsection{subsection}{2}{\z@}%
       {-1ex\@plus -.4ex \@minus -.4ex}%
       {1ex \@plus .2ex \@minus .2ex}%
       {\raggedright\normalfont\bfseries\sffamily}}
    \renewcommand\subsubsection{\@startsection{subsubsection}{3}{\z@}%
      {2ex \@plus1ex \@minus.3ex}%
      {-1em}%
      {\normalfont\normalsize\bfseries\sffamily}}

Notice that for subsubsection, the lengths seem to be reversed, in that the first length is positive, and the second is negative. This has the effect that the heading is placed on the same line as the text, instead of on a separate line. Paragraphs and subparagraphs are formatted like this, but I wanted it for subsubsection, which is the lowest level of sectioning I use in my dissertation.

I made one additional modification to all these parameters. The default space between columns seems to be about .1in, which is not very much. I increased this to .25in.

\setlength{\columnsep}{.25in}

With just a little tweaking, I turned the default formatting into a very professional looking document.

Addendum — equations

Several people have asked about how to handle long equations. There is no great way, and it will depend on your equation. If you absolutely need the whole page, you have to put the equation in a figure* or table* environment, which means that it can only appear at the top of a page. Other options are to split the equation up into multiple lines, make the font a bit smaller, or go into the margins a bit. I used all of these techniques for one equation in my dissertation. Here is the code:

\hspace*{-.4em}%
  \begin{minipage}{1.02\columnwidth}
  {\fontsize{8.7}{10}\selectfont
  \begin{multline}%
  \label{E:NPR}
  p(ID)=\\
  \frac{\displaystyle\prod_{i=1}^{n} p(PS_i|PS_i)\cdot Freq_S}
  {\left\{\left[\displaystyle\prod_{i=1}^{n} p(PS_i|PS_i)\right]\cdot
  Freq_S\right\} +
      \displaystyle\sum_{j=1}^{nn} \left\{\left[\displaystyle\prod_{i=1}^{n}
      p(PN_{ij}|PS_i)\right]\cdot  Freq_{Nj}\right\}
      }
  \end{multline}%
  }
  \end{minipage}

And the resulting output.

screenshot of a long equation
screenshot of a long equation that uses the margins a bit, has smaller font, and uses multiple lines

It is not perfect, but I am pretty happy with the results.

  • FriendFeed
  • Reddit
  • del.icio.us
  • Digg
  • Slashdot
  • Technorati
  • Facebook
  • Fark
  • TwitThis
  • LinkedIn

sourdough wheat with spelt berries

Tuesday, March 13th, 2007

I have been baking bread for over 6 years now. I started in 2001, my last semester at Grinnell College, with the hopes of producing some bread like I fell in love with in Germany. I started off with fairly simple recipes from a Fleischmann’s baking book my mom gave me. That book got me going pretty well. There were some very obvious failures, but I enjoyed the pursuit, and usually, the results.

sourdough wheat with spelt berries 1
In 2003, I started experimenting with sourdough bread. Sourdough bread is the traditional way of making bread, and is how all leavened bread was made prior to the 19th century, when yeast was discovered. Before the discovery of yeast, bread-making (and beer brewing) were seen as a bit magical. No one really knew why bread rose, or why beer stayed good so long, and made you feel drunk. Nowadays both of these processes are usually done with commercial yeast, which speeds up the process quite a bit. There are some definite advantages to sourdough bread though:

  1. Stays fresh longer than normal bread (without preservatives)
  2. Has a chewier texture, and a tangy flavor
  3. Some people think it is healthier, though I am not so sure
  4. You don’t have to buy yeast!

sourdough wheat with spelt berries 2
My first few attempts at sourdough were not that great either, and at some point I gave up. But after a break, I started up again in 2004, and I have had quite a bit of success since then. In the summer of 2004 I actually began using two different starters. I created my own wheat starter, which only takes about a week, and I also got some rye starter from a professor in the German department. One of the mistakes I had made in 2003 was keeping the starter in the freezer. The freezer is too cold for yeast, and basically kills the yeast. If you are going to wait more than a couple days between using your starter, keep in the fridge. It keeps for several months. It might start looking a little funky on top, but you can always just get rid of that part. While I was in Germany last year for 5 weeks, my roommate actually thought my rye starter had gone bad, and threw it out. I was quite angry about that, but I ended up just taking the wheat starter, and refreshing it with rye flour, and that worked fine. So now I am back to two nice starters.

Anyways, on to the latest foray. Clare recently made some swiss chard and spelt soup, which resulted in lots of leftover spelt, so I thought I would put it in some bread. Clare really likes bread with wheat berries and big nuts and seeds in it, so I thought she would really enjoy it. Here is what I used (in order of mixing):

  • 2 cups of wheat starter, refreshed twice
    • 1st refreshment — add 2 cups warm water and 2 cups whole wheat flour; wait 6 hours
    • 2nd refreshment — add 1 cup warm water and 2 cups whole wheat flour wait 10 hours
  • 1 1/2 cups warm water
  • 1 cup rye flour
  • 1 cup soy flour
  • 1/4 cup vital wheat gluten
  • 1/8 cup xantham gum
  • 1/3 cup flaxseed meal
  • 4 cups cooked spelt berries
  • 3 cups whole wheat flour
  • 1 Tbsp salt
  • 3 cups all purpose (white) flour
  • 3 cups white flour

sourdough wheat with spelt berries 3

I mixed the dough up around 10 a.m. It took a lot of kneading, as the spelt berries added a lot of water, and the dough did not want to really get very firm. After a good 10-15 minutes of kneading, I called it good. Then I let it rise. And rise. It was rising very slowly for some reason. It could be that the starter was not very active. Sourdough is as much of an art as a science. According to Joe Ortiz, in The Village Baker, one should think of making sourdough bread not as forcing the bread to rise, but guiding it. Kind of interesting. Through experience, one learns when the dough is ready to be baked, and so on. I punched down the dough around 6 p.m., shaped it into 3 loaves - one small, one medium, and one large. I always try to make the loaves equal-sized, but I usually end up with three different sizes. Oh well. Variety is the spice of life. I put the loaves in the oven around 10 p.m. I usually put them in at 425ºF and then turn it down to 400ºF, and bake them for an hour. The bread was well worth the wait. Clare and I have been enjoying it for over a week now. Usually the sourdough bread will stay good for about 2 weeks, depending on the heat and humidity.

  • FriendFeed
  • Reddit
  • del.icio.us
  • Digg
  • Slashdot
  • Technorati
  • Facebook
  • Fark
  • TwitThis
  • LinkedIn

More on LaTeX multimedia presentations

Saturday, March 10th, 2007

Yesterday I gave a talk in the Linguistics department colloquium series. I like to cover all my bases, so I had a handout and a slide presentation, which were both made from the same LaTeX code. In an earlier post, I briefly discussed using the prosper package for LaTeX to make presentations. A few months ago, I discovered the powerdot package, which is kind of the niece of prosper (cousin of ha-prosper). The syntax and framework is very similar to prosper, but it has a few advantages. Some of the advantage include better overlay and verbatim support, which is definitely nice. I think the biggest advantage though is the possibility to include a running table of contents on your slides. You can see this in the screenshots below.

powerdot screenshot 1
In the first screenshot, you can also see some nicely typeset equations with LaTeX. This is an obviously nice feature of using LaTeX to do presentations. If you are already using LaTeX for other writing, you can do a lot of copying and pasting, which certainly is not possible with powerpoint (for equations at least). And, if you like dark backgrounds with light text, this works fine for your equations. Powerpoint seems to only be handle black on white equations.

powerdot screenshot 2
Back to the running table of contents. This is probably not great for everyone, but at least one person who was at my talk said he liked it. And I agree. It lets you know where you are at in the talk the whole time, and is fairly unobtrusive. If for some reason you need more space on the slide, you can simply use the wideslide environment, which gets rid of the table of contents bar. Before I gave my talk yesterday, I saw another talk, which was quite interesting, but I was definitely confused, when I saw a slide titled “summary”, which was then followed immediately by 20 more slides, and a final summary, about 25 minutes later. This was very distracting. Sure, the speaker could have said something like “summary so far”, but having the outline of the talk would have been helpful. Actually, he did present an outline of the talk at the beginning, on one slide, which he displayed for about 20 seconds. Not very helpful. Another option is to display the outline periodically throughout the talk, but this means you have to keep saying what you are about to say, instead of just saying it. Especially in short talks, I don’t like to waste time saying what I am going to say. Having the running table of contents, and also a handout, gives people a good idea of what I am going to say, without me having to waste time saying it.

This brings up a more general point about handouts. I think that a good handout can be very helpful to your audience, for a number of reasons:

  1. They can read ahead to see what you are going to say
  2. They can re-read stuff if they don’t understand it the first time you say it
  3. They can take as long as they want to look at your figures
  4. They can take notes on your handout if they want to
  5. If they really liked your talk, they can keep your handout, and perhaps share it with others, or learn more from it

And just to clarify, when I mean handout, I don’t mean your slides printed off on paper. Using this method leaves a lot of whitespace (good for extensive note-takers I suppose, of which I am not one), wasting paper. The handout might be a good place to include long quotes, or large tables, which might not be appropriate for the screen. The handout is also a good place to list all your references, which is very valuable to people who want to know more about your research. It also might be appropriate to display some of your figures differently. In this particular presentation, I had several figures, which I placed one per slide. In the handout however, the figures are grouped into 3×2 subfigures, which allows for better comparison, and also makes them more compact. Furthermore, they are black & white, with font sizes appropriate for the handout. Doing all this with LaTeX was quite simple. Out of the box, LaTeX gives the user the ability to use conditional (if - then) statements. I find it easiest to do with counts, e.g.:

\newcount\Slides \Slides=1 \ifnum\Slides=1 \includegraphics{myColorfigure} \else \includegraphics{myBWfigure} \fi

I think that is probably enough for now. If you are interested, you can download the compiled pdf or the TeX source for my presentation, as well as the compiled handout. Note that the .tex file will not compile on your system as is, due to missing figure files and such, as well as my own custom powerdot theme. But hopefully it should be illustrative.

  • FriendFeed
  • Reddit
  • del.icio.us
  • Digg
  • Slashdot
  • Technorati
  • Facebook
  • Fark
  • TwitThis
  • LinkedIn

Swiss chard and spelt soup

Friday, March 9th, 2007

swiss chard spelt soup 1
As I write this I am enjoying some extremely tasty leftover soup that Clare made last Sunday. It kind of has everything in it, but I think that the swiss chard and the spelt are the most distinctive parts. She had bought some swiss chard at Trader Joe’s (on sale I think), and wanted to make something with it, but didn’t know what. I had seen several recipes in my new Italian cookbook calling for swiss chard, so I suggested she use one of those for inspiration. Clare is not much into following recipes, but she was nice enough to humor me. There was a recipe in the cookbook for some sort of soup with swiss chard, so she used that as a jumping off point. That recipe did not include spelt though.

For those who don’t know, spelt is an ancient cousin of wheat (plants have cousins, you say? — sure, why not). You can make spelt into flour as use it for making bread, or you can use the whole berries. Some people who are allergic to wheat can tolerate spelt.

Anyways, the soup consisted of onions, mushrooms, canned tomatoes, swiss chard, chickpeas, spelt, and vegetable broth. As we sat down to taste it, we both felt it was missing something — RedHot did the trick. The slogan on the bottle is really true. It does add flavor, not just heat.

swiss chard spelt soup 2
So there you have it, a complete, healthy meal in a bowl. Spelt provides some good fiber and starch. Swiss chard provides calcium, iron, and other vitamins and minerals. Chickpeas provide protein, and RedHot adds some flavor. I’m looking forward to a repeat.

  • FriendFeed
  • Reddit
  • del.icio.us
  • Digg
  • Slashdot
  • Technorati
  • Facebook
  • Fark
  • TwitThis
  • LinkedIn

umthesis now on CTAN

Tuesday, March 6th, 2007

I just submitted the umthesis package to CTAN. I will of course keep an up to date version on my own server, but now it will be more accessible to others. If you have not checked out CTAN, I highly recommend it. There are many packages of all sorts that will make your TeXing more enjoyable.

  • FriendFeed
  • Reddit
  • del.icio.us
  • Digg
  • Slashdot
  • Technorati
  • Facebook
  • Fark
  • TwitThis
  • LinkedIn