4.4 Floats

Tables and figures in LaTex are called floats, because they tend to float away from the referring text. The user may desire the table or figure to illustrate a killer argument, right here, immediately adjacent to the text. The Latex compiler doesn’t have much regard for killer arguments; it goes by certain built-in design considerations. The effect is that the float object could appear anywhere in the document. The placement of floats is determined by an internal algorithm which is optimized to prevent whitespaces. The float placement algorithm tries to place it by using the supplied placement arguments. The possible values are a sequence of the letters h, t, b, and p, explained below.

Argument Effect
h (Here)—at the position in the text where the figure environment should appear. However, h is not allowed by itself; t is automatically added—the logic being, if the algorithm cannot place the flot object here, then it will place the object at top of next page.
t (Top)—at the top of a text page; not necessarily of the current page or the next page
b (Bottom)—at the bottom of a text page.
p (Page of floats)—on a separate float page, which is a page containing no text, only floats. This format is favoured by some academic publishers, who don’t favour “distractions” or discontinuity in the middle of a text exposition.


The placement (htbp) controls where the table or figure is placed. Tables and figures will not necessarily go near the referring text. The LaTex compiler places float objects around the canvas to prevent large areas of white space from appearing in the document.

Order of processing:
  • The first letter in the placement parameters gets the highest priority of processing. In a [htbp] spec, the top priority will be to place the float ‘here’, immediately next to the referring text.

  • The ‘H’ specifier from the float package forces a float to appear “here”.

  • If the compiler cannot accommodate the desired placement in the first pass, it moves to process the next letter, and so on.
    For instance, while processing [htbp], the compiler will first try “here”. If that doesn’t work, it moves to t, the top of the current page, failing which it will attempt b, bottom of the current page. If the current pass is unsuccessful, the compiler will recycle the commands, beginning with t, the top of the next page.

  • The default for floats--both figure and table--in both article and book classes, is tbp, top of current page, bottom of current page and page of floats.

  • The placement parameters operate on the table placement by exclusion.

  •       o The order of letters determines the priority of LaTex processing. However, the absence of a letter tells the compiler to definitely not consider that option. For instance, a [htp] specification will recycle between ‘here, top of current page and page of floats. But never bottom of the page.
  • To. avoid the off chance of floats appearing at the top of the page before they are referenced in the text, the flafter package ensures floats appear after the point of text reference.

  • The endfloat package overwrites float’s default behaviour and clubs all float objects towards the end of the document.


In order to prevent the compiler from defaulting to the p (page of floats option which has the last priority), it is usual to trick it by ‘ending’ the page wherever feasible. This is done by using the \clearpage command which has the effect of flushing out the current page and inserting all pending floats. The \clearpage command will, of course insert a pagebreak, which is not an intended result. To accommodate the fake page ending with an undesirable pagebreak, the afterpage package can be called \afterpage{\clearpage}, which has the effect of instructing the compiler to wait until the current page is finished and then flush all outstanding floats.

User control in a float environment can be re-established to some extent by specifying the amount of canvas that is available to the float environment. The following table summarises some commands to constrain the float canvas.

Command Instruction
\floatpagefraction The minimum fraction of a float page that must be occupied by floats; default is ‘0.5’.
\textfraction Minimum fraction of a page that must be text; if floats take up too much space to preserve this much text, floats will be moved to a different page. The default is ‘0.2’
\topfraction Maximum fraction at the top of a page that may be occupied before floats; default ‘0.7’.


4.41 Captions
Float objects—figures and tables-- usually go with a caption to give the reader an instant context. This descriptive text is called a caption. It is called with the command \caption{caption-text}. The placement of the \caption command determines the position of the caption relative to the float.

The \caption command will automatically paste a label such as ‘Figure n:’ before the caption text in an article class document or ‘Figure n.n :’ for a book class. The default behaviour is the caption in centered.

The \caption command updates the LaTex’s internal counter, The counter for the figure environment is named 'Figure'; and 'Table' for the table environment. List of figures or List of tables can be called in the main body by invoking \listoffigures and \listoftables at the appropriate point in the document map.

