3

I have a table and a figure, both with captions, that I want to keep together, problem is that when

\begin{figure}[htbp]
   ...figure code, graphics, plot, whatever
   \caption[small caption]{figure caption}\label{fig:figlabel}
\end{figure}
\begin{table}[htbp]
   \caption[small caption]{table caption}\label{tab:tablabel}
   ...table code, numbers, etc.
\end{table}

is used, latex has a tendency to split them up sometimes, I really want them kept together on a dedicated page, there is plenty of room on a single page, for both.

Anyone know a simple solution?

2
  • I think the problem is here that figures as floats and tables as floats both get a counter. I guess, the best soltion is to define a new float environment, where you put in \includegraphics (or whatever) and begin{tabular}, and also set the counters. Yet the captions might be difficult then... (Edit: see answer of Gonzalo Medina for that)
    – jjdb
    Apr 19, 2013 at 15:10
  • @jjdb it is not the floating environment that increments the counters and write to teh list of.. files, but the caption command, so what you describe is pretty much what happens anyway. Apr 19, 2013 at 15:47

1 Answer 1

3

You can use only one float environment and \captionf from the capt-of (or caption) package:

\documentclass{article}
\usepackage{capt-of}

\begin{document}

\begin{figure}[htbp]
   ...figure code, graphics, plot, whatever
   \caption[small caption]{figure caption}\label{fig:figlabel}
   \captionof{table}[small caption]{table caption}\label{tab:tablabel}
   ...table code, numbers, etc.
\end{figure}

\end{document}

enter image description here

5
  • Does this give the right counters? Will the table show up in the List of Tables?
    – jjdb
    Apr 19, 2013 at 15:11
  • Gives the right counters, however, now I have table 1.2 appearing in the typeset document before an unrelated table 1.1 (and also in the list of tables). Maybe a float barrier before and after will enforce numeric consistency. Apr 19, 2013 at 15:18
  • \FloatBarrier before and after fixed the numbering, not sure if this is the most sensible solution. Apr 19, 2013 at 15:20
  • @jjdb of course. Why wouldn't it? Apr 19, 2013 at 15:43
  • @ADP yes, that might happen, as you now have a bigger floating object, so the positioning algorithm will place it in the best location according to the rules for positioning. Once your document is finished, if necessary, you can make some manual adjustment for the positioning. Apr 19, 2013 at 15:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .