captionsetup 很好地重新定义了我的边距标题,但我希望其他标题为默认样式

captionsetup 很好地重新定义了我的边距标题,但我希望其他标题为默认样式

我正在编写一份文档,其中小图和辅助图放在宽边距中,而文本中则有较大的图。我使用 captions 包并使用以下代码重新定义标题

\captionsetup{
justification=raggedright
font=small}

并将其用于我的边距图标题,效果很好。由于边距标题的每一行上的字数太少,当 Latex 拉伸标题以覆盖整个边距宽度时,它看起来很丑陋,因此出现了 raggedright。

现在,问题是 \captionsetup 也重新定义了我的“正常”标题,因此它们也变得参差不齐,而这是我不想要的。

因此,我的文件的元素包括:

\usepackage{captions}

\addtolength{\evensidemargin}{1.5cm} 
\addtolength{\textwidth}{-1.5cm}
\addtolength{\marginparwidth}{20pt}
\addtolength{\marginparsep}{10pt}

\captionsetup{
justification=raggedright
font=small}

\begin{document}

text text text ...

\begin{figure}
\begin{center}    
\includegraphics{figure1}
\caption{figure 1 text, which I don't want to have a raggedright justification, since it looks quite good without it due to the many words that I can fit into one line in this type of caption.}    
\end{center}
\end{figure}

some 

more 

text 

about 

something

\marginpar{\includegraphics[width=\marginparwidth]{figure2}
\captionof{figure}{Here for figure 2, the caption will look odd when few words are stretched across the marginparwidth}}

\end{document}

因此,我希望 \captionof 生成的标题与 caption 在图形环境中使用时生成的标题不同。感谢您提供的任何提示。我查看了 tufte 类,但在我看来,该类中的所有标题都有不规则的右对齐。

答案1

您可以使用\captionsetup[<name>]{...} ... \captionsetup{options=<name>}定义和执行自定义命令或环境的选项,例如:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption}

\addtolength{\evensidemargin}{1.5cm} 
\addtolength{\textwidth}{-1.5cm}
\addtolength{\marginparwidth}{20pt}
\addtolength{\marginparsep}{10pt}

\captionsetup[marginfigure]{
justification=raggedright,
font=small}

\newcommand\marginfigure[1]{%
  \marginpar{%
    \captionsetup{type=figure,options=marginfigure}%
    #1}}

\begin{document}

text text text ...

\begin{figure}
\centering
\includegraphics{figure1}
\caption{figure 1 text, which I don't want to have a raggedright justification, since it looks quite good without it due to the many words that I can fit into one line in this type of caption.}    
\end{figure}

some 

more 

text 

about 

something

\marginfigure{\includegraphics[width=\marginparwidth]{figure2}
\caption{Here for figure 2, the caption will look odd when few words are stretched across the marginparwidth}}

\end{document}

相关内容