The code below introduces two additional concepts:

1. Change the caption marker (default is Figure n:) with a call \renewcommand{\figurename}{Fig.}. This will mark all figure floats as Fig n.
2. Customise float numbering by overwriting the default running counter. You can define the counter every time with a custom number which makes more sense. \renewcommand{\thefigure}{4.41}

The code and Figure 4.41 below illustrate the use of the \caption call.

Caption on top Caption below
1. \documentclass{article}[12pt]
2. \pagestyle{empty} %supresses page numbering
3. \usepackage[lmargin=1in]{geometry}
4. \usepackage{caption, graphicx}
5. \renewcommand{\figurename}{Fig.}
6. \begin{document}
7. \begin{figure}
8. \vspace*{1cm}
9. \renewcommand{\thefigure}{4.41.1}
10.
11. \caption{\textbf{Black Hole Gobbles a Star} (Illustration credit: NASA/CXC/M.Weiss)}
12. \label{fig}
13. \includegraphics{4.41 blackhole.jpeg}
14. \end{figure}
15. \end{document}
1. \documentclass{article}[12pt]
2. \pagestyle{empty} %supresses page numbering
3. \usepackage[lmargin=1in]{geometry}
4. \usepackage{caption, graphicx}
5. \renewcommand{\figurename}{Fig.}
6.
7. \begin{document}
8. \begin{figure}
9. \renewcommand{\thefigure}{4.41.2}
10. \includegraphics{4.41 blackhole.png}
11. \caption{\textbf{Using the Event Horizon Telescope, scientists obtained an image of the black hole at the center of galaxy M87, outlined by emission from hot gas swirling around it under the influence of strong gravity near its event horizon.} Credits: Event Horizon Telescope collaboration \textit{et al}}.
12. % \label{fig}
13. \end{figure}
14. \end{document}



Black Hole Gobbles a Star

The illustration above depicts a supermassive black hole ripping apart a star and consuming a portion of it, a long-predicted astronomical event confirmed by NASA's Chandra and the European Space Agency's XMM-Newton X-ray Observatories.
Astronomers believe a doomed star came too close to a giant black hole after being thrown off course by a close encounter with another star. As it neared the enormous gravity of the black hole, the star was stretched by tidal forces until it was torn apart. This discovery provides crucial information about how these black holes grow and affect surrounding stars and gas.
Illustration: NASA/CXC/M.Weiss
For Copyright notice, see section 5.
First image of a black hole

Using the Event Horizon Telescope, scientists obtained an image of the black hole at the center of galaxy M87, outlined by emission from hot gas swirling around it under the influence of strong gravity near its event horizon.
Credits: Event Horizon Telescope collaboration et al.
For Copyright notice, see section 5

Figure 4.41 Caption placement



4.42 Table of contents, figures and tables
One of the benefits of multiple counter running in the background is that LaTex can produce a table of content without human intervention. Of course, it is possible to make additional entries by hand at the appropriate places. The command \tableofcontents (or \tableoffigures) calls a table of contents, or list of figures, respectively, at the appropriate point. The table of contents entries are automatically generated from the sectioning commands \section, \subsection, etc.

This code snippet below illustrates the usage of \tableofcontents and Figure 4.42 illustrataes the output.

1. \documentclass{article}[12pt]
2. \pagestyle{empty}
3. \usepackage[lmargin=1in]{geometry}
4. \usepackage{lipsum}
5. \setcounter{tocdepth}{3}. % instructs Latex to keep count to three levels deep
6. \begin{document}
7. \tableofcontents %call to insert table of contents here
8. \newpage
9. \section {Section heading}
10. \lipsum[2]
11. \section {Next section heading}
12. \lipsum[3]
13. \subsection{This is a sub-section}
14. \lipsum[4]
15. \subsubsection{One more indented level}
16. \lipsum[5]
17. \section{Section heading}
18. \lipsum[6]
19. \end{document}


Page 1: Table of contents Page 2: The content within

Figure 4.42 Table of contents