0

I am trying to reference a Figure and Table (with ~\ref{}) in my document. I placed both elements in a figure environment (figure first, table second, both inside of a minipage) to have them displayed next to each other. For a better look I am using a combined caption. I found a solution to the label issue on this feed. I can now call my figure and the table. However, the table reference seems to be tied to the figure number. The problem is that I have figures and tables in my document that are in their normal environments and the counters at the place where this combined figure/table appears are not the same for the figure and the table.

Does anyone have suggestions on how to fix this to show the correct table and figure numbers? In my preamble I also defined this:

\DeclareCaptionLabelFormat{figandtab}{#1~#2  \&  \tablename~\thetable}

to allow me to use a combined figure and table caption. It is working as it should and states the correct figure and table number. It is just the label and referencing of it that isn't working with the correct counter.

Here is what I have used for the figure/table.

\begin{figure}[h]
    \centering
    \begin{minipage}{0.49\textwidth}
        \centering
        \includegraphics[width=1.0\columnwidth]{picture.jpg}%}
\end{minipage}
\begin{minipage}{0.49\textwidth}
    \centering
    \captionsetup{type=table}
    \resizebox{0.9\linewidth}{!}{%
        \begin{tabular}{lll}
        *my table contents*
        \end{tabular}%
    }
\end{minipage}
\captionsetup{labelformat=figandtab}
\caption{combined caption}
\label{fig:figure_label}
{\makeatletter\edef\@currentHref{table.caption.\the\c@table}\label{tab:table_label}}
\end{figure}

I would be grateful for your help!

4
  • You can avoid \caption altogether. All you really need is \refstepcounter{figure} and \refstepcounter{table} followed by \labels (one each presumably). I take it you don't plan on using a \listoffigures etc. Commented May 11, 2022 at 15:08
  • Thank you @JohnKormylo. I think I would like to retain the option of using a list of figures and tables though. So I think that will not work for me then.
    – Bianca
    Commented May 12, 2022 at 7:03
  • @JohnKormylo, just to add to my previous comment. Your suggestion does work (also without including an additional caption for the table). Do you maybe have a suggestion on how one could make this compatible with using a list of figures and tables?
    – Bianca
    Commented May 12, 2022 at 7:45
  • Yes, using \addcontentsline, but it is easier to show than explain. Commented May 12, 2022 at 12:19

2 Answers 2

0

You can use the command \captionof{<figure or table>}{<text>} (package caption). It will take care of all the homework.

c

\documentclass[12pt]{article}

\usepackage{graphicx}
\usepackage{caption} % needed <<<<<<<<<<<<<<<<<<<<<<

\begin{document}
    \listoftables
    \listoffigures
    
    \begin{figure}[h]
        \centering
        \begin{minipage}{0.49\textwidth}
            \centering
            \includegraphics[width=1.0\linewidth]{example-image}%}
        \end{minipage}
        \begin{minipage}{0.49\textwidth}
            \centering
            \captionof{table}{A table caption}\label{tab:table_label}
            \resizebox{0.9\linewidth}{!}{%
                \begin{tabular}{lll}
                    *my table contents*
                \end{tabular}%
            }
        \end{minipage}      
        \captionof{figure}{combined caption}
        \label{fig:figure_label}
    \end{figure}

See the figure~\ref{fig:figure_label} and the adjoining table~\ref{tab:table_label}.

\end{document}
    
1
  • Thank you! Your suggestion does work and sets the counter in the \ref{} argument correctly. However, if using the \captionof{}{}, I get an additional caption for the table as you showed above. I would like to only have one caption for the whole display element. Is there maybe a way to get rid of the table caption while still retaining the ability to call the table in a list of tables?
    – Bianca
    Commented May 12, 2022 at 7:48
0

This performs the same functions as \caption. Note that the hyperlinks go to the tops of the minipages.

\documentclass{article}
\usepackage{graphicx}
\usepackage{hyperref}
\begin{document}
\listoffigures

\listoftables

\begin{figure}[ht]
\centering
    \begin{minipage}{0.49\textwidth}
        \refstepcounter{figure}\label{fig:figure label}%
        \addcontentsline{lof}{figure}{\protect\numberline{\thefigure}LOF caption}%
        \centering
        \includegraphics[width=\linewidth]{example-image}%}
    \end{minipage}
    \begin{minipage}{0.49\textwidth}
        \refstepcounter{table}\label{tab:table_label}%
        \addcontentsline{lot}{table}{\protect\numberline{\thetable}LOT caption}%
        \centering
        \resizebox{0.9\linewidth}{!}{%
            \begin{tabular}{lll}
            *my table contents*
            \end{tabular}%
        }
    \end{minipage}
\par\vskip\abovecaptionskip
\figurename~\thefigure~\&~\tablename~\thetable: yadda yadda yadda
\par\vskip\belowcaptionskip
\end{figure}

Link to \figurename~\ref{fig:figure label} and \tablename~\ref{tab:table_label}.
\end{document}

You must log in to answer this question.

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