使用組合標題對圖和表格進行獨立標記(在同一圖環境中)

使用組合標題對圖和表格進行獨立標記(在同一圖環境中)

我試圖在我的文件中引用圖表和表格(帶有 ~\ref{})。我將這兩個元素放置在圖形環境中(第一個是圖形,第二個是表格,兩者都在小型頁面內),以使它們彼此相鄰顯示。為了更好地觀看,我使用了組合標題。我找到了解決標籤問題的方法餵食。我現在可以調用我的圖形和表格。然而,表格參考似乎與圖號相關。問題是我的文件中的圖形和表格處於正常環境中,並且該組合圖形/表格出現位置的計數器與圖形和表格不同。

有人對如何解決此問題以顯示正確的表格和數字有建議嗎?在我的序言中我還定義了

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

允許我使用組合的圖形和表格標題。它正在正常工作,並指出正確的圖形和表格編號。只是標籤和引用無法與正確的計數器配合使用。

這是我用於圖/表的內容。

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

我將非常感謝您的幫助!

答案1

您可以使用命令\captionof{<figure or table>}{<text>}(包caption)。它將處理所有的家庭作業。

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}
    

答案2

這執行與 相同的功能\caption。請注意,超連結位於小型頁面的頂部。

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

相關內容