Stage 5 · Figures, tables and bibliography 33 / 48 ≈ 24 min read

Figures and Tables in LaTeX: Floats, Captions, Lists

Figures, tables and listings are one float machine used three times. This page is the map and the trap list: what a float is for, which slot owns which consequence, why the label follows the caption, and where the list of figures gets its lines.

    One float machine, three pipelines

    A figure and a table are not two kinds of object; they are one machine used twice. Both reserve a box that cannot be split, both hand that box to a queue with a placement request attached, both are numbered by a counter that \caption steps, and both write one line into a side file that becomes a list at the front of the document. The third pipeline — the listing family, and anything you invent with \newfloat — is the same machine a third time with a different counter name, a different word in front of the number and a different extension. Seeing one skeleton is what makes the rest of this topic stop being a list of special cases.

    The stages are fixed, and every question you will be asked about figures and tables is a question about one of them. Material becomes a box. The box joins the deferred-float list with its letters attached. The page builder decides which page and which slot, several pages downstream of your source. \caption numbers it and writes its entry into .lof or .lot. \label records the number for later lookups. And a list command — \listoffigures, \listoftables, \lstlistoflistings — reads those entries back on the following pass. Each stage has its own package, its own error message, and, this is the part people miss, its own file on disk that a clean build can throw away.

    Why a queue at all: TeX breaks pages only at legal glue, and an indivisible box — a 4 cm picture, a sixteen-row table — cannot be cut, so it has to wait until a page has room for the whole of it. The float mechanism is that waiting pile, not an optional convenience laid on top of typesetting and not LaTeX being difficult. Accept it and three otherwise mysterious facts fall out immediately: a float can only move forward from where you typed it, an object too tall to fit any page can never be placed at all, and the position you asked for is a request the page builder is free to refuse.

    \text{material} \to \text{box} \to \text{queue} \xrightarrow{\;[htbp]\;} \text{a page} \to \text{.lof} \to \text{.aux} \to \text{the next pass}
    \text{material} \to \text{box} \to \text{queue} \xrightarrow{\;[htbp]\;} \text{a page} \to \text{.lof} \to \text{.aux} \to \text{the next pass}
    Name the stage before you search for a fix. "The file is not found" and "the file is on the wrong page" are two different machines failing, and the packages that answer them do not overlap.
    Figures and Tables in LaTeX: Floats, Captions, Lists — One float machine, three pipelines
    Rendered output — typeset from the source shown on this page.

    Choosing the carrier: cells, ink or generated rules

    Before any syntax, decide what the reader is supposed to do with the object. Checking individual values, reading a number off a row, comparing a control against a treatment — that is a table, and no picture will do it as well. Seeing shape — a trend, a distribution, where two curves cross, whether an error grows with the input — that is a plot, and a block of six columns by eight rows is how papers end up with a table nobody reads and a referee who asks for the figure instead. The decision is about the reader's task, not about what your measurement software happens to export.

    The three carriers have completely different failure profiles, which is the practical reason to choose deliberately. A table is laid out by your own document, so it reflows, matches the body font, stays searchable and copyable, and fails at width and at column count. An image carries a layout decided by another program, so it fails at resolution, at engine-and-format and at font mismatch, but nothing else can be a photograph, a micrograph, a screenshot or somebody else's circuit diagram. A generated plot draws its own axes, ticks and legend from numbers inside your source, so its fonts and its digits cannot drift away from the text — at the cost of engine and version sensitivity that the other two never have.

    Two boundary calls are worth settling once. An exported image of a table, or of a plot, is nearly always a mistake: it breaks the font match, destroys the text for search and copy, and prints badly at any size the exporting program did not intend; a table belongs in tabular, and a curve belongs in pgfplots or, at worst, in a vector PDF. A picture of an apparatus, conversely, does not become a table because it happens to contain labelled values — the numbers belong in the caption or the prose, and the photograph keeps its job as evidence.

    The cells themselves use one grammar everywhere: the column declaration is written once, l c r per column, & separates cells and \\ ends a row — the same syntax as a matrix, which is why array can sit inside a displayed equation and look like the small bordered tables below. The fence of rules on the left of the pair is the pre-booktabs look, still what a spreadsheet export gives you, and the reason the tables lesson bans vertical rules outright.

    \begin{array}{lcr} left & centre & right \end{array}
    \begin{array}{lcr} left & centre & right \end{array}
    The column spec is a contract every row has to honour, so Extra alignment tab has been changed to 10 columns. is a counting error rather than a typography one: compare specifiers with ampersands, then look for an unescaped & in the text.
    \begin{array}{|c|c|} \hline a & b \\ \hline 1 & 2 \\ \hline \end{array}
    \begin{array}{|c|c|} \hline a & b \\ \hline 1 & 2 \\ \hline \end{array}

    Anatomy of a float, slot by slot

    Six slots in a fixed order: the environment with its bracketed placement request, \centering, the material, \caption, \label, \end. Two of them are conventions and two of them are load-bearing. The load-bearing pair is \caption — the only command in the block that steps a counter and writes a list line — and the position of \label relative to it. The rest can be rearranged by style; those two cannot be rearranged at all without changing what the document says.

    Write \centering, not \begin{center}. The centre environment is a list-like construct: it starts a paragraph, and it adds vertical space above and below itself. Inside a float that space lands between the picture and its caption, which is exactly the gap people then spend an option trying to remove. \centering is a declaration whose scope ends with the float, adds nothing, and is what the document classes themselves use. The same reasoning applies to \small or \footnotesize around a large table: as a declaration inside the float it changes the material's size without pushing anything outward.

    Caption position is a convention with a reason behind it, which is why it is worth keeping. A figure's caption is the punchline: you look at the picture first and then read what it shows, so the text goes below. A table's caption is its title: you need to know what the columns are before you hunt for a value, and the rule above the header row already separates the two, so the text goes above. Both live in the caption package's reach if a house style wants them flipped, but a document that mixes the two conventions reads as though its pages were collected from different papers.

    The listing pipeline compresses the same six slots into option keys — \begin{lstlisting}[caption={...},captionpos=t,label={lst:calib}] — which is why code samples behave like floats in every way that matters: they float away, they get numbered, they appear in their own list, and \ref points at them. They differ in one way that matters more: the material inside is verbatim, so nothing in it can be retypeset, and a caption typed as part of the code listing's body simply does not exist.

    \begin{array}{ll}\text{slot} & \text{what it decides} \\ \texttt{[htbp]} & \text{which page, which slot} \\ \texttt{centering} & \text{the shape of the box} \\ \texttt{caption} & \text{number and list entry} \\ \texttt{label} & \text{every later mention}\end{array}
    \begin{array}{ll}\text{slot} & \text{what it decides} \\ \texttt{[htbp]} & \text{which page, which slot} \\ \texttt{centering} & \text{the shape of the box} \\ \texttt{caption} & \text{number and list entry} \\ \texttt{label} & \text{every later mention}\end{array}
    One float, one box, one number. Two \caption lines inside one environment produce two numbers and two list entries from the same physical box, which legal — and confusing, because a page reference cannot tell them apart.
    % ============================================================
    % One skeleton, three pipelines: figure, table, listing.
    % The counter name, the list file and the printed word change.
    % ============================================================
    \documentclass[11pt,a4paper]{article}
    
    \usepackage[T1]{fontenc}
    \usepackage{graphicx}       % \includegraphics, \graphicspath
    \usepackage{booktabs}       % \toprule, \midrule, \bottomrule
    \usepackage{caption}        % \captionof, \caption*, position keys
    \usepackage{listings}
    \usepackage[colorlinks=true]{hyperref}   % near last, as always
    
    \lstset{basicstyle=\ttfamily\small}
    
    \begin{document}
    
    \listoffigures                     % reads \jobname.lof
    \listoftables                      % reads \jobname.lot
    \lstlistoflistings                 % reads \jobname.lol
    
    \section{Measurements}
    
    % ---- pipeline 1: an image, numbered into .lof ----
    \begin{figure}[htbp]
      \centering
      % \includegraphics[width=0.6\textwidth]{results.pdf}
      \rule{0.6\textwidth}{4cm}          % placeholder, so this file compiles alone
      \caption{Measured pressure versus flow rate.}%
      \label{fig:pressure}               % AFTER \caption: that is what numbers it
    \end{figure}
    
    % ---- pipeline 2: typeset cells, numbered into .lot ----
    \begin{table}[htbp]
      \caption{First two samples.}%      ABOVE the material: a table is titled
      \label{tab:samples}                % the order rule is unchanged by position
      \centering
      \begin{tabular}{lrr}
        \toprule
        Sample & Flow & Pressure \\
        \midrule
        A & 1.0 & 101.3 \\
        B & 2.0 & 198.7 \\
        \bottomrule
      \end{tabular}
    \end{table}
    
    % ---- pipeline 3: verbatim text, numbered into .lol ----
    \begin{lstlisting}[caption={The calibration script.},captionpos=t,
                       label={lst:calib}]
    for s in samples:
        measure(s)      # number, list entry and caption come from options
    \end{lstlisting}
    
    Figure~\ref{fig:pressure}, Table~\ref{tab:samples} and
    Listing~\ref{lst:calib} are three counters, three side files and one
    mechanism. Nothing above is specific to pictures or to numbers in cells.
    \end{document}

    The caption numbers it; the label only reads the number

    The trap in one sentence: \label stores whatever was numbered most recently, and inside a float the numbering is done by \caption. Write \caption{...}\label{fig:pressure} and every mention prints the figure's number. Swap those two lines and the run stays clean, the number comes out in a plausible format, the entry in the list of figures looks reasonable, and the only symptom is a sentence on page six that says "see section 2.1" about a photograph. This is the most common silent failure in the pipeline, and it is worth memorising as an ordering rule rather than looking up each time, because a float you move by hand at midnight reproduces it in a document that was correct the week before.

    There is a second order hiding inside the same command. \caption[short]{long} sends the bracketed text to the list and the braced text to the page, so the two are different strings with different rules. The short form is written into a file and read back later, which means anything fragile in it has to be deferred with \protect; that is why a caption can fail while the list is being typeset, with the reported line number in a part of the document you were not looking at. It also means a long caption shortened for the list is a decision you make deliberately, not an abbreviation the reader never sees.

    The third failure is character-level, and it belongs to captions because they are moved twice. Percent, hash, underscore, ampersand and caret are all live in the argument: 70\% of samples is safe, 70% of samples comments out the rest of the line and, if the caption is long, changes the sentence on the page as well. Inside a table cell the same characters have a second job — & is a column separator and # is a parameter marker there — so a caption written inside a tabular can raise Extra alignment tab a long way from the ampersand that caused it. The fix is the same in every case: \&, \#, \_, \%, and the special-characters page is the full table.

    What the caption does not do is tell you where the object is. That is the label's job, and the machinery behind it — the internal macro the counter writes, the \newlabel line in the .aux, the two passes that make a reference resolve — is the subject of the cross-referencing lesson, which covers it for equations and sections as well as floats. What matters here is the decision that machinery forces on you: any number you type by hand, and any object you move by cutting and pasting, has just changed what every mention of it says.

    \text{caption}(S\,\mid\,L) \;\longmapsto\; \begin{cases}\text{printed:} & L \\ \text{listed in .lof:} & S\end{cases} \qquad S \neq L \;\Rightarrow\; \text{two strings, one command}
    \text{caption}(S\,\mid\,L) \;\longmapsto\; \begin{cases}\text{printed:} & L \\ \text{listed in .lof:} & S\end{cases} \qquad S \neq L \;\Rightarrow\; \text{two strings, one command}
    When a reference names the wrong object, suspect the ordering of two adjacent lines before you touch any spacing parameter — and if the wrong number is a section number, the \label is above the \caption.
    % ============================================================
    % Five captions, five different outcomes in the list of figures.
    % Compile TWICE: the list is written by the pass that reads the body.
    % ============================================================
    \documentclass[11pt,a4paper]{article}
    
    \usepackage{graphicx}
    \usepackage{amsmath}
    \usepackage{caption}        % supplies \captionof and \caption*
    
    \begin{document}
    \listoffigures
    
    \section{Calibration}
    
    % (1) Two strings from one command: the BRACKETED text is what the list
    %     prints, the braced text is what the page prints.
    \begin{figure}[htbp]\centering
      \rule{5cm}{2.5cm}
      \caption[Pressure drop, run 1]{Pressure drop across the filter for run 1,
        averaged over ten cycles with $95\%$ confidence bands.}
      \label{fig:one}
    \end{figure}
    
    % (2) The bracketed argument is stored and re-read while the LIST is being
    %     typeset, so fragile macros need \protect or they break at a line
    %     number several pages away from the caption that caused it.
    \begin{figure}[htbp]\centering
      \rule{5cm}{2.5cm}
      \caption[Run 1, about 0.3 kPa]{Run 1: the fit $y = a + bx$ with
        $\Delta p \approx 0.3$\,kPa, note\protect\footnotemark{} kept out of
        the list.}
    \end{figure}
    
    % (3) No caption at all. The float prints, is never numbered, contributes
    %     nothing to the list, and cannot be pointed at. This is the usual cause
    %     of "my figure is missing from the list of figures".
    \begin{figure}[htbp]\centering
      \rule{5cm}{1cm}
    \end{figure}
    
    % (4) Printed on purpose, unnumbered and unlisted: \caption* steps nothing
    %     and writes nothing. What an ornament in a preface should look like.
    \begin{figure}[htbp]\centering
      \rule{5cm}{1cm}
      \caption*{Decoration. Never numbered, never listed, never referenced.}
    \end{figure}
    
    % (5) Numbered and listed from OUTSIDE the float machinery. A box that stays
    %     where it was typed still gets a number, a list line and a \ref target.
    \noindent\begin{minipage}{0.5\textwidth}
      \centering
      \rule{4cm}{1.5cm}\par
      \captionof{figure}{A graphic pinned under this paragraph.}%
      \label{fig:pinned}%
    \end{minipage}
    
    Figures~\ref{fig:one} and \ref{fig:pinned} sit in the list; the third
    picture does not exist there at all, and the fourth never will.
    \end{document}

    Placement: a request, not a promise

    The letters in [htbp] are not four places to choose from; they are the order in which four attempts are made — here, if a page break can legally be placed at that point; top of the current or the next page; bottom; a page carrying nothing else. LaTeX takes the first that succeeds at the moment the queue is drained, which may be several pages after the source mention. A ! does not force anything either: its real meaning is "this float may not move to an earlier position than the one it was asked for", a nuance that explains most of the folklore about [h!] failing to do what people intended.

    Three consequences of the queue answer most complaints. Floats only travel forward, so a cluster of them late in a section can pile up behind material that has already finished: ! LaTeX Error: Too many unprocessed floats. reports that the waiting list overflowed, not that you own too many pictures. A box taller than the printable area satisfies none of the four letters, and you get either Float too large for page or the silent version where the last pages fill with nothing but pictures — a size problem that no placement letter can fix. And in two-column documents the starred forms figure* and table* span the gutter, which costs them the right to appear anywhere but the top of a page.

    So the professional move is the one that feels like surrender: let the object float, refer to it by number, and keep the source block near the first mention. A reader told "as Figure 3 shows" does not care which page the figure landed on, whereas a document whose every float is pinned is one where the page builder runs out of legal positions and hands you twelve centimetres of white at the bottom of page nine. The knobs to turn when placement genuinely misbehaves — the kernel float parameters, \FloatBarrier, the float package's [H] and what it costs — belong to the float-positioning lesson; what this page owes you is knowing which of them answers your symptom.

    \text{here} \xrightarrow{\text{no}} \text{top} \xrightarrow{\text{no}} \text{bottom} \xrightarrow{\text{no}} \text{own page} \xrightarrow{\text{no}} \text{deferred}
    \text{here} \xrightarrow{\text{no}} \text{top} \xrightarrow{\text{no}} \text{bottom} \xrightarrow{\text{no}} \text{own page} \xrightarrow{\text{no}} \text{deferred}
    Put the float block in the source where the object is first discussed, not where it currently looks acceptable — the second is a position that changes every time you edit a paragraph.

    Where the list of figures gets its lines

    Every \caption does two jobs: it prints and numbers the caption on the page, and it writes a line into a stream — .lof for figures, .lot for tables, .lol for listings — which \listoffigures and \listoftables read back. That is the entire mechanism, and it has four consequences people discover one at a time. Only captioned objects appear. The list lags the document by one pass, so a figure you have just added shows in the list at the second compile. The entry is the short form of the caption when you gave one. And the entries are laid out by the same machinery as the table of contents, which is why the packages that restyle \tableofcontents restyle these lists too.

    An entry is not just a string. It carries the number produced by the counter, the caption text or its short form, the page the float landed on, and with hyperref a destination name — which is what makes list lines clickable and also what makes them a source of warnings, since the text reaches the list through a different code path from the one that prints it. Two names are worth knowing because they are edited constantly: the heading of the list is \listfigurename and \listtablename, while the word in front of each number is \figurename and \tablename, and it is the second pair you change if you want "Fig. 1" rather than "Figure 1".

    Two questions land on this stage. If your document needs a list of something that has none — problem sets, schemas, a custom float built with \newfloat — the missing pieces are always the same three: a counter, a stream file, and a command that reads it, supplied together by \newlistof from tocloft or already assembled for you as \lstlistoflistings. And if an object should not appear in its list at all, the honest answer is \caption*{...} from the caption package: it prints, steps no counter, writes no line, and so leaves nothing for a reference to point at — which is exactly right for an ornament in a preface and exactly wrong for anything you cite.

    A table that runs over four pages is listed once, under the page where it begins, because longtable writes its caption line the same way a float does. Nobody worries about it until a forty-row appendix table appears in the list of tables with a single page number and no hint that it continues, so say so in the short form: \caption[All runs (continued)]{...}, or keep the list entry to one clause and put the qualification in the caption body.

    \text{.lof line} \;=\; \underbrace{1.1}_{\text{counter}} \; \underbrace{\text{Measured pressure}}_{\text{short form, if given}} \; \underbrace{7}_{\text{page of the float}}
    \text{.lof line} \;=\; \underbrace{1.1}_{\text{counter}} \; \underbrace{\text{Measured pressure}}_{\text{short form, if given}} \; \underbrace{7}_{\text{page of the float}}
    Keep .lof and .lot out of version control but never out of the build directory: a freshly cloned repository with a single compile pass shows a document whose lists are simply empty.

    When the object must not move: the non-float branch

    Not every boxed object wants to be a float, and the pipeline has a branch for the ones that do not. The triggers are all semantic rather than aesthetic. The material is a step in an argument, and moving it two pages breaks the argument. It is a form field, a worked example, a screenshot in a manual beside the sentence that walks through it. Or it is simply too large for any of the four letters, which is what happens to a table that grows past a page boundary and discovers that a float is, by definition, something that cannot be split.

    The branch has three tools and they trade the same things. A plain box — a center environment, or a minipage holding the graphic or the tabular — sits exactly where you typed it and, on its own, is invisible to numbering, to the lists and to \ref; that is what \captionof{figure}{...} from the caption package exists for, since it numbers and lists an object from outside the float machinery, and it is the reason "I do not want it to float but I want it in the list" is a solved problem rather than a compromise. longtable is a second, different thing: not a float at all, so it breaks at page boundaries and repeats its header, and it can carry a caption and a number, but it cannot be centred as a unit or moved out of the way, and the space around it behaves like text.

    State the rule once: float the object when its position is decoration, pin it when its position is meaning. Then avoid the two ways people end up in the wrong branch by accident. A longtable inside a table is a deadlock — a construct whose whole purpose is to split, placed inside a box that must not split — and it produces either a page pushed out to the end of the document or a run that complains about unclosed floats. And a bare \includegraphics with a hand-typed "Figure 12" beneath it is a number that will silently rot the first time anyone inserts an illustration above it; if you are not going to float it, you still need \captionof and \label, which is the same two lines you were trying to avoid.

    \begin{array}{lcc} & \text{float} & \text{non-float} \\ \text{position} & \text{page builder} & \text{you} \\ \text{number} & \text{free} & \texttt{captionof} \\ \text{list entry} & \text{free} & \texttt{captionof} \\ \text{may split} & \text{never} & \text{longtable only}\end{array}
    \begin{array}{lcc} & \text{float} & \text{non-float} \\ \text{position} & \text{page builder} & \text{you} \\ \text{number} & \text{free} & \texttt{captionof} \\ \text{list entry} & \text{free} & \texttt{captionof} \\ \text{may split} & \text{never} & \text{longtable only}\end{array}
    A minipage is a box with its own baseline arithmetic: it is the right tool for holding a captioned object in place, and the wrong tool to place beside another one without thinking — that is the subfigures lesson's subject.
    % ============================================================
    % The non-float branch: material whose position is meaning.
    % ============================================================
    \documentclass[11pt,a4paper]{article}
    
    \usepackage[T1]{fontenc}
    \usepackage{graphicx}
    \usepackage{booktabs}
    \usepackage{caption}      % \captionof, \caption*, the skip options
    \usepackage{longtable}    % not a float: it breaks at the page boundary
    
    \begin{document}
    \listoffigures\listoftables
    
    \section{Procedure, in place}
    
    % (A) A plain box, staying exactly here. On its own it is invisible to the
    %     counters, the lists and \ref. \captionof supplies all three from
    %     outside the float, so "must not move" no longer costs numbering.
    \noindent\begin{minipage}{\textwidth}
      \centering
      \begin{tabular}{lrr}
        \toprule
        Step & Time & Pressure \\
        \midrule
        Purge & 3\,s & 12.1 \\
        Fill  & 7\,s & 99.4 \\
        \bottomrule
      \end{tabular}
      \captionof{table}{The two steps the argument depends on.}%
      \label{tab:steps}%
    \end{minipage}
    
    % (B) Too tall for h, t, b or p, because no page has room for the whole of
    %     it: longtable is a text construct. It splits, repeats its header, and
    %     still writes ONE line to .lot, carrying the page where it starts.
    \begin{longtable}{lrr}
      \caption{All forty runs. The list of tables shows this caption once, at
        the starting page --- say "continued" in the text if that will mislead.}\\
      \toprule
      Sample & Flow & Pressure \\
      \midrule
      \endfirsthead
      \multicolumn{3}{l}{\itshape Table \thetable{} continued}\\
      \toprule
      Sample & Flow & Pressure \\
      \midrule
      \endhead
      A & 1.0 & 101.3 \\
      B & 2.0 & 198.7 \\
      \bottomrule
    \end{longtable}
    
    % (C) The deadlock people build by accident:
    %     \begin{table}[htbp] ... \begin{longtable} ...
    %     A float is an un-splittable box, and longtable exists to be split, so
    %     the inner construct can never be honoured: the whole run is pushed to
    %     its own page, or dropped at the end of the document with a warning
    %     about unclosed floats. Pick one branch, never both.
    
    Table~\ref{tab:steps} sits under the paragraph that discusses it, on the
    same page, every time the document is built.
    \end{document}

    Symptoms, and the stage each one belongs to

    The payoff of a map is that error messages stop being a list to memorise and become a routing problem: which stage failed? File `results.pdf' not found. is stage one, the lookup, and lives between \graphicspath, the extension search list and the formats your engine can read. Extra alignment tab has been changed to 10 columns. and ! Misplaced \noalign. are stage two, the material, and are a counting problem or a stray blank line inside the cells rather than a typography problem.

    A float that lands where you did not want it is stage three, and the log almost never says anything about it, because refusing your request is a legal outcome. A caption or reference printing the wrong thing is stage four or five, and is nearly always an ordering question, answered by moving one line. A list of figures that is out of date, or empty, is stage six, and means one compile short or one side file missing. Only the first two categories produce errors at all: the other four are silent, which is why this lesson spends more space on ordering than on syntax.

    So the reading order for the lessons that carry this one's detail. The image pipeline — \graphicspath and its trailing slash, which formats each engine reads, scaling, trim and clip, the draft workflow — is the includegraphics lesson. The cell pipeline — column specifiers, rules, tabularx and its X width computation, header repetition, decimal alignment — is the tables lesson. The queue itself, including the kernel parameters behind h t b p !, [H] and \FloatBarrier, is the float-positioning lesson. Panels, subcaption and the baselines of side-by-side boxes are the subfigures lesson. And the number's journey through the .aux, including why a first pass prints ??, is cross-referencing. What stays here is the part no one of them owns: knowing which of those files to open.

    \begin{array}{ll}\text{not found} & \Rightarrow \text{stage 1: the lookup} \\ \text{wrong shape} & \Rightarrow \text{stage 2: the material} \\ \text{wrong page} & \Rightarrow \text{stage 3: the queue} \\ \text{wrong number} & \Rightarrow \text{stage 4: the caption} \\ \text{wrong words} & \Rightarrow \text{stage 5: the label} \\ \text{missing entry} & \Rightarrow \text{stage 6: the list}\end{array}
    \begin{array}{ll}\text{not found} & \Rightarrow \text{stage 1: the lookup} \\ \text{wrong shape} & \Rightarrow \text{stage 2: the material} \\ \text{wrong page} & \Rightarrow \text{stage 3: the queue} \\ \text{wrong number} & \Rightarrow \text{stage 4: the caption} \\ \text{wrong words} & \Rightarrow \text{stage 5: the label} \\ \text{missing entry} & \Rightarrow \text{stage 6: the list}\end{array}
    Read the log in stage order rather than in line order: the first error names the stage, and everything after it is the same object falling through the remaining five.

    Lesson cheat sheet

    One key line of code from each section — jump to it or copy it straight from here.

    Section Key code
    \text{material} \to \text{box} \to \text{queue} \xrightarrow{\;[htbp]\;} \text{a page} \to \text{.lof} \to \text{.aux} \to \text{the next pass}
    \begin{array}{lcr} left & centre & right \end{array}
    \documentclass[11pt,a4paper]{article}
    \text{here} \xrightarrow{\text{no}} \text{top} \xrightarrow{\text{no}} \text{bottom} \xrightarrow{\text{no}} \text{own page} \xrightarrow{\text{no}} \text{deferred}
    \text{.lof line} \;=\; \underbrace{1.1}_{\text{counter}} \; \underbrace{\text{Measured pressure}}_{\text{short form, if given}} \; \underbrace{7}_{\text{page of the float}}
    \begin{array}{ll}\text{not found} & \Rightarrow \text{stage 1: the lookup} \\ \text{wrong shape} & \Rightarrow \text{stage 2: the material} \\ \text{wrong page} & \Rightarrow \text{stage 3: the queue} \\ \text{wrong number} & \Rightarrow \text{stage 4: the caption} \\ \text{wrong words} & \Rightarrow \text{stage 5: the label} \\ \text{missing entry} & \Rightarrow \text{stage 6: the list}\end{array}

    Common mistakes

    • \label written above \caption. Nothing fails, the number is correctly formatted, and \ref{fig:pressure} prints the section the float sits in — because \caption is what steps the figure counter and the label stored whatever was numbered before it. The order is \caption{...}\label{fig:pressure}, and the same rule applies when the caption is placed above a table: position changes, order does not.
    • ! LaTeX Error: \caption outside float. The \caption line stands in a center environment or loose in the text after the tabular was un-floated, so there is no counter to step. Either put the float back, or keep the object where it is and use \captionof{table}{...} from the caption package, which numbers and lists it without the float.
    • A list of figures that is empty, or a page behind. \listoffigures reads .lof, and that file is written only by \caption — so the usual causes are a caption typed as \caption*{}, a float with no caption at all, one compile instead of two, or a build that deleted or never produced the side files, which includes compiling a child file directly under another \jobname.
    • ! LaTeX Error: Too many unprocessed floats. The waiting list overflowed because floats were requested faster than the page builder could place them — a tall picture near the end of a section is enough. It is not a bug in the figures: drain the queue with \clearpage at a section boundary, shrink the boxes, and stop asking for [h] on objects that cannot fit there.
    • ! Misplaced \noalign. plus ! Extra alignment tab has been changed to 10 columns. Vertical space typed on its own line between rows, a blank line inside the tabular, an & in a cell that is not \&, or more separators than the column spec declares. Attach space to a rule or write it as \\[6pt] at the end of a row, and count specifiers against ampersands.
    • A table that survives until it is moved. Typing \label{tab:x} once and reusing the block with copy-paste duplicates the key, so the later write owns the number, page and destination together and the earlier table becomes unreachable; and a row inserted into a table whose caption you edited by hand leaves the printed number and the list entry disagreeing. Let the counter do the numbering, give each float its own key, and grep for duplicate \label{ before you submit.

    Questions about this lesson

    What is the actual difference between the figure and table environments in LaTeX?
    None in mechanism, three in appearance. Both are floats: both reserve an un-splittable box, queue it, place it with the same h t b p letters, and are numbered by a caption. What differs is the counter (figure versus table), the side file the caption writes (.lof versus .lot), the word printed in front of the number (\figurename versus \tablename), and the convention for where the caption goes (below for figures, above for tables). Because the environments are interchangeable in every other respect, you may put a tabular inside a figure or an image inside a table; doing so is a decision about which numbering series and which list the object joins, which is exactly what you should be choosing on purpose.
    Why is my figure missing from the list of figures in LaTeX?
    Only \caption writes list lines, so work through four causes in order. The float has no \caption at all, or it uses \caption*{}, which prints without numbering or listing. The caption is present but you compiled once: the list is produced from \jobname.lof by the pass after the one that wrote it, so a newly added figure appears at the second compile. The .lof is missing or stale, which happens after a cleanup, on a fresh clone, or when a child file is compiled directly under a different \jobname. Or the caption sits inside verbatim material or a listing body, where it never reaches the captioning code. The corresponding fix for a deliberately unlisted object is \caption*{}; the fix for an accidentally unlisted one is usually a second compile.
    Should a caption go above or below a table in LaTeX?
    The convention is above for tables and below for figures, and the reason is how each is read: a table caption is a title you need before scanning the columns, while a figure caption is a punchline you read after looking at the picture. LaTeX follows neither automatically — \caption prints wherever you type it — so put \caption and \label first inside a table environment and last inside a figure. If a journal or a house style wants something else, change it document-wide with the caption package (\captionsetup[table]{position=top} and the skip lengths) rather than per float, because a document that mixes the two conventions looks assembled from fragments even when each individual float is correct.
    How do I keep a LaTeX table on the same page as the text that mentions it?
    Four options with increasing cost. Move the source block earlier and let it float: usually the mention still ends up on the same page and nothing else breaks. Load the float package and ask for [H], which pins the object exactly where it stands — at the price of a possible large gap at the bottom of the page, and it stops working entirely inside a two-column span or when the box is taller than what is left. Take the object out of the float machinery: a minipage or a plain box with \captionof{table}{...} stays put and still gets a number, a list entry and a \ref target. If the reason it will not fit is height rather than preference, the right construct is longtable, which is not a float and is designed to break across pages. What you should not do is put a longtable inside a table float: an un-splittable box around a splittable table resolves in favour of the box and pushes the whole thing out of sequence.
    Why does \ref print the section number instead of the figure number?
    Because \label stores whatever was numbered most recently, and inside a float the numbering is done by \caption. Putting \label before \caption means the label records the last section, theorem or equation counter instead of the figure one. The run produces no warning: the format is plausible and the number exists, so the only symptom is prose that points at the wrong kind of object. The rule is caption first, label second, always — and it is unchanged by caption position, so a table whose caption sits above the material still takes \caption then \label on the first two lines. If instead the reference prints ?? you have a different problem, namely a missing second pass or a key that was never written.
    What is the difference between \centering and \begin{center} inside a figure or table?
    Both centre the material; only one of them does it quietly. The center environment is a list-like construct that ends the current paragraph and adds vertical space above and below itself — inside a float that space lands between the graphic and its caption, which is the gap you then have to remove with a skip option. \centering is a declaration: it switches the alignment for the rest of the current group, which in a figure means exactly the float, and it adds nothing. That is why the classes use \centering in their float definitions and why \centering is the correct first line of any figure or table. The same reasoning covers \small or \footnotesize around a wide table: as declarations inside the float they resize the material without introducing spacing of their own, whereas the equivalent environments would push the float apart from the text around it.

    Live playground: edit the LaTeX, see it render

    The preview updates as you type — break it on purpose to see how errors look.

    KaTeX error
    Try an example

    Keep reading

    Three ways into the same idea: the notation itself, the lesson that teaches it, and an article that applies it.