图形计数器:标题和标签

图形计数器:标题和标签

我确实有一个普遍的问题,那就是为什么我暂时不提供一个最小的工作示例。

问题:在代码中,是否可以在任何子图/子表下方写入 \caption 和 \label,同时显示表格/图形的主标题?

原因:每当我在第一个 \begin{subfigure} 之前写入 \caption 然后再写入 \label 时,任何子图都会增加图形计数器,这不是我想要的。

\documentclass{report}
\usepackage[utf8]{inputenc}
\usepackage{caption}
\usepackage{subcaption}
\usepackage[utf8]{inputenc}

% Use T1 font encoding
\usepackage[T1]{fontenc}

% Key value processing
\usepackage{pgfkeys}

% Graphics
\usepackage{graphicx}
\usepackage{adjustbox}

% Colors
\usepackage{xcolor}

% Table and figure notes
\usepackage[flushleft]{threeparttable}

% Mathematics
\usepackage{amsmath}
\usepackage{amssymb}
% For mathematical definitions
\newtheorem{definition}{Definition}

% Algorithms
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\usepackage{algorithmicx}

% Use Times New Roman as default font
\usepackage{txfonts}

% Use Garamond as default font
%\usepackage[urw-garamond]{mathdesign}

% Floats
\usepackage{newfloat}
\usepackage{placeins} 

% Header formatting
\usepackage{fancyhdr}
\usepackage{titlesec}

% Footnote formatting
\usepackage[flushmargin,hang,bottom]{footmisc}

% Managing table of contents appearance
\usepackage{tocvsec2}

% Managing list of abbreviation appearance
% Full name's first letter is in capital form
\usepackage{mfirstuc} 

% Change the resetting of counters
\usepackage{chngcntr}

% Advanced tables
\usepackage{array}
\usepackage{tabularx}
\usepackage{multirow}
\usepackage{makecell}
\usepackage{rotating}
\usepackage{tablefootnote}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{threeparttablex}
\usepackage{wrapfig}
\usepackage{colortbl}
\usepackage{pdflscape}
\usepackage{tabu}
\usepackage[normalem]{ulem}
\usepackage{xcolor}

% Flowcharts
\usepackage{tikz}
\usetikzlibrary{calc,matrix,shapes.geometric,arrows,positioning,fit,backgrounds}

% External tables
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.12}

% Advanced captions
\usepackage{caption}
\usepackage[list=false]{subcaption}

% Code listings
\usepackage{listings}

% Minipages with variable lists
\usepackage{varwidth}

% Advanced table of contents formatting
\usepackage[titles]{tocloft}

% Formatting of ordered (enumeration) and unordered (itemize) lists
\usepackage[inline]{enumitem}

% Customizing of citations in the text
\usepackage[style=apa,backend=biber,natbib=true]{biblatex}

% Advanced page layout
\usepackage{geometry}

% Hyperlinks and PDF information
\usepackage{hyperref}

% Glossaries (must be loaded after hyperref)
% Add "notree" if the self-created style is used
\usepackage[acronym,nonumberlist,nopostdot,nomain]{glossaries}

% Length calculations
\usepackage{calc}

% Allow for "Textmarker" highlighting \texthl{highlighted text}
\usepackage{soul}

% \todo Notes
\setlength{\marginparwidth}{2cm}
\usepackage{todonotes}

% Abbreviations
\usepackage[acronym]{glossaries}

% Blind texts
\usepackage{lipsum}

% English hyphenation rules
\usepackage[ngerman, english]{babel}

% Use nice quotation marks with \enquote
\usepackage{csquotes}

\begin{document}

\begin{figure}
    \centering
    \caption{Caption}
    \label{fig:my_label}
    \includegraphics[width=0.3\textwidth]{Log_marginal_likelihood_25_200.png}
\end{figure}

\begin{figure}
    \centering
    \caption{Test}
    \label{mainlabel}
    \begin{subfigure}{.4\textwidth}
        \includegraphics[width=1\textwidth]{Log_marginal_likelihood_25_200.png}
        \caption{sub1}
        \label{labelsub1}
    \end{subfigure}
    \hfill
    \begin{subfigure}{.4\textwidth}
        \includegraphics[width=1\textwidth]{Log_marginal_likelihood_25_2000.png}
        \caption{sub2}
        \label{labelsub2}
    \end{subfigure}
\end{figure}

As can be seen in Figure \ref{labelsub1} and Figure \ref{labelsub2}

\end{document}

实际上,我使用的模板似乎使事情变得更糟(一个相当复杂的模板,因为它在 *.tex 文件中使用 *.cls 文件,cls 文件使用键值对,如\begin{figure}[caption={test},label={labeltest}]。我检查了将图 2 的主标题移动到底部和顶部,子图始终引用主标题/标签。所以我想我可能自己找到了答案,但如果有人认为有更好的方法......很高兴听到它。

相关内容