子图使用 sidenotes 包中的 sidecaptions 来中断图编号

子图使用 sidenotes 包中的 sidecaptions 来中断图编号

我正在将标题放在包的边缘sidenotes。我还经常使用subfigure来自的环境subcaptions来注释子图并引用它们。

我现在注意到这种组合破坏了编号。MWE:

\documentclass[a4paper,11pt]{scrbook}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{hyperref}

\usepackage{geometry}
\geometry{a4paper, top=10mm, left=33mm, right=46mm, bottom=46mm, headsep=\baselineskip, 
          marginparwidth=43mm, marginparsep=1em}

% ********************************************************************
% captions, taking use of the margins
% ********************************************************************
\usepackage{ragged2e}
\usepackage{sidenotes}
\DeclareCaptionStyle{stdstyle}{
    format=hang,                 % caption hangs behind label
    justification=justified,     % caption is a normal paragraph
    singlelinecheck=false,       % always left-align caption
    labelsep=quad,               % quad separator behind label
    labelfont=sc,                % label in scshape
    font=footnotesize            % all in small font size
}
\DeclareCaptionJustification{outerragged}{\ifthispageodd{\RaggedRight}{\RaggedLeft}}
\DeclareCaptionStyle{sidestyle}{
    format=plain, %indention=2em, % whole line for caption, with indent after first
    justification=outerragged,    % caption is a normal paragraph
    singlelinecheck=false,        % always left-align caption
    labelsep=newline,             % quad separator behind label
    labelfont=sc,                 % label in scshape
    font=footnotesize             % all in small font size
}
\DeclareCaptionStyle{marginfigure}{
    style = sidestyle,
    labelsep=quad
}
\DeclareCaptionStyle{widetable}{style = stdstyle}
\DeclareCaptionStyle{widefigure}{style = stdstyle}
\DeclareCaptionStyle{sidecaption}{
    style = sidestyle,
    format=plain,
    labelsep=newline
}
\usepackage[style = stdstyle]{caption}
\usepackage[
    format=hang,
    justification=raggedright,
    labelfont=sc
]{subcaption}

\begin{document}
\chapter{for the numbers}
\begin{figure}
    \sidecaption{caption of figure 1
    \label{fig:1}
    }
    \includegraphics[width=.6\textwidth]{example-image-a}
\end{figure}
some text and we talk about \autoref{fig:1}

\begin{figure}
    \sidecaption{caption of figure 2. this one has two images but nor subfigures
    \label{fig:2}
    }
    \includegraphics[width=.5\textwidth]{example-image-a}%
    \includegraphics[width=.5\textwidth]{example-image-a}
\end{figure}
some text and we talk about \autoref{fig:2}

\begin{figure}
    \sidecaption{caption of figure 3. this one has two images and uses subfigures with captions to address the subplots
    \label{fig:3}
    }
    \begin{subfigure}{0.5\textwidth}
        \includegraphics[width=\columnwidth]{example-image-a}%
        \caption{some text for 3a}
        \label{fig:3:a}
    \end{subfigure}%
    \begin{subfigure}{0.5\textwidth}
        \includegraphics[width=\columnwidth]{example-image-b}
        \caption{some text for 3b}
        \label{fig:3:b}
    \end{subfigure}
\end{figure}
some text and we talk about \autoref{fig:3} and then there is something important about \autoref{fig:3:a} and \autoref{fig:3:b} but why does this latter one increase the figure counter?

\begin{figure}
    \sidecaption{caption of figure 4
    \label{fig:4}
    }
    \includegraphics[width=.6\textwidth]{example-image-a}
\end{figure}
some text and we talk about \autoref{fig:4} but hey it's Figure 1.5 now...

\end{document}

我得到了正确编号的图 1.1 和 1.2,它们都没有使用环境subfigure。图 1.3 的编号正确,但参考子图将计数器增加到 1.4a 和 1.4b,而不是 1.3a。此外,下一个图的编号为 1.5,完全跳过了 1.4。

显然,子图似乎打开了一个新的图,或者至少增加了图计数器。观察到的行为与是否引用子图无关。下一个图的编号总是错误的。

有人知道到底发生了什么吗?最重要的是,如何解决它?

