Search code examples
latex

Force an image, table and algorithm in a column of 2 column text


I asked how to force an algorithm to be under a table and got an excellent response here.

I want to add an image on top of this. I tried figure, subfigure and adding an image in a minipage, but could not get it working. How can I do this?

Edit: The following somewhat works, but it makes the image caption small-caps and centered, as a Table caption. I want the image's caption to have image style caption (small letters), while the Table to have a table-style caption.

\documentclass[journal]{IEEEtran}

\usepackage{lipsum}
\usepackage{threeparttable, booktabs}
\usepackage{multirow}
\usepackage{amsmath}
\usepackage[ruled, noline, noend, linesnumbered]{algorithm2e}

\begin{document}

    \lipsum[1-4]
    
    \begin{table}[!h] 

      \includegraphics[width=\columnwidth]{image.png}
      \caption{Caption}
      \label{fig:enter-label}


      \centering
        \begin{threeparttable}
            \caption{Example table }
            \begin{tabular}{l|l|l|l|l}
              \toprule
              \multirow{2}{*}  & \multicolumn{2}{c|}{Description}  & \multicolumn{2}{c}{Test}   \\
                               & Test           & Test            & Test       &  Test          \\
              \midrule
               Test            & Test           & Test            & Test       &  Test          \\
            \end{tabular}
            \begin{tablenotes}
                \item[\textdagger]    Test
            \end{tablenotes}
        \end{threeparttable}
        \medskip
        
       \begin{minipage}{\linewidth}
       \makeatletter
       \@twocolumnfalse
       \makeatother
    \begin{algorithm}[H]
      \caption{Test}
      \For{Test}{ 
        Test
        }
    \end{algorithm}
           \end{minipage}
        \end{table}
    
    \lipsum[1-8]

\end{document}

Solution

    • you are missing the graphicx package

    • you could temporarily change the captype to add a figure caption in your table environment


    \documentclass[journal]{IEEEtran}
    
    \usepackage{lipsum}
    \usepackage{threeparttable, booktabs}
    \usepackage{multirow}
    \usepackage{amsmath}
    \usepackage{graphicx}
    \usepackage[ruled, noline, noend, linesnumbered]{algorithm2e}
    
    \begin{document}
    
        \lipsum[1-4]
        
        \begin{table}[!h] 
    
          \includegraphics[width=\columnwidth]{example-image-duck}
          {
          \makeatletter
          \def\@captype{figure}
          \makeatother
          \caption{Caption}
          \label{fig:enter-label}
          }
    
          \centering
            \begin{threeparttable}
                \caption{Example table }
                \begin{tabular}{l|l|l|l|l}
                  \toprule
                  \multirow{2}{*}  & \multicolumn{2}{c|}{Description}  & \multicolumn{2}{c}{Test}   \\
                                   & Test           & Test            & Test       &  Test          \\
                  \midrule
                   Test            & Test           & Test            & Test       &  Test          \\
                \end{tabular}
                \begin{tablenotes}
                    \item[\textdagger]    Test
                \end{tablenotes}
            \end{threeparttable}
            \medskip
            
           \begin{minipage}{\linewidth}
           \makeatletter
           \@twocolumnfalse
           \makeatother
        \begin{algorithm}[H]
          \caption{Test}
          \For{Test}{ 
            Test
            }
        \end{algorithm}
               \end{minipage}
            \end{table}
        
        \lipsum[1-8]
    
    \end{document}
    

    enter image description here