Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm beginning to work on my senior thesis for biochemistry and I'm excited to use LaTeX to make a nice looking final product.

I'm new to LaTeX though so I don't actually know that much about it. Before I invest too much time in LaTeX I wanted to make sure I could do everything I needed to with the software.

In biology it is typical to use a two-column format for papers so I decided to use the twocolumn option in document class at the start of my document. I've found a way to get a one column abstract, include the paper's title in the corner of every page, and include page numbers throughout (all requirements I set for myself). The last thing I wanted to get working before I set down to start making the actual document was images (also known as "floats" in LaTeX?). 99% of my data is actual graphics, either graphs or western blots, so getting images in the document is key. I have figured out how to use the graphicx package to do so and using figure* instead of figure made it span the entire page. The problem is that the image almost always appears on the page after the reference, not on the same page. This is annoying because the way it looks right now I will never have an image on the same page I talk about it, it will always be exactly one page later.

Now that I have my rationale out of the way here is the short version: Is there a trick to placing images where you want them consistently and automatically, specifically in a 2-column document. I included the full rationale because there may be a much better way to approach this that is "outside the box" so to speak and in most of my searching online the first suggestions involve people recommending the asker do something other than what they specifically asked for. To give an example, here is a minimum example:

\documentclass[12pt,twocolumn]{article}

\usepackage{lipsum}
\usepackage{stfloats}

\begin{document}
\section*{Introduction}
\setlipsumdefault{13-19} 
\lipsum

{\bf Here is where I reference Figure~\ref{one}}

\begin{figure*}[tbph]
\makebox[\textwidth]{\framebox[5cm]{\rule{0pt}{5cm}}} 
\caption{And here is the actual figure.
\label{one}} 
\end{figure*}

\lipsum

\end{document}

I found some suggestions to use the multicol package and used it to make a two column page, but it didn't seem to fix the float placement. Also, most people seemed to say that specifying twocolumn in documentclass was the most efficient way to do it for a document that will be almost entirely 2 columns. I understand I could manually move the placement of the images around in my text and fix it, but I will be doing several rounds of revisions and don't want to have to fix it every time. Is there a good solution or will LaTeX not work for me? I apologize if this is a duplicate, most of the other questions I found were a year or more old and I hoped there would be a more modern solution.

share|improve this question
    
Wide figures in two-column documents. Regarding multicols: latex two column layout set figure to load on single column, but Placing figures inside a two-column document (with answer of Frank Mittelbach himself). –  Speravir Mar 31 '13 at 23:36
    
Next remark: There is the quite new (3 months old) package dblfloatfix. Cannot say anything about this. –  Speravir Mar 31 '13 at 23:53
add comment

1 Answer

up vote 4 down vote accepted

enter image description here

First the bad news:

You are correct that as implemented two-column floats are never inserted on the page on which their definition falls. Actually most people find this isn't a problem in practice as the figure* environment doesn't need to be near the first \ref to the figure, however it would be good not to have that restriction.

It would in fact be relatively easy to allow floats to float to the top if they fell in the first column using the same mechanism as the single column case, however the problem is that if the definition falls in the second column then the first column has already been set and saved in a box of full height and so the full width float can not be added.

Now the good news

LaTeX is a very open system, not only is it open source so you can look at the source and change things, its code is modifiable from within the document itself. Any document can redefine any latex definition.

The code below shows how you can automate the insertion of a figure definition on the page before the first reference, so that it is positioned at the top of the page with teh reference.

As posted below it only works with one figure but it would be easy to extend this with some declarative macros so that each figure was added to a list to be inserted as needed. (But it's late and I wanted to show the result of a few minutes tinkering). So while the code below probably isn't production ready it does I hope show that you shouldn't abandon the idea of using LaTeX just because of some perceived restrictions. Other alternative systems may well have restrictions that they don't document so well and that are harder to work round:-)

\documentclass[12pt, twocolumn]{article}

\usepackage{lipsum}

\output\expandafter{\the\output\floatfix}

\makeatletter
\def\floatfix{%
\expandafter\ifx\csname r@x@one\endcsname\relax
\else
\ifnum\c@page=\numexpr\expandafter\expandafter\expandafter
              \@secondoftwo\csname r@x@one\endcsname-1\relax
\aftergroup\figone
\fi
\fi}
\makeatother

\begin{document}
\section*{Introduction}

\def\figone{%
\begin{figure*}[tbph]
\makebox[\textwidth]{\framebox[5cm]{\rule{0pt}{5cm}}} 
\caption{And here is the actual figure.
\label{one}} 
\end{figure*}
\global\let\figone\relax}

\setlipsumdefault{13-19} 
\lipsum

\textbf{Here is where I reference Figure~\ref{one}\label{x@one}}


\lipsum


\end{document}
share|improve this answer
    
Thanks for the quick response! I played around with the code myself and it appears that what you have works well if it is only referenced once. In one example I referenced it on pages 2 and 4, the figure ended up on page 3. With references on pages 2 and 6 the figure ended up on page 6, so it appears that it ends up with the last reference. I'm wondering how hard it would be to change it to use \label instead? That way I could put the label where ever I wanted it? Also support for multiple floats would be a must. Thanks for the help, hopefully you have time tomorrow for a general fix? Thanks! –  Blake Apr 1 '13 at 4:06
    
@Blake did you only use one \label{x@..} after the \ref It should near that reference, I suspect you used a label after every ref? –  David Carlisle Apr 1 '13 at 9:35
    
Yes you're right! I did use the label after every reference, I guess in my attempt to duplicate code I didn't fully understand I duplicated too much and included that unnecessarily. I just removed the extra label and it's working! Thanks a lot, now how could I best extend this to work for an arbitrary number of figures? –  Blake Apr 1 '13 at 18:10
    
@Blake I may do something (but probably not tonight:-) –  David Carlisle Apr 1 '13 at 18:20
    
Ok, no rush, I'm just getting started writing the paper! Thanks for your time :) –  Blake Apr 1 '13 at 20:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.