3

I know that I can place two tabulars in a single table environment and reference both tabulars using the cref package, as in the following example:

\documentclass[oneside,11pt]{book}

\usepackage[semibold,tt=false]{libertine}
\usepackage{libertinust1math}
\usepackage[font={sf,small},labelsep=quad,labelfont=sc]{caption}
\usepackage[subrefformat=parens]{subcaption}
\usepackage[
  expansion = false ,
  tracking = smallcaps ,
  letterspace = 40 ,
]{microtype}
\usepackage[capitalize]{cleveref}
\usepackage{graphicx}

\begin{document}

\begin{table}
  \centering
  \begin{tabular}{ll}
    A & B\\
    C & D\\
  \end{tabular}
  \caption{Table A}\label{tab:a}
  
  \vspace*{2\floatsep}

  \begin{tabular}{ll}
    W & X\\
    Y & Z\\
  \end{tabular}
  \caption{Table B}\label{tab:b}
\end{table}

Refer to \cref{tab:a} and \cref{tab:b}.

\end{document}

mwe1

That is one way to force two tabulars to be on the same page.

Now, however, I want to force a tabular and an image to be on the same page. Is it possible to place a tabular and an image in the same float? I tried the following (similar to this answer):

\documentclass[oneside,11pt]{book}

\usepackage[semibold,tt=false]{libertine}
\usepackage{libertinust1math}
\usepackage[font={sf,small},labelsep=quad,labelfont=sc]{caption}
\usepackage[subrefformat=parens]{subcaption}
\usepackage[
  expansion = false ,
  tracking = smallcaps ,
  letterspace = 40 ,
]{microtype}
\usepackage[capitalize]{cleveref}
\usepackage{graphicx}

\begin{document}

\begin{figure}
  \centering
  \begin{tabular}{ll}
    E & F\\
    G & H\\
  \end{tabular}
  \caption{Table C}\label{tab:c}

  \vspace*{2\floatsep}

  \includegraphics[width=0.2\textwidth]{example-image}
  \caption{Figure A}\label{fig:a}
\end{figure}

Refer to \cref{tab:c} and \cref{fig:a}.

\end{document}

mwe2

However, the labels/captions are incorrect; "Figure 1" should be "Table 1". What can I do?

