\captionsetup 用于图片* 和 表格*

\captionsetup 用于图片* 和 表格*

对于我正在写的一本书,我将标题设置在页边距中,效果很好。但我对figure和环境的区别有一个问题。第一个应该在顶部有一些负垂直空间(标题格式),第二个应该有一个正垂直空间(标题格式)。figure*\captionsetupsidenotesidenotebelow

那么我如何使用和(当然也包括和)\captionsetup的不同配置?figurefigure*tabletable*

\documentclass[twoside=semi]{scrreprt}

\usepackage[a4paper,left=24.8mm,top=27.4mm,headsep=2\baselineskip,textwidth=107mm,marginparsep=8.2mm,marginparwidth=49.4mm,%
    textheight=49\baselineskip,headheight=\baselineskip]{geometry}%
\usepackage{caption,subcaption}
\usepackage{scrlayer-notecolumn}
\usepackage{xparse,etoolbox}
\usepackage{graphicx}

\RedeclareNoteColumn[position=\oddsidemargin+1in+\textwidth+\marginparsep,width=\marginparwidth,font=\footnotesize]{marginpar}
\DeclareDocumentCommand{\xmarginnote}{O{0pt} +m}{%
    \makenote[marginpar]{\hbox{}\vskip#1\setlength{\parindent}{0.5pc}\setlength{\parskip}{0pt}\noindent #2}%
}
\AtEndPreamble{%
    \DeclareDocumentEnvironment{figure*}{o}{\begin{figure}[#1]\begin{addmargin}[0pt]{-\dimexpr\marginparwidth+\marginparsep}}
        {\end{addmargin}\end{figure}}
    \DeclareDocumentEnvironment{table*}{o}{\begin{table}[#1]\begin{addmargin}[0pt]{-\dimexpr\marginparwidth+\marginparsep}}
        {\end{addmargin}\end{table}}
}%
\captionsetup{compatibility=false}%
\DeclareCaptionFormat{sidenote}{\protect\xmarginnote[-\baselineskip]{#1#2#3}}%
\DeclareCaptionFormat{sidenotebelow}{\protect\xmarginnote[1.5\baselineskip]{#1#2#3}}%
\DeclareCaptionStyle{sidecap}{parskip=0pt,skip=0pt,position=below,labelfont={footnotesize,bf},font=footnotesize,%
    singlelinecheck=off}%
\DeclareCaptionStyle{subsidecap}{format=plain,parskip=0pt,skip=0pt,position=below,labelfont={scriptsize,bf},labelformat=parens,labelsep=space,%
    font=scriptsize,justification=centering,singlelinecheck=off}%
\captionsetup[figure]{style=sidecap,format=sidenote}\captionsetup[table]{style=sidecap,format=sidenote}%
% here it doesn't work
\captionsetup[figure*]{style=sidecap,format=sidenotebelow}\captionsetup[table*]{style=sidecap,format=sidenotebelow}%
\captionsetup[sub]{style=subsidecap}%

\begin{document}
    \begin{figure}[h]
        \centering
        \includegraphics[width=\textwidth]{example-image-A.pdf}
        \caption{Working caption}
    \end{figure}
    \begin{figure*}[h]
        \centering
        \includegraphics[width=\dimexpr\textwidth+\marginparwidth]{example-image-A.pdf}
        \caption{Caption to high}
    \end{figure*}
\end{document}

答案1

正如 Schweinebacke 在评论中指出的那样,有一个我不知道的简单解决方案。那就是将其移入\captionsetup环境定义中。

这是更正后的代码:

\documentclass[twoside=semi]{scrreprt}

\usepackage[a4paper,left=24.8mm,top=27.4mm,headsep=2\baselineskip,textwidth=107mm,marginparsep=8.2mm,marginparwidth=49.4mm,%
    textheight=49\baselineskip,headheight=\baselineskip]{geometry}%
\usepackage{caption,subcaption}
\usepackage{scrlayer-notecolumn}
\usepackage{xparse,etoolbox}
\usepackage{graphicx}

\RedeclareNoteColumn[position=\oddsidemargin+1in+\textwidth+\marginparsep,width=\marginparwidth,font=\footnotesize]{marginpar}
\DeclareDocumentCommand{\xmarginnote}{O{0pt} +m}{%
    \makenote[marginpar]{\hbox{}\vskip#1\setlength{\parindent}{0.5pc}\setlength{\parskip}{0pt}\noindent #2}%
}
\AtEndPreamble{%
    \DeclareDocumentEnvironment{figure*}{o}{\begin{figure}[#1]%
            \captionsetup{style=sidecap,format=sidenotebelow}\begin{addmargin}[0pt]{-\dimexpr\marginparwidth+\marginparsep}}
        {\end{addmargin}\end{figure}}
    \DeclareDocumentEnvironment{table*}{o}{\begin{table}[#1]%
            \captionsetup{style=sidecap,format=sidenotebelow}\begin{addmargin}[0pt]{-\dimexpr\marginparwidth+\marginparsep}}
        {\end{addmargin}\end{table}}
}%
\captionsetup{compatibility=false}%
\DeclareCaptionFormat{sidenote}{\protect\xmarginnote[-\baselineskip]{#1#2#3}}%
\DeclareCaptionFormat{sidenotebelow}{\protect\xmarginnote[1.5\baselineskip]{#1#2#3}}%
\DeclareCaptionStyle{sidecap}{parskip=0pt,skip=0pt,position=below,labelfont={footnotesize,bf},font=footnotesize,%
    singlelinecheck=off}%
\DeclareCaptionStyle{subsidecap}{format=plain,parskip=0pt,skip=0pt,position=below,labelfont={scriptsize,bf},labelformat=parens,labelsep=space,%
    font=scriptsize,justification=centering,singlelinecheck=off}%
\captionsetup[figure]{style=sidecap,format=sidenote}\captionsetup[table]{style=sidecap,format=sidenote}%
\captionsetup[sub]{style=subsidecap}%

\begin{document}
    \begin{figure}[h]
        \centering
        \includegraphics[width=\textwidth]{example-image-a}
        \caption{Working caption}
    \end{figure}
    \begin{figure*}[h]
        \centering
        \includegraphics[width=\dimexpr\textwidth+\marginparwidth]{example-image-a}
        \caption{Caption to high}
    \end{figure*}
\end{document}

相关内容