How to put caption under image without using \begin{figure}?

by Nasser   Last Updated May 23, 2020 01:23 AM

I need to put an image inside table. I can't use figure inside table. Will not work even if I add minipage.

But can add \includegraphics OK inside table. But now I am not able to use \caption any more. It looks like \caption{} only works with figure.

The question is, how to add caption, but without using figure? Here is MWE.

First the version that does not work

\documentclass[12pt]{article}
\usepackage{graphicx}
\usepackage{longtable}
\begin{document}

\begin{longtable}{p{2in}}
    \begin{figure}    
       \includegraphics[width=0.3\textwidth]{example-image-a}
       \caption{my caption}
    \end{figure}
\end{longtable}
\end{document}

so removed figure. But like to use caption, or caption like thing

\documentclass[12pt]{article}
\usepackage{graphicx}
\usepackage{longtable}
\begin{document}

\begin{longtable}{p{2in}}
    %\begin{figure}    
       \includegraphics[width=0.3\textwidth]{example-image-a}
       \caption{my caption} %only when commenting this will it compile
    %\end{figure}
\end{longtable}
\end{document}

The idea is to get something similar to what is obtained when using figure but without using figure, since figure can't be used inside tables.

Is there something that has same semantics as \caption but does not need figure to use?

What is the best way to do this? Please note I only use lualatex to compile.

TL 2020.



Related Questions


Why should a table caption be placed above the table?

Updated November 16, 2017 15:23 PM


figure captations do not show number

Updated September 09, 2018 07:23 AM

Figure "name.jpg" mysteriously shows up!

Updated December 14, 2018 18:23 PM