为了直接解决一些潜在的问题并让您了解替代方法应提供哪些功能,这里列出了我这样做的一些原因:我将标题放在边缘,因为那里 (i) 有空间,并且 (ii) 我还在那里设置了整个子图集的图例,这比把它放在其中一个图中方便得多,并且我在格式方面比放在图下方的标题中有更多的自由。我使用该subcaption包是因为它效果最好,并且语法比 KOMA-sidecaption 更简单、更简短。特别是标题可能比图形本身的高度更长,然后标题文本会放在正文旁边。KOMA 方法不允许这样做(或者我没有让它工作)。

如果有人采用不同的方法实现上述功能,我也会非常欢迎。

答案1

\sidecaption{...}增加标题编号,因此subfigure“看到”的标题增加计数器的值caption而不是使用的值\sidecaption。这意味着必须\sidecaption{...}subfigure环境之后。通过此更改,您的 MWE 给出了预期结果:

在此处输入图片描述

编辑: 在此更改中,您需要考虑,它\sidecaption{...}在包中定义sidenotes,但遗憾的是没有选择其相对于浮动内容的位置的选项。它仅允许手动移动标题位置。如上图所示,可以利用此功能\sidecaption[][-6em]{...}

\documentclass[a4paper,11pt]{scrbook}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{hyperref}

\usepackage{geometry}
\geometry{a4paper, top=10mm, left=33mm, right=46mm, bottom=46mm, headsep=\baselineskip,
          marginparwidth=43mm, marginparsep=1em}
% ********************************************************************
% captions, taking use of the margins
% ********************************************************************
\usepackage{ragged2e}
\usepackage{sidenotes}
\DeclareCaptionStyle{stdstyle}{
    format=hang,                 % caption hangs behind label
    justification=justified,     % caption is a normal paragraph
    singlelinecheck=false,       % always left-align caption
    labelsep=quad,               % quad separator behind label
    labelfont=sc,                % label in scshape
    font=footnotesize            % all in small font size
}
\DeclareCaptionJustification{outerragged}{\ifthispageodd{\RaggedRight}{\RaggedLeft}}
\DeclareCaptionStyle{sidestyle}{
    format=plain, %indention=2em, % whole line for caption, with indent after first
    justification=outerragged,    % caption is a normal paragraph
    singlelinecheck=false,        % always left-align caption
    labelsep=newline,             % quad separator behind label
    labelfont=sc,                 % label in scshape
    font=footnotesize             % all in small font size
}
\DeclareCaptionStyle{marginfigure}{
    style = sidestyle,
    labelsep=quad
}
\DeclareCaptionStyle{widetable}{style = stdstyle}
\DeclareCaptionStyle{widefigure}{style = stdstyle}
\DeclareCaptionStyle{sidecaption}{
    style = sidestyle,
    format=plain,
    labelsep=newline
}
\usepackage[style = stdstyle]{caption}
\usepackage[
    format=hang,
    justification=raggedright,
    labelfont=sc
]{subcaption}

\begin{document}
\chapter{for the numbers}
\begin{figure}[ht]
    \sidecaption{caption of figure 1
    \label{fig:1}
    }
    \includegraphics[width=.6\textwidth]{example-image-a}
\end{figure}
some text and we talk about \autoref{fig:1}

\begin{figure}[ht]
    \sidecaption{caption of figure 2. this one has two images but nor subfigures
    \label{fig:2}
    }
    \includegraphics[width=.45\textwidth]{example-image-a}\hfill%
    \includegraphics[width=.45\textwidth]{example-image-a}
\end{figure}
some text and we talk about \autoref{fig:2}

\begin{figure}[ht]
    \begin{subfigure}{0.45\textwidth}
        \includegraphics[width=\columnwidth]{example-image-a}%
        \caption{some text for 3a}
        \label{fig:3:a}
    \end{subfigure}\hfill%
    \begin{subfigure}{0.45\textwidth}
        \includegraphics[width=\columnwidth]{example-image-b}
        \caption{some text for 3b}
        \label{fig:3:b}
    \end{subfigure}
    \sidecaption[][-6em]% <-- addedoptions for manual adjustment of caption position
                        {caption of figure 3. this one has two images and uses subfigures with captions to address the subplots
    \label{fig:3}
    }
