考虑一下这个 MWE
\documentclass[12pt,a4paper]{article}
\usepackage[showframe]{geometry}
\usepackage[demo]{graphicx}
\usepackage{lipsum}
\usepackage{floatrow}
\usepackage{caption}
\captionsetup{labelsep=newline,
justification=raggedleft,
singlelinecheck=false,
labelfont=bf,
font=small}
\begin{document}
\lipsum[2]
\begin{figure}[H]
\raggedleft
\begin{minipage}{20cm}
\floatbox[{\capbeside\thisfloatsetup{capbesideposition={left,center},capbesidewidth=4cm}}]{figure}[\FBwidth]
{\caption{Some caption that spans more than a line and some additional text}}
{\includegraphics[width=5cm]{name}}
\end{minipage}
\end{figure}
\end{document}
这就是我得到的
从代码中的命令可以看出\raggedleft
,我期望的结果更像这样
我该如何实现这一点?另外,虽然此代码与article
类配合得很好,但如果我切换到scrartcl
编译过程,除非我删除包选项,否则会遇到一些麻烦labelsep=newline
。caption
我该如何解决这个问题?
答案1
为了将图像与右边距对齐,您可能需要使用foatrow
命令\floatsetup[figure]{margins=raggedleft}
。您可以将其放入前导码中以全局方式使用它,也可以在本地使用它,如以下 MWE 所示:
\documentclass[12pt,a4paper]{article}
\usepackage[showframe]{geometry}
\usepackage[demo]{graphicx}
\usepackage{lipsum}
\usepackage{floatrow}
\usepackage{caption}
\captionsetup{labelsep=newline,
justification=raggedleft,
singlelinecheck=false,
labelfont=bf,
font=small}
\begin{document}
\lipsum[2]
{\floatsetup[figure]{margins=raggedleft}
\begin{figure}[H]
\floatbox[{\capbeside\thisfloatsetup{capbesideposition={left,center},capbesidewidth=4cm}}]{figure}[\FBwidth]
{\caption{Some caption that spans more than a line and some additional text}}
{\includegraphics[width=5cm]{name}}
\end{figure}}
\begin{figure}[H]
\floatbox[{\capbeside\thisfloatsetup{capbesideposition={left,center},capbesidewidth=4cm}}]{figure}[\FBwidth]
{\caption{Some caption that spans more than a line and some additional text}}
{\includegraphics[width=5cm]{name}}
\end{figure}
\end{document}
关于从 切换到article
,scrartcl
您将收到以下错误消息:
包
caption
错误:该选项labelsep=newline
不适用于\setcaphanging
(默认设置)。
通过查看caption
手册可以发现和format
的默认值有所不同: article
scrartcl
通过添加format=plain
命令\captionsetup
,我们可以使代码scrartcl
也可供编译。不过,我建议看一下 KOMA 脚本文档,因为这些文档类已经提供了自定义字幕外观的方法。
答案2
仅作为补充@leandris 的回答对于 KOMA-Script 部分:KOMA-Script 类提供环境captionbeside
和captionofbeside
。
\documentclass[12pt,a4paper]{scrartcl}
\usepackage{showframe}
\usepackage{graphicx}
\usepackage{lipsum}
\usepackage{float}% if position H is really needed
\KOMAoption{captions}{nooneline,centeredbeside,leftbeside}
\setcapindent*{0pt}
\setcaptionalignment{r}
\renewcommand\captionformat{}
\addtokomafont{caption}{\small}
\addtokomafont{captionlabel}{\bfseries}
\begin{document}
\lipsum[1]
\begin{figure}[H]
\begin{captionbeside}
{Some caption that spans more than a line and some additional text}%
\includegraphics[width=5cm]{example-image}
\end{captionbeside}
\end{figure}
\lipsum[2]
\begin{figure}[H]
\begin{captionbeside}
{Some caption that spans more than a line and some additional text}%
[l]% caption position
[\dimexpr9cm+10pt\relax]% width of caption and figure
[\dimexpr\linewidth-9cm-10pt\relax]% offset
\includegraphics[width=5cm]{example-image}
\end{captionbeside}
\end{figure}
\end{document}
结果:
警告:软件包floatrow
破坏环境captionbeside
。