4
  • 3
    you have already loaded caption package so you can do \captionof{table}>my caption} to put a table caption in a figure or \captionof{figure}{...] to put a figure in a table. Note that in either case the floats may float out of order. Nov 23 '20 at 21:25
  • @DavidCarlisle How can I force the floats to stay in order?
    – Andrew
    Nov 23 '20 at 21:37
  • You have also the option of make two floats, but change the options to maintain they together, including ignoring the rules (e.g., if the second top float is a bit large for the LaTeX taste, simply a [!] could help) o change the rules (for instance, allowing more than two top floats). See here for more about this.
    – Fran
    Nov 23 '20 at 21:39
  • You can put all tables in figure environments then all figures will stay in source order if you put most tables in table environments but some in figures then my float past each other (but same is true of longtable or [H] tables, a table environment may float past them too. Nov 23 '20 at 21:44
3
+500

Use caption's \captionof{<float type>}:

enter image description here

\documentclass[oneside,11pt]{book}

\usepackage[semibold,tt=false]{libertine}
\usepackage{libertinust1math}
\usepackage[font={sf,small},labelsep=quad,labelfont=sc]{caption}
\usepackage[subrefformat=parens]{subcaption}
\usepackage[
  expansion = false ,
  tracking = smallcaps ,
  letterspace = 40 ,
]{microtype}
\usepackage[capitalize]{cleveref}
\usepackage{graphicx}

\begin{document}

\begin{table}
  \centering
  \begin{tabular}{ll}
    E & F\\
    G & H\\
  \end{tabular}
  \caption{Table C}\label{tab:c}

  \vspace*{2\floatsep}

  \begingroup
  \includegraphics[width=0.2\textwidth]{example-image}
  \captionof{figure}{Figure A}\label{fig:a}
  \endgroup
\end{table}

Refer to \cref{tab:c} and \cref{fig:a}.

\end{document}

The grouping of the \captionof{figure}{<caption>} is not really needed here, but it is advised to put \captionof inside a group since it changes macros locally. It already resides within a group provided by the table environment and is placed last inside the float, so it wouldn't affect anything if you remove the \begingroup...\endgroup.

3

The xcoffins package was conceived to place stuff on a page specifying the relative positions with each other, and where in the page. In this case you want a table and a figure stacked vertically and treated as a single element.

In this solution there are 4 coffins (boxes with handles) defined, one for the table, a second for the figure and the last two for their respective captions.

I chose the width of the Table and Figure coffins to be 0.4\textwidth. The captions coffins will adjust their width to their respective parents-width, automatically.

The assembly process are just three steps: join the top center of CaptionTablex to the bottom center of the Tablex, with an Y offset of -\floatsep, then repeating the action for the Figure and its caption. (Shouldn't the caption be above the table?)

Finally the full assembly is typeset in the current insertion point, usually the left side of the text area, over the baseline.

This full set is a text object, not a float, and therefore immune to the TeX float mechanism. That means that can be inserted before or after any text, in a margin, etc; or even outside the text area.

[hc,b] refers to a point at the bottom and the horizontal center of the box, [hc,t] refers to point at the top and the horizontal center of the box.

\documentclass[oneside,11pt]{book}

\usepackage[semibold,tt=false]{libertine}
\usepackage{libertinust1math}
\usepackage[font={sf,small},labelsep=quad,labelfont=sc]{caption}
\usepackage[subrefformat=parens]{subcaption}
\usepackage[%
expansion = false ,
tracking = smallcaps ,
letterspace = 40 ,
]{microtype}
\usepackage[capitalize]{cleveref}
\usepackage{graphicx}

\usepackage{xcoffins} % added

\begin{document}

% allocate  
\NewCoffin\Tablex
\NewCoffin\Figx
\NewCoffin\CaptionTablex
\NewCoffin\CaptionFigx  

%fill
\SetVerticalCoffin\Tablex{0.4\textwidth}{%
    \centering
    \begin{tabular}{ll}
        E & F\\
        G & H\\
    \end{tabular}
}

\SetVerticalCoffin\Figx{0.4\textwidth}{%
    \centering
\includegraphics[width=0.2\textwidth]{example-image}
}

\SetVerticalCoffin\CaptionTablex{\CoffinWidth\Tablex}{\captionof{table}{Table C \label{tab:c}}} 
\SetVerticalCoffin\CaptionFigx{\CoffinWidth\Figx}{\captionof{figure}{Figure A \label{fig:a}}}

 % assembly
%\JoinCoffins\Tablex[hc,t]\CaptionTablex[hc,b](0pt,-0.5\floatsep ) % X Y offsets caption above table
\JoinCoffins\Tablex[hc,b]\CaptionTablex[hc,t](0pt,-0.5\floatsep ) % X Y offsets caption below table
\JoinCoffins\Tablex[hc,b]\Figx[hc,t](0pt,-\floatsep ) % X Y offsets
\JoinCoffins\Tablex[hc,b]\CaptionFigx[hc,t](0pt,-0.5\floatsep ) % X Y offsets

%typeset
\noindent\TypesetCoffin\Tablex(0pt, 0pt) % X Y offsets not needed here
\bigskip

Refer to \cref{tab:c} and \cref{fig:a}.

\end{document}

bounty

I expect the readers to became aware of the potency and potential of this tool--method, which in a very simple way is capable of dealing with a many different elements: tables, text, figures, plots, rules, etc; and accommodate them using the relative position one to the other, instead of an absolute coordinate system.

I works like a layout design program (almost, no GUI) by filling the boxes with its content, each with his own color, font type and size and graphic material, and then arrange and align them according the design specs. There is a clear separation between content and graphic design.

The float mechanism is great until it puts your material in another page, and then you have to turn the page (in a printed document) to see the figure or the table. As it is not a float, it offers the possibility of locating any set of elements in an exact place in a document, the subject of many questions in this forum, without further packages.

1

I would suggest this easy solution with floatrow, which lets you have table and figure side by side, with their respective cations:

\documentclass[oneside,11pt]{book}

\usepackage[semibold,tt=false]{libertine}
\usepackage{libertinust1math}
\usepackage[font={sf,small}, labelsep=quad, labelfont=sc]{caption}
\usepackage[subrefformat=parens]{subcaption}
\usepackage[expansion=false, tracking=smallcaps, letterspace=40]{microtype}
\usepackage[capitalize]{cleveref}
\usepackage{graphicx}
\usepackage{floatrow}

\begin{document}

\begin{figure}
  \centering
\begin{floatrow}\TopFloatBoxes
\killfloatstyle \ttabbox[2\FBwidth]{\begin{tabular}{ll}
    E & F\\
    G & H\\
  \end{tabular}}
{\caption{Table C}\label{tab:c}}
%
\ffigbox{\includegraphics[width=0.2\textwidth]{example-image}}
 {\caption{Figure A}\label{fig:a}}
 \end{floatrow}
\end{figure}

Refer to \cref{tab:c} and \cref{fig:a}.

\end{document} 

enter image description here

2
  • Thank you! Do you know if there is a floatcolumn package?
    – Andrew
    Nov 23 '20 at 22:59
  • 1
    I don't think so, but you can have several consecutive floatrow's.
    – Bernard
    Nov 23 '20 at 23:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.