平均能量损失

平均能量损失

我正在使用\sidecaption来自sidenotes包裹使用 KOMA-Script 类。我想格式化(形状、大小、颜色)标题文本及其标签。

根据KOMA 文档(第 3 章,第 118 页),应该这样处理:

\setkomafont{captionlabel}{<layout>}

但是,它不起作用。有没有什么办法可以改变它?


平均能量损失

在此处输入图片描述

(标签图1:应以粗体和小写字母显示)

\documentclass{scrartcl}
    \usepackage{lipsum}
    \usepackage{graphicx}
    \usepackage{sidenotes}

    \setkomafont{captionlabel}{\scshape\bfseries}

\begin{document}
    \lipsum
    \begin{figure}[htb]
        \sidecaption[][-2\baselineskip]{This is my caption}
        \includegraphics[width=\textwidth, height=20em]{example-image-a}
    \end{figure}
    \lipsum
\end{document}

答案1

sidenotes包使用 packagecaption来定义一个标题样式sidecaption。您可以重新声明此样式:

\documentclass{scrartcl}
\usepackage[T1]{fontenc}% <- added
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{sidenotes}

\DeclareCaptionStyle{sidecaption}{labelfont={sc,bf},justification=raggedright}
\begin{document}
    \lipsum
    \begin{figure}[htb]
        \sidecaption[][-2\baselineskip]{This is my caption}
        \includegraphics[width=\textwidth, height=20em]{example-image-a}
    \end{figure}
    \lipsum
\end{document}

在此处输入图片描述


或者使用 KOMA-Script 环境captionbeside

\documentclass{scrartcl}
\usepackage[T1]{fontenc}
\usepackage{lipsum}
\usepackage{graphicx}

\setkomafont{captionlabel}{\scshape\bfseries}

\usepackage{etoolbox}
\BeforeBeginEnvironment{captionbeside}{%
  \setcapindent*{0pt}%
  \setcaptionalignment{l}% needs KOMA-Script Version 3.25; workaround for older versions: \addtokomafont{caption}{\raggedright}%
}

\begin{document}
\lipsum
\begin{figure}[htb]
\begin{captionbeside}{This is my caption}
    [o]% caption on the outer document side
    [\dimexpr\textwidth+\marginparwidth+\marginparsep\relax]% enlarge the used width
    [0pt]*% align with the inner margin
  \includegraphics[width=\textwidth, height=20em]{example-image-a}
\end{captionbeside}
\end{figure}
\lipsum
\end{document}

在此处输入图片描述

或者使用选项captions=topbeside和凸起的图像:

\documentclass[%
  captions=topbeside% change the position of the sidecaption to the top baseline
]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage{lipsum}
\usepackage{graphicx}

\setkomafont{captionlabel}{\scshape\bfseries}

\usepackage{etoolbox}
\BeforeBeginEnvironment{captionbeside}{%
  \setcapindent*{0pt}%
  \setcaptionalignment{l}% needs KOMA-Script Version 3.25; workaround for older versions: \addtokomafont{caption}{\raggedright}%
}

\begin{document}
\lipsum
\begin{figure}[htb]
\begin{captionbeside}{This is my caption}
    [o]% caption on the outer document side
    [\dimexpr\textwidth+\marginparwidth+\marginparsep\relax]% enlarge the used width
    [0pt]*% align with the inner margin
  \raisebox
    {\dimexpr-\totalheight+\ht\strutbox\relax}
    {\includegraphics[width=\textwidth, height=20em]{example-image-a}}
\end{captionbeside}
\end{figure}
\lipsum
\end{document}

在此处输入图片描述

答案2

KOMA-Script 有自己的captionbeside环境(见手册第 121 页)。使用它\addkomafont可以根据需要更改标题的字体。

请参阅以下 MWE:

\documentclass{scrartcl}

\usepackage{lipsum}
\usepackage{graphicx}
%\usepackage{sidenotes}

\setkomafont{captionlabel}{\scshape\bfseries}


\begin{document}
\lipsum
\begin{figure}[htb]
\begin{captionbeside}{This is my caption}%
   [r]
  \includegraphics[width=.7\textwidth]{example-image-a}
\end{captionbeside}
\end{figure}

\lipsum
\end{document}

结果如下:

在此处输入图片描述

如果您想要使用,\sidecaption则必须使用包caption来影响标题的格式,因为包在内部sidenotes调用caption......

答案3

去完成埃塞克斯很棒的答案,我定义了以下两个环境margincaptionbottom并将margincaptiontop所有设置一起包装起来。

这些环境创造了内心参差不齐标题外边距文档的标题。标题分别位于底部或顶部。
请注意,该环境适用于单面和双面文档。

在此处输入图片描述


句法

\begin{margincaptionbottom}[Optional different caption for the LoT]{Caption to be displayed}
    <your picture here>
\end{margincaptionbottom}

