4

Sorry if this is a triviality ... Anyhow,

how would you go about to insert a table inside a figure caption?

how do I go about to insert a block inside a block?

    \begin{figure}[h]
    \begin{center}
        some picture here
        \caption{. . . table here . . . !!}
    \end{center}
    \end{figure}
Ricardo Cruz
  • 1,770
  • 1
  • 22
  • 34
  • 2
    Welcome to TeX.SX! A tabular can go anywhere, not only in a table environment. However, I'm not sure this is the best way to tell readers your ideas. Could you give a more realistic example? – egreg Jul 27 '13 at 08:05
  • A caption of a figure (or table) object ideally is both short and self-contained. Placing a tabular object inside a caption may make it difficult or impossible to achieve these goals. Is there any way you can express what needs to go into the caption without (over)burdening the caption's appearance? – Mico Jul 27 '13 at 17:03

2 Answers2

10

Inside \caption, a table (meaning "table" a tabular environment, not a table float environment!) could be problematic in several ways, for example, in order to format the table under "Figure 1:" since \\ don't work inside the caption. Another example is making a list of figures, since tabular hides the whole caption, even text outside tabular (anyway, a table inside a list of figures will be awfull), although this can solved putting an optional text for the list:

MWE

\documentclass[a5paper]{article}
\usepackage{mwe}

\begin{document}
\listoffigures 

\begin{figure}[h]
\centering
\includegraphics[height=2cm]{example-image}
\caption[A table inside a caption]{
\begin{tabular}{|c|cc|ccc|}
\hline 
a  & b & c & 1 & 2 & 3 \\\hline
d  & e & f & 4 & 5 & 6 \\
g  & h & i & 7 & 8 & 9 \\\hline
\end{tabular}}
\end{figure}
\end{document}

To have "Figure 1": centred and above the table a simple solution is put the tabular environment after the caption:

MWE1

\documentclass[a5paper]{article}
\usepackage{mwe}

\begin{document}
\listoffigures 

\begin{figure}[h]
\centering
\includegraphics[height=2cm]{example-image}
\caption[A table inside a caption]{}
\begin{tabular}{|c|cc|ccc|}
\hline 
a  & b & c & 1 & 2 & 3 \\\hline
d  & e & f & 4 & 5 & 6 \\
g  & h & i & 7 & 8 & 9 \\\hline
\end{tabular}
\end{figure}

\end{document}

Another solution could be avoid the caption and take care yourself of figure counter, references and list of figures, but as counterpart you can place place \thefigure where you want, even inside of tabular environment. Some examples that with the help of Torbjørn T. seem to work also with cleveref and hyperref packages:

MWE

\documentclass{article}
\usepackage{mwe}
\usepackage[colorlinks=true,linkcolor=blue]{hyperref}
\usepackage{booktabs,cleveref}
\usepackage{multirow}

%\fakecap{caption title in list of figures}{label}
\makeatletter
\newcommand\fakecap[2]{
\refstepcounter{figure}
\addcontentsline{lof}{figure}{\figurename~\thefigure: #1}%
\mbox{\figurename~\thefigure}
\renewcommand\@currentlabel{\thefigure}
\label{fig:#2}}
\makeatother

\begin{document}
\listoffigures

\section{Section One}\label{sec:ccc}
This \cref{sec:ccc} has not figures. 
Just to check that counters are not mixed.

\section{Section Two}\label{sec:ddd}
This \cref{sec:ddd} contain the \cref{fig:aaa} 
with a table as caption. Whithout using \verb|\caption|, 
the float is still correctly numbered and cross-referenced.

\begin{figure}[h]
\centering
\includegraphics[height=35pt]{example-image}
\quad\begin{tabular}[b]{|l|ccccc|}
\hline
\fakecap{Another fake caption}{aaa} & 1 & 2 & 3 & 4 & 5 \\
\hline
Some thing  & 6 & -- & 7 & 8 & 9 \\
Another stuf  & 0 & 0 & 1 & $\pi$ & $\alpha$ \\
\hline
\end{tabular}
\end{figure}

\section{Section three}\label{sec:eee}
The  \verb|\fakecap| could be placed everywere, 
inside or outside the table, as well as the image, 
as show the \cref{fig:bbb}  in this \cref{sec:eee}. 

\begin{figure}[h]
\centering
\def\arraystretch{1.85}
\begin{tabular}[b]{cccccc}
\hline
\fakecap{Fake caption in a table}{bbb}
 & 1 & 2 & 3 & 4 & 5 \\
\hline
\multirow{3}{*}{%
\includegraphics[width=.34\textwidth]{example-image}}
 & 1 & & 4 & 5 & 6 \\
 & 3 & 5 & 5 & 8 & 9 \\
 & 7 & 2 & 7 & $\frac{2}{4}$ & 3 \\
 & $\beta$ & 2 &  6 & 6 & 3 \\
\hline
\end{tabular}
\end{figure}

\end{document}
Moriambar
  • 11,466
Fran
  • 80,769
0

You can use \raisebox. For example,

\documentclass{article} 
    \usepackage[font=small,labelfont={bf,footnotesize}]{caption}
    \usepackage{graphicx}
\begin{document}

\begin{figure}
    \begin{center}
        \includegraphics[scale=0.5]{parabola.pdf}
        \caption{
            \raisebox{-0.41cm}{
                \begin{tabular}{rl}
                    Ecuaci\'on can\'onica \;&$(y-k)^2\;=\;4p(x-h)$\\
                    V\'ertice \;& $V=(h,k)$\\
                    Foco\; & $F=(h+p,k)$
                \end{tabular}
                             }
                }
   \end{center}
\end{figure}

\end{document}

enter image description here

wmora2
  • 325
  • 2
  • 10