LaTeX two column layouts and rubber lengths

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

36 Responses to “LaTeX two column layouts and rubber lengths”

  1. On March 22nd, 2007 at 5:07 pm
    Danny Reeves wrote:

    Rob, you’re hot in latex.

  2. On April 30th, 2007 at 9:27 am
    Julia wrote:

    Thanks for the great work! It really is more than what was expected. I loved its simplicity! Keep up the good work!

  3. On May 9th, 2007 at 1:05 pm
    Wade wrote:

    I think you have a typo in your columnsep code above: \setlength{columnsep}{.25in} should be \setlength{\columnsep}{.25in}

    Notice the \ preceding columnsep.

    I found your article very useful–thanks for posting it! I also see you use powerdot. I do as well and I like it a lot.

  4. On May 9th, 2007 at 3:09 pm
    robfelty wrote:

    Wade: Thanks for your comment. I have corrected the code.

    Rob

  5. On May 12th, 2007 at 4:50 pm
    Christian F. wrote:

    Really impressive. I am a LaTeX newbie and I must admit I was not aware of the ‘table*’ and ‘figure*’ environments; hence, to achieve page-wide tables or figures with ‘twocolumn’ style I used the environmente ’strip’ from package ‘cuted’ (with the drawback that no references toward the environment are allowed).

    So, a big thank you :)

  6. On May 17th, 2007 at 9:57 am
    Marc wrote:

    I’m just preparing a paper for an international conference and wasn’t aware of the figure* environment until I read your blog.

    Thanks a lot!

  7. On May 23rd, 2007 at 4:17 am
    Chris wrote:

    Hi,
    I got a question: if I add the

    \renewcommand\section{\@startsection {section}{1}{\z@}% {-1.5ex \@plus -.5ex \@minus -.8ex}% {1.5ex \@plus.2ex \@minus .2ex}% {\raggedright\normalfont\large\bfseries\sffamily}}

    in my Settings.tex file, LaTeX is complaining that I cannot use \spacefactor in the vertical mode. What is wrong?

    Thanks,

    Chris

  8. On May 23rd, 2007 at 8:26 am
    robfelty wrote:

    Chris,

    I would have to see a minimal example to be sure, but if you are inputing Settings.tex just as a normal file like:

    \input{Settings}

    then you must make sure to start Settings.tex with
    \makeatletter

    and end with

    \makeatother

    Commands with the @ symbol in them are not really intended to be modified by the average user, only true TeXnicians, and is kind of intended to protect the average user from messing things up too much. The makeatletter is not necessary in .sty files.

    I hope this helps.

    Rob

  9. On September 18th, 2007 at 6:31 am
    Ben wrote:

    Hi there, very impressive tweaking! I am preparing a document which is best suited for twocolumn but I was wondering if there is a way to have a line breaking the two columns. I am unlikely to have images that need to span the two columns so hopefully that should be ok. Also is there a way to have two columns on most pages but some that are one column pages?

    Thank you for making this website

    Ben

  10. On September 18th, 2007 at 10:26 am
    robfelty wrote:

    Ben,

    Glad you found the info helpful. There is a way to have a line breaking the two columns. Simply do:
    \setlength{\columnseprule}{XXpt} — 1-2pt is probably a good thickness for the line.

    It is also possible to switch back and forth from 1 to 2 columns. If you are doing this frequently , you may want to check out the multicol package. It makes doing this very easy. If you are only doing it occasionally, you can do something like the following:
    \makeatletter
    \twocolumn[%
    \begin{@twocolumnfalse}
    blah blah
    \end{@twocolumnfalse}
    ]
    \makeatother

    (thanks to Kevin McGowan for that tip)
    This will make a section span both columns without inserting a page break. If you want a pagebreak, you can simply do:
    \onecolumn
    starts a new page with one column
    blah blah
    \twocolumn
    new page with two columns

    Also, to force page breaks, use
    \clearpage
    when in single column mode, or
    \cleardoublepage
    when in two column mode

    Hope that helps.

    Rob

  11. On September 18th, 2007 at 11:11 am
    Ben wrote:

    I just wanted to say thanks for the very speedy reply! It means I can get more done on it tonight.

    Thank you again, it’s much appreciated

    Ben

  12. On September 19th, 2007 at 10:00 am
    Piotr wrote:

    Is there any possibility to introduce different parameters of \columnsep in the same twocolumn text? I’ve tried to change it with \newcommand{…}{\twocolumn\setlength{\columnsep}{…}} but with no results. Help me!

    Piotr

  13. On September 20th, 2007 at 9:26 am
    Xiongfei wrote:

    I tried the following code segment:

    \makeatletter
    \twocolumn[%
    \begin{@twocolumnfalse}
    blah blah
    \end{@twocolumnfalse}
    ]
    \makeatother

    I wanted to put a table between the tags \begin{@twocolumnfalse}
    and \end{@twocolumnfalse}. It did not work. Any way to solve this problem?

    I want single column to contain the wide table with changing to a page. Can this be done?

    Thanks!

  14. On September 20th, 2007 at 9:35 am
    robfelty wrote:

    Xiongfei:

    \begin{table*}
      \centering
      \caption{full width table. Note that it can only appear at the top of a page. That is ok. Most journals do this anyways}
      \begin{tabular}{l r}
    \hline
    full & width\\
    easy & simple\\
    \hline
      \end{tabular}
    \end{table*}

    If you really need it in the middle of the page, you could use the \twocolumn command, but you cannot put a float inside of it (tables and figures are floats — latex decides where to place them, not you). You should be able to use a tabular environment inside the \twocolumn environment. (haven’t tested it though)

  15. On October 5th, 2007 at 12:34 am
    In Line… » Blog Archive » LaTeX float pages wrote:

    [...] sense that LATEX tried to make use of all available space, it often looked odd. Today I came across this article, which talks about an attempt to create a two column [...]

  16. On October 15th, 2007 at 7:04 am
    Stephane Bordas wrote:

    Thanks a lot for this nice work. It is good to see this dedication to increasing understanding. Well done!
    Stephane

  17. On November 20th, 2007 at 3:57 am
    Rohin wrote:

    Thats a nice work. It worked for me. But right now i am interested solve a new problem. Can i switch on and switch off @twosidetrue and @twoside false to go to odd pages in the running text. I tried it but did not work for me. Can you please help me.

  18. On February 13th, 2008 at 12:03 am
    KhoKing wrote:

    Very useful article, thank you!

  19. On February 28th, 2008 at 7:04 am
    Ali wrote:

    I have been writing a document that has two-column and I have a really long equation. I want to specify this equation as double column width. How can I do this?

  20. On February 28th, 2008 at 10:02 am
    robfelty wrote:

    Ali,

    If you can try to break up the equation into multiple lines using eqnarray or multiline. Otherwise, you must put the equation in a figure* or table* environment, which means that it can only appear at the top of the page. You could also try altering the font size a bit to squeeze it in, or sticking out into the margins a little bit. For one equation in my dissertation I ended up using several strategies, including sticking into the margin, breaking up the equation, and making the font size smaller. I have added the code to the end of this post, along with a screenshot of the result.

  21. On March 26th, 2008 at 2:25 am
    erik wrote:

    From the aps website:
    % If in two-column mode, this environment will change to single-column
    % format so that long equations can be displayed. Use
    % sparingly.
    %\begin{widetext}
    % put long equation here
    %\end{widetext}

    I tried it, it works (using revtex4).

  22. On March 28th, 2008 at 11:26 am
    Amir wrote:

    I have a two column document and I need to include a big table in it. But I want it on the bottom of the page not on the top of it, have any idea?

    Thanks,

    Amir.

  23. On April 13th, 2008 at 6:41 am
    Michael wrote:

    Thanks for the help with two columns, especially the column separation command, which I couldn’t find til now, \setlength{\columnsep}{.25in}

  24. On April 28th, 2008 at 6:54 am
    Venkat wrote:

    Thanks dude!

  25. On May 11th, 2008 at 8:09 am
    turtleyuan wrote:

    Many thanks, it help me out in two volume problem with long table.

  26. On June 12th, 2008 at 9:40 am
    emre wrote:

    Hi, this is the second time I find a solution for my problem (1st related to twocolumn -> onecolumn switching of tables & 2nd related to eqn scaling). Thanks a lot.

  27. On July 30th, 2008 at 11:37 am
    Tsenwva wrote:

    Thank you for your good work. It is brief and to the point. The project report like and goal-driven style helps me every single word. Moreover, it is not boring to keep on the reading. Genius!

  28. On October 6th, 2008 at 10:23 pm
    gary wrote:

    Congrats on a job well-done! Great output and clearly a lot of work put into it.

  29. On October 6th, 2008 at 10:25 pm
    gary wrote:

    Really strong work. Succint and informative all at once.

  30. On October 20th, 2008 at 8:39 am
    Ram wrote:

    Hi There
    I am totally new, and will appreciate a sample latex code to tell me how to put the figure on both columns as mentioned above.
    Regards

  31. On October 20th, 2008 at 8:51 am
    Rob wrote:

    @Ran

    \begin{figure*}
    \includegraphics{yourGraphicsFile}
    \end{figure*}
  32. On October 22nd, 2008 at 2:12 am
    malebo wrote:

    I am using the \ctable package, and would like to place two tables side by side without using the \twocolumn option - ideally the \multicol package may be useful, but doesn’t work, does anyone know how to do this?

  33. On October 22nd, 2008 at 2:14 am
    malebo wrote:

    I am using the \ctable package, and would like to place two tables side by side without using the \twocolumn option - ideally the \multicol package may be useful, but doesn’t work, does anyone know how to do this?

  34. On October 22nd, 2008 at 5:44 am
    kutlwi wrote:

    I need to place two tables side by side, and am using the \ctable command to create the tables (better footnote layout). I cannot use the \twoocolumn option because of the empty space created. I have tried using the multicol package, but the tables are not showing, can anyone help?

  35. On October 22nd, 2008 at 6:11 pm
    Robert Felty wrote:

    @kutlwi,

    I think that the subfigure package can do this. The other option is to use two minipage environments, like so:

    \begin{table}
    \begin{minipage}
    \begin{tabular}{l r}
    data & 0.1\\
    \end{tabular}
    \end{minipage}%
    \begin{minipage}
    \begin{tabular}{l r}
    data & 0.1\\
    \end{tabular}
    \end{minipage}
    \end{table}
  36. On October 22nd, 2008 at 11:17 pm
    kutlwi wrote:

    Thank you. the subfigure and minipage environments didn’t work for me, but what worked is the \cleardoublepage command as follows:

    \twocolumn
    \cleardoublepage

    blah blah blah

    \setlength{\columnsep}{1cm}

    \ctable[
    data & etc
    }

    \ctable[
    data & etc
    }

Leave a Reply