0

How can I make sure that the table is always just below the figure and they always go together?
Each should have its own caption and the caption follows IEEEtrans as in the image.
In the code below it works but I think there is no constraint to make that they are always next to each other.

EDIT: I want to glue the figure and table together and place them on a corner of a page instead of putting them inside the text.

enter image description here

\documentclass[journal]{IEEEtran}

\usepackage{booktabs} \usepackage{graphicx} \usepackage{blindtext}

\begin{document}

\blindtext[1]

\begin{figure}[!t] \centering \includegraphics[width=0.9\linewidth]{example-image-a} \caption{A figure} \label{fig:a figure} \end{figure} % \begin{table}[!t] \centering \caption{A table} \label{tab:a table} \begin{tabular}{ r@{}c@{}l r@{}c@{}l r@{}c@{}l r@{}c@{}l } % 12 columns
\toprule \multicolumn{6}{c}{\textbf{SET 1}} &\multicolumn{6}{c}{\textbf{SET 2} } \ \cmidrule(rl){1-6} \cmidrule(rl){7-12} \multicolumn{3}{c}{A long name} & &B& & &C& &\multicolumn{3}{c}{A longer name} \ %changed <<<<<<<<<<< \midrule $\mathrm{X_{A}}$ &$\leftrightarrow$ &$\mathrm{X_B}$ & $\mathrm{X_{A}}$ &$\leftrightarrow$ &$\mathrm{X_B}$ & $\mathrm{X_{A}}$ &$\leftrightarrow$ &$\mathrm{X_B}$ & $\mathrm{X_{A}}$ &$\leftrightarrow$ &$\mathrm{X_B}$ \ $\mathrm{Y_{CD}}$ &$\leftrightarrow$ &$\mathrm{Y_N}$ & $\mathrm{Y_{CD}}$ &$\leftrightarrow$ &$\mathrm{Y_N}$ & $\mathrm{Y_{CD}}$ &$\leftrightarrow$ &$\mathrm{Y_N}$ & $\mathrm{Y_{CD}}$ &$\leftrightarrow$ &$\mathrm{Y_N}$ \ $\mathrm{Z_{CDE}}$ &$\leftrightarrow$ &$\mathrm{Z_K}$ &&& &&& &&& \ &A.4& & && & & & && \ &A.5& & && & & & && \ \bottomrule \end{tabular} \end{table}

\end{document}

emnha
  • 445
  • 3
  • 11
  • 1
    You can put both into one float. (There is a problem regarding autoref.) See https://tex.stackexchange.com/questions/643473/unexpected-table-figure-reference – John Kormylo Aug 22 '22 at 23:12

1 Answers1

2

You could gather both objects within the same float environment, either figure or table. Then, with \captionof, you can define which caption is for a table or for a figure.

enter image description here

The example.
Please note, blue words are markers to indicate that latex moves the big float to the right column to keep both objects together.

\documentclass[journal]{IEEEtran}

\usepackage{booktabs} \usepackage{graphicx} \usepackage{blindtext} \usepackage{float} \usepackage{caption} \usepackage{cleveref}

%%% For demonstration \usepackage{xcolor} \usepackage{kantlipsum}

\begin{document} \kant[1-2]

\textcolor{blue}{Before float.} \kant[1][1]

\begin{figure}[!tbh] \centering

\includegraphics[width=0.9\linewidth]{example-image-a}\par
\captionof{figure}{A figure}\label{fig:afigure}

\vspace{\floatsep}

\captionof{table}{A table}\label{tab:atable}
\begin{tabular}{ r@{}c@{}l    r@{}c@{}l    r@{}c@{}l    r@{}c@{}l }     % 12 columns
    \toprule
    \multicolumn{6}{c}{\textbf{SET 1}} &amp;\multicolumn{6}{c}{\textbf{SET 2} }  \\
    \cmidrule(rl){1-6} \cmidrule(rl){7-12}
    \multicolumn{3}{c}{A long name} &amp;   &amp;B&amp; &amp;   &amp;C&amp; &amp;\multicolumn{3}{c}{A longer name}  \\  %changed &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;
    \midrule
    $\mathrm{X_{A}}$    &amp;$\leftrightarrow$  &amp;$\mathrm{X_B}$     &amp; $\mathrm{X_{A}}$  &amp;$\leftrightarrow$  &amp;$\mathrm{X_B}$ &amp; $\mathrm{X_{A}}$  &amp;$\leftrightarrow$  &amp;$\mathrm{X_B}$ &amp; $\mathrm{X_{A}}$  &amp;$\leftrightarrow$  &amp;$\mathrm{X_B}$ \\
    $\mathrm{Y_{CD}}$   &amp;$\leftrightarrow$  &amp;$\mathrm{Y_N}$     &amp; $\mathrm{Y_{CD}}$ &amp;$\leftrightarrow$  &amp;$\mathrm{Y_N}$ &amp; $\mathrm{Y_{CD}}$ &amp;$\leftrightarrow$  &amp;$\mathrm{Y_N}$ &amp; $\mathrm{Y_{CD}}$ &amp;$\leftrightarrow$  &amp;$\mathrm{Y_N}$ \\
    $\mathrm{Z_{CDE}}$  &amp;$\leftrightarrow$  &amp;$\mathrm{Z_K}$     &amp;&amp;&amp;  &amp;&amp;&amp; &amp;&amp;&amp;    \\
                                     &amp;A.4&amp;   &amp;   &amp;&amp;  &amp;   &amp; &amp; &amp;&amp;  \\
                                     &amp;A.5&amp;   &amp;   &amp;&amp;  &amp;   &amp; &amp; &amp;&amp;  \\
    \bottomrule
\end{tabular}

\end{figure}

\textcolor{blue}{After float.} \kant[1-3] \end{document}

Celdor
  • 9,058