GeneralStruggling with Table and Figure floats

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
User avatar
tripwire45
Posts: 129
Joined: Thu Apr 10, 2008 4:35 am

Struggling with Table and Figure floats

Post by tripwire45 »

I've been trying to take a document originally created in Word 2007 and convert it into LaTex...basically from scratch. I've done pretty well so far, given the fact that I have been using LaTex (using Kile) for maybe a week tops. I've come up against some of the last, big challenges. Right now, it's floats.

The tables and figures need to appear in very specific parts of the document since a paragraph will refer to a table or figure immediately following. Also, some of the figures have their own subsection titles that they need to appear beneath. This hasn't worked out too well, thus far.

I took a look at the following thread to see if I could get some clues:

http://www.latex-community.org/viewtopic.php?f=5&t=1243

I positioned all of the figures using [!ht]. This put the figures pretty close to where they need to be (but not exactly) *BUT* pushed all of the tables to the bottom of the document. I tried to fix this by positioning the tables using [!h] but that had absolutely no impact.

I believe there's a way to position at least graphics without using a float environment, but my newness to LaTeX is showing and Googling either doesn't yield the specific troubleshooting information or it only provides the standard "this is how you position a table/graphic using a float" without addressing what happens when problems occur.

Needless to say, I'd appreciate any input you may have. Thanks.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Struggling with Table and Figure floats

Post by Stefan Kottwitz »

Hi Trip,
tripwire45 wrote:I believe there's a way to position at least graphics without using a float environment
Yes, there is. Don't use the figure environment. Captions are still possible using \captionof and the caption package (or capt-of), even included in the list of figures. Example:

Code: Select all

\documentclass[a4paper,10pt]{article}
\usepackage{graphicx}
\usepackage{caption}
\begin{document}
\listoffigures
\begingroup
\centering
\includegraphics{picture}
\captionof{figure}{test picture}
\endgroup
\end{document}
Stefan
balf
Posts: 158
Joined: Sat Jan 12, 2008 1:11 am

Re: Struggling with Table and Figure floats

Post by balf »

However, this way of doing things suppresses the specific vertical space wrt the surrounding text, I'm afraid. Maybe it would be better to use the capital H specifier for the placement of the figure ; it is defined in the float package, and has been borrowed by the floatrow package.
You can also give a try at the insbox (plain tex) package.

B.A.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Struggling with Table and Figure floats

Post by localghost »

tripwire45 wrote:I've been trying to take a document originally created in Word 2007 and convert it into LaTex...basically from scratch. I've done pretty well so far, given the fact that I have been using LaTex (using Kile) for maybe a week tops. I've come up against some of the last, big challenges. Right now, it's floats. [...]
You won't get a complete reproduction, unless you do exactly the same page layout, font size and so on.
tripwire45 wrote:[...] I positioned all of the figures using [!ht]. This put the figures pretty close to where they need to be (but not exactly) *BUT* pushed all of the tables to the bottom of the document. I tried to fix this by positioning the tables using [!h] but that had absolutely no impact. [...]
Of course you should use the [!ht] combination also for table environments. From my experience this yields the best results in placing floats.

The purpose of floats is to place figures or tables without disturbing the text flow and providing references. If you are describing a figure/table directly in the text, you won't need a reference hence no float environment. Take this as an example.

Code: Select all

... as shown in the following figure.
\begin{center}
  \begin{picture}
    ...
  \end{picture}
\end{center}
The quick brown fox jumps over the lazy dog. ...
The result is that your figure exactly appears in the output where you defined it in the source (as you already experienced). If you want to have a coherent text flow with a description of a figure/table, you will need a reference.

Code: Select all

... as shown in Figure~\ref{fig:figure}.

\begin{figure}[!ht]
  \centering
  \begin{picture}
    ...
   \end{picture}
  \caption{Figure caption}\label{fig:figure}
\end{figure}

The quick brown fox jumps over the lazy dog. ...
In this case it can happen that the figure doesn't appear as declared in the source but shoved on the next page if there is not enough space left on the current. Now you refer to the label of that figure in your description. Such references are better supported by the varioref package, so take a look.


Best regards
Thorsten¹
User avatar
tripwire45
Posts: 129
Joined: Thu Apr 10, 2008 4:35 am

Re: Struggling with Table and Figure floats

Post by tripwire45 »

Not *quite* as simple as it seems. Getting the tables and graphics to position well together still required a bit of tweaking. I'm pretty close, although just a few graphics tend to drift a bit. I've abandoned the idea of getting them to appear under their own subsection headings, and just added the subsection titles in the figure captions. Looking better, but we'll see how this all holds up once I add more polish (such as replacing the crummy ps graphics with pngs).
Post Reply