(同上margincaptiontop


放在序言中的环境定义

\usepackage{etoolbox}
\usepackage{environ}

\makeatletter
\if@twoside%
   \newcommand{\raggedinner}{\ifthispageodd{\raggedright}{\raggedleft}}
\else%
   \newcommand{\raggedinner}{\raggedright}
\fi%
\makeatother

\BeforeBeginEnvironment{captionbeside}{\setcapindent*{0pt}\addtokomafont{caption}{\raggedinner}}
\KOMAoptions{captions=outerbeside}

\NewEnviron{margincaptionbottom}[2][]{%
    \KOMAoptions{captions=bottombeside}
    \begin{captionbeside}%
        [#1]
        {#2}%
        [o]%
        [\dimexpr\textwidth+\marginparwidth+\marginparsep\relax]%
        [0pt]*%
        \BODY
    \end{captionbeside}%
}

\NewEnviron{margincaptiontop}[2][]{%
    \KOMAoptions{captions=topbeside}
    \begin{captionbeside}%
        [#1]
        {#2}%
        [o]%
        [\dimexpr\textwidth+\marginparwidth+\marginparsep\relax]%
        [0pt]*%
        \raisebox{\dimexpr\ht\strutbox-\totalheight\relax}{\BODY}%
    \end{captionbeside}%
}

平均能量损失

\documentclass[two side]{scrartcl}
    %standard packages
    \usepackage{graphicx}
    \usepackage{lipsum}

    %Own definition of caption style
    \setkomafont{captionlabel}{\scshape\sffamily\small}
    \setkomafont{caption}{\normalfont\small}
    \renewcommand*{\captionformat}{\quad}

%%%% To be copied to define environments 'margincaptionbottom' and 'margincaptiontop'
    \usepackage{etoolbox}
    \usepackage{environ}

    \makeatletter
    \if@twoside%
       \newcommand{\raggedinner}{\ifthispageodd{\raggedright}{\raggedleft}}
    \else%
       \newcommand{\raggedinner}{\raggedright}
    \fi%
    \makeatother

    \BeforeBeginEnvironment{captionbeside}{\setcapindent*{0pt}\addtokomafont{caption}{\raggedinner}}
    \KOMAoptions{captions=outerbeside}

    \NewEnviron{margincaptionbottom}[2][]{%
        \KOMAoptions{captions=bottombeside}
        \begin{captionbeside}%
            [#1]
            {#2}%
            [o]%
            [\dimexpr\textwidth+\marginparwidth+\marginparsep\relax]%
            [0pt]*%
            \BODY
        \end{captionbeside}%
    }

    \NewEnviron{margincaptiontop}[2][]{%
        \KOMAoptions{captions=topbeside}
        \begin{captionbeside}%
            [#1]
            {#2}%
            [o]%
            [\dimexpr\textwidth+\marginparwidth+\marginparsep\relax]%
            [0pt]*%
            \raisebox{\dimexpr\ht\strutbox-\totalheight\relax}{\BODY}%
        \end{captionbeside}%
    }
%%%% end of definition
\title{MWE for \texttt{margincaptionbottom} and \texttt{margincaptiontop} environments}
\author{ebo}    
\begin{document}
    \maketitle
    \clearpage

    \section*{Bottom beside left}
    \lipsum[1]
    \begin{figure}[!h]
        \begin{margincaptionbottom}[Bottom left]{This is a bottom caption in the left margin}
        \includegraphics[width=\textwidth, height=210pt]{example-image-a}
        \end{margincaptionbottom}
    \end{figure}
    \lipsum[2]
    \clearpage

    \section*{Bottom beside right}
    \lipsum[1]
    \begin{figure}[!h]
        \begin{margincaptionbottom}[Bottom right]{This is a bottom caption in the right margin}
        \includegraphics[width=\textwidth, height=210pt]{example-image-a}
        \end{margincaptionbottom}
    \end{figure}
    \lipsum[2]
    \clearpage

    \section*{Top beside left}
        \lipsum[1]
        \begin{figure}[!h]
            \begin{margincaptiontop}[Top left]{This is a top caption in the left margin}
            \includegraphics[width=\textwidth, height=210pt]{example-image-a}
            \end{margincaptiontop}
        \end{figure}
        \lipsum[2]
        \clearpage  

    \section*{Top beside right}
        \lipsum[1]
        \begin{figure}[!h]
            \begin{margincaptiontop}[Top right]{This is a top caption in the right margin}
            \includegraphics[width=\textwidth, height=210pt]{example-image-a}
            \end{margincaptiontop}
        \end{figure}
        \lipsum[2]
        \clearpage

    \listoffigures
\end{document}

答案4

另一个解决方案是mcaption封装。

\documentclass{scrartcl}
\usepackage{blindtext}
\usepackage{graphicx}
\usepackage[top]{mcaption}
\usepackage{caption}

\addtokomafont{captionlabel}{\bfseries\scshape}
\addtokomafont{caption}{\itshape}
\setcapindent*{0em}

\begin{document}
\blindtext
\begin{figure}[htb]
\begin{margincap}
    \caption{This is my caption}
    \includegraphics[width=\textwidth, height=20em]{example-image-a}
\end{margincap}
\end{figure}
\blindtext
\end{document}

在此处输入图片描述

相关内容