My ongoing battle with LaTeX

I’ve started using LaTeX to prepare assignments and other documents, and so far it’s working out pretty well. Formatting math is easily done, especially since I’m coming from OpenOffice, which uses a simplified version of the same markup. Importing and formatting code files with the listings package is great too. My big issue has been with positioning of figures.

It’s easy enough to add a figure to a document, and give it a caption, or reference it from elsewhere in the text. Getting it to flow into the text where you want it to is another story altogether. LaTeX likes to keep pages balanced, so as long as there’s text to be output, it doesn’t want to take up too much space on a page with figures. LaTeX likes to re-flow your document automatically to make sure it remains visually pleasing when you make changes to it. The problem is that with most assignments what’s needed is not so much a visually pleasing document as a document that will be easy for a TA or professor to mark. In order to achieve this, you generally want, say, the text and figures for question 6 to all appear, in order, before any of the text for question 7.

I’ve found a couple of the things that will make LaTeX float figures to later pages are settings for the limit as to how many figures it will allow on one page and how much text it will push to the next page to make room for figures. These commands will change those limits:

\renewcommand{\textfraction}{x%}
\setcounter{totalnumber}{x}

The first one sets the minimum fraction of text that will be displayed on any page, and the second sets the maximum number of figures to appear on any page. These two settings, in combination with the ! and h positioning flags to the figure environment, get close to letting you force the positioning of figures.

I’m still looking for something better though…

Leave a Reply