由于加载 subcaption 或 subfig 包导致字幕样式丢失

由于加载 subcaption 或 subfig 包导致字幕样式丢失

我问的是,是否有任何方法可以使用该subcaption包,而无需加载其自己的样式。更准确地说,我有一个带有相关.sty文件的 LaTeX 模板,它为我提供了这种类型的标题样式:

在此处输入图片描述

如果我尝试加载subcaptionsubfig包,我将完全失去这种风格。

有没有办法使用这些包来保持原始模板样式,或者像subfig没有这些包一样用字母枚举图形?我正在使用此处提供的 IOP latex 模板:Iop 模板

太感谢了。

答案1

如果您确实想使用类似subfig下面的方法,至少可以得到一些接近的行为,尽管确实需要更多的手动工作。我希望这可以与您的模板一起使用(我在回答 TeX.SX 上的问题时不会访问第三方网站,因此没有使用您的模板进行测试)!

\documentclass[]{article}

\usepackage{blindtext}
\usepackage{graphicx}
\usepackage{etoolbox} % to hook into `figure` and reset the mysubfig counter

% reset the counter (it is unlikely that another figure environment has
% additional subfigures of the previous one
\AtBeginEnvironment{figure}{\setcounter{mysubfig}{0}}


\newcounter{mysubfig}[figure]% also reset after the figure-counter has increased
\makeatletter
\newcommand*\mysubfig{\@ifstar\mysubfig@above\mysubfig@below}
\newcommand*\mysubfig@above{%
  \renewcommand*\themysubfig{\thefigure(\alph{mysubfig})}%
  \refstepcounter{mysubfig}(\alph{mysubfig})}
\newcommand*\mysubfig@below{%
  \renewcommand*\themysubfig{\the\numexpr\c@figure+1\relax(\alph{mysubfig})}%
  \refstepcounter{mysubfig}(\alph{mysubfig})}
\makeatother

\begin{document}
You could place the figures into \texttt{minipage}s with individual
\verb|\caption|s:
\begin{figure}[!htbp]
  \centering
  \begin{minipage}[]{0.4\linewidth}
    \centering
    \includegraphics[width=0.9\linewidth]{example-image-a}
    \caption{left picture}
    \label{fig:1l}
  \end{minipage}
  \begin{minipage}[]{0.4\linewidth}
    \centering
    \includegraphics[width=0.9\linewidth]{example-image-b}
    \caption{right picture}
    \label{fig:1r}
  \end{minipage}
\end{figure}

Or you put some letters semi-manually beneath them. If the caption is below the
figures use the unstarred version:
\begin{figure}[!htbp]
  \centering
  \begin{minipage}[]{0.4\linewidth}
    \centering
    \includegraphics[width=0.9\linewidth]{example-image-a}\\
    \mysubfig\label{fig:2l}
  \end{minipage}
  \begin{minipage}[]{0.4\linewidth}
    \centering
    \includegraphics[width=0.9\linewidth]{example-image-b}\\
    \mysubfig\label{fig:2r}
  \end{minipage}
  \caption{In \ref{fig:2l} we see an A; in \ref{fig:2r} we see a B}
  \label{fig:2}
\end{figure}

Else use the starred version:
\begin{figure}[!htbp]
  \centering
  \caption{In \ref{fig:3l} we see an A; in \ref{fig:3r} we see a B}
  \label{fig:3}
  \begin{minipage}[]{0.4\linewidth}
    \centering
    \includegraphics[width=0.9\linewidth]{example-image-a}\\
    \mysubfig*\label{fig:3l}
  \end{minipage}
  \begin{minipage}[]{0.4\linewidth}
    \centering
    \includegraphics[width=0.9\linewidth]{example-image-b}\\
    \mysubfig*\label{fig:3r}
  \end{minipage}
\end{figure}

Just to see if it works if you use the unstarred after the starred version.
\begin{figure}[!htbp]
  \centering
  \begin{minipage}[]{0.4\linewidth}
    \centering
    \includegraphics[width=0.9\linewidth]{example-image-a}\\
    \mysubfig\label{fig:4l}
  \end{minipage}
  \begin{minipage}[]{0.4\linewidth}
    \centering
    \includegraphics[width=0.9\linewidth]{example-image-b}\\
    \mysubfig\label{fig:4r}
  \end{minipage}
  \caption{In \ref{fig:4l} we see an A; in \ref{fig:4r} we see a B}
  \label{fig:4}
\end{figure}
\end{document}

这是输出的第一页(裁剪为有趣的部分): 在此处输入图片描述

笔记:

s 标签中图形计数器的格式\mysubfig必须进行调整以匹配 的格式\thefigure。下面的代码不需要这样做,但我不能保证它与更改的包兼容\refstepcounter(尽管我做了一个简短的测试hyperref,似乎成功了)。

\documentclass[]{article}


\usepackage{blindtext}
\usepackage{graphicx}
\usepackage{etoolbox} % to hook into `figure` and reset the mysubfig counter

% reset the counter (it is unlikely that another figure environment has
% additional subfigures of the previous one)
\AtBeginEnvironment{figure}{\setcounter{mysubfig}{0}}


\newcounter{mysubfig}[figure]% also reset after the figure-counter has increased
\renewcommand*\themysubfig{\thefigure(\alph{mysubfig})}%
\makeatletter
\newcommand*\mysubfig{\@ifstar\mysubfig@above\mysubfig@below}
\newcommand*\mysubfig@above{%
  \refstepcounter{mysubfig}(\alph{mysubfig})}
\newcommand*\mysubfig@below{%
  \bgroup
  \advance\c@figure by 1
  \xdef\mysubfig@thefigure{\thefigure}%
  \egroup
  \stepcounter{mysubfig}%
  \protected@edef\@currentlabel{%
    \p@mysubfig\mysubfig@thefigure(\alph{mysubfig})}%
  (\alph{mysubfig})%
  }
\makeatother

\begin{document}
You could place the figures into \texttt{minipage}s with individual
\verb|\caption|s:
\begin{figure}[!htbp]
  \centering
  \begin{minipage}[]{0.4\linewidth}
    \centering
    \includegraphics[width=0.9\linewidth]{example-image-a}
    \caption{left picture}
    \label{fig:1l}
  \end{minipage}
  \begin{minipage}[]{0.4\linewidth}
    \centering
    \includegraphics[width=0.9\linewidth]{example-image-b}
    \caption{right picture}
    \label{fig:1r}
  \end{minipage}
\end{figure}

Or you put some letters semi-manually beneath them. If the caption is below the
figures use the unstarred version:
\begin{figure}[!htbp]
  \centering
  \begin{minipage}[]{0.4\linewidth}
    \centering
    \includegraphics[width=0.9\linewidth]{example-image-a}\\
    \mysubfig\label{fig:2l}
  \end{minipage}
  \begin{minipage}[]{0.4\linewidth}
    \centering
    \includegraphics[width=0.9\linewidth]{example-image-b}\\
    \mysubfig\label{fig:2r}
  \end{minipage}
  \caption{In \ref{fig:2l} we see an A; in \ref{fig:2r} we see a B}
  \label{fig:2}
\end{figure}

Else use the starred version:
\begin{figure}[!htbp]
  \centering
  \caption{In \ref{fig:3l} we see an A; in \ref{fig:3r} we see a B}
  \label{fig:3}
  \begin{minipage}[]{0.4\linewidth}
    \centering
    \includegraphics[width=0.9\linewidth]{example-image-a}\\
    \mysubfig*\label{fig:3l}
  \end{minipage}
  \begin{minipage}[]{0.4\linewidth}
    \centering
    \includegraphics[width=0.9\linewidth]{example-image-b}\\
    \mysubfig*\label{fig:3r}
  \end{minipage}
\end{figure}

Just to see if it works if you use the unstarred after the starred version.
\begin{figure}[!htbp]
  \centering
  \begin{minipage}[]{0.4\linewidth}
    \centering
    \includegraphics[width=0.9\linewidth]{example-image-a}\\
    \mysubfig\label{fig:4l}
  \end{minipage}
  \begin{minipage}[]{0.4\linewidth}
    \centering
    \includegraphics[width=0.9\linewidth]{example-image-b}\\
    \mysubfig\label{fig:4r}
  \end{minipage}
  \caption{In \ref{fig:4l} we see an A; in \ref{fig:4r} we see a B}
  \label{fig:4}
\end{figure}
\end{document}

相关内容