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}
1

1 Answer 1

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}} &\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{figure}

\textcolor{blue}{After float.} \kant[1-3]
\end{document}
2
  • That looks very nice. Can I keep the same caption style as the original one?
    – emnha
    Aug 23, 2022 at 0:27
  • I fixed it with \usepackage{booktabs,capt-of} . Thanks.
    – emnha
    Aug 23, 2022 at 0:49

You must log in to answer this question.

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