\end{figure}
some text and we talk about \autoref{fig:3} and then there is something important about \autoref{fig:3:a} and \autoref{fig:3:b} but why does this latter one increase the figure counter?

\begin{figure}[ht]
    \sidecaption{caption of figure 4
    \label{fig:4}
    }
    \includegraphics[width=.6\textwidth]{example-image-a}
\end{figure}
some text and we talk about \autoref{fig:4} but hey it's Figure 1.5 now...
\end{document}

答案2

正如 Zarko 所解释的那样,subfigure环境会增加figure计数器。一个丑陋的黑客建议是每次调用子图时手动减少计数器,方法是\addtocounter{figure}{-1}在代码中添加。这必须完成之内调用第一个用于图形编号和引用的工作figure之前的环境。subfigure

这样,您sidecaption仍将与图形顶部对齐,而无需手动移动每个图形。但我不确定弄乱计数器是否会产生任何其他严重问题...

\documentclass[a4paper,11pt]{scrbook}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{hyperref}

\usepackage{geometry}
\geometry{a4paper, top=10mm, left=33mm, right=46mm, bottom=46mm, headsep=\baselineskip, 
          marginparwidth=43mm, marginparsep=1em}

% ********************************************************************
% captions, taking use of the margins
% ********************************************************************
\usepackage{ragged2e}
\usepackage{sidenotes}
\DeclareCaptionStyle{stdstyle}{
    format=hang,                 % caption hangs behind label
    justification=justified,     % caption is a normal paragraph
    singlelinecheck=false,       % always left-align caption
    labelsep=quad,               % quad separator behind label
    labelfont=sc,                % label in scshape
    font=footnotesize            % all in small font size
}
\DeclareCaptionJustification{outerragged}{\ifthispageodd{\RaggedRight}{\RaggedLeft}}
\DeclareCaptionStyle{sidestyle}{
    format=plain, %indention=2em, % whole line for caption, with indent after first
    justification=outerragged,    % caption is a normal paragraph
    singlelinecheck=false,        % always left-align caption
    labelsep=newline,             % quad separator behind label
    labelfont=sc,                 % label in scshape
    font=footnotesize             % all in small font size
}
\DeclareCaptionStyle{marginfigure}{
    style = sidestyle,
    labelsep=quad
}
\DeclareCaptionStyle{widetable}{style = stdstyle}
\DeclareCaptionStyle{widefigure}{style = stdstyle}
\DeclareCaptionStyle{sidecaption}{
    style = sidestyle,
    format=plain,
    labelsep=newline
}
\usepackage[style = stdstyle]{caption}
\usepackage[
    format=hang,
    justification=raggedright,
    labelfont=sc
]{subcaption}

\begin{document}
\chapter{for the numbers}
\begin{figure}
    \sidecaption{caption of figure 1
    \label{fig:1}
    }
    \includegraphics[width=.6\textwidth]{example-image-a}
\end{figure}
some text and we talk about \autoref{fig:1}

\begin{figure}
    \sidecaption{caption of figure 2. this one has two images but nor subfigures
    \label{fig:2}
    }
    \includegraphics[width=.5\textwidth]{example-image-a}%
    \includegraphics[width=.5\textwidth]{example-image-a}
\end{figure}
some text and we talk about \autoref{fig:2}

\begin{figure}
    \sidecaption{caption of figure 3. this one has two images and uses subfigures with captions to address the subplots
    \label{fig:3}
    }
\addtocounter{figure}{-1}
    \begin{subfigure}{0.5\textwidth}
        \includegraphics[width=\columnwidth]{example-image-a}%
        \caption{some text for 3a}
        \label{fig:3:a}
    \end{subfigure}%
    \begin{subfigure}{0.5\textwidth}
        \includegraphics[width=\columnwidth]{example-image-b}
        \caption{some text for 3b}
        \label{fig:3:b}
    \end{subfigure}
\end{figure}
some text and we talk about \autoref{fig:3} and then there is something important about \autoref{fig:3:a} and \autoref{fig:3:b} but why does this latter one increase the figure counter?

\begin{figure}
    \sidecaption{caption of figure 4
    \label{fig:4}
    }
    \includegraphics[width=.6\textwidth]{example-image-a}
\end{figure}
some text and we talk about \autoref{fig:4} but hey it's Figure 1.5 now...

\end{document}

相关内容