我使用singlelinecheck=true
该caption
包将小标题居中。但是,我还希望能够将单行标题左对齐或右对齐。通过以下方法可以将它们左对齐
\captionsetup{singlelinecheck=false}%
正如我在图 1 中所做的那样。如果标题更长,在这种情况下一切仍然有效。
如何使图 2 的单行标题右对齐(但前提是它是单行标题)?
代码:
\documentclass{article}
\usepackage{showframe}
\usepackage{graphicx}
\usepackage{caption}
\captionsetup{%
format=plain,%
textformat=period,
justification=RaggedRight,
singlelinecheck=true,
}%
\begin{document}
\noindent
\begin{minipage}{0.5\linewidth}
\centering
\includegraphics[width=0.95\linewidth]{example-image}%
\captionsetup{width=0.95\linewidth}%
\captionsetup{singlelinecheck=false}%
\captionof{figure}{Caption on Left}%
\end{minipage}%
\begin{minipage}{0.5\linewidth}
\centering
\includegraphics[width=0.95\linewidth]{example-image}%
\captionsetup{width=0.95\linewidth}%
\captionof{figure}{Caption on Right}%
\end{minipage}%
\medskip\noindent
\begin{minipage}[t]{0.5\linewidth}
\centering
\includegraphics[width=0.95\linewidth]{example-image}%
\captionsetup{width=0.95\linewidth}%
\captionof{figure}{Caption Centered}%
\end{minipage}%
\begin{minipage}[t]{0.5\linewidth}
\centering
\includegraphics[width=0.95\linewidth]{example-image}%
\captionsetup{width=0.95\linewidth}%
\captionof{figure}{Caption taking up full width}%
\end{minipage}%
\end{document}
答案1
您可以使用可选参数\DeclareCaptionStyle
来定义单行标题的特殊行为,以用于自己的标题样式:
\documentclass{article}
\usepackage{showframe}
\usepackage{graphicx}
\usepackage{caption}
\DeclareCaptionStyle{mystyle}
{format=plain,%
textformat=period,
justification=RaggedRight,
singlelinecheck=true,
}% all captions are left aligned
\DeclareCaptionStyle{singlelinecentered}
[justification=Centering]% centered if single line and no `singlelinecheck=false`
{style=mystyle}% other captions are left aligned
\DeclareCaptionStyle{singlelineraggedleft}
[justification=RaggedLeft]% right aligned if single line and no `singlelinecheck=false`
{style=mystyle}% other captions are left aligned
\captionsetup{style=singlelineraggedleft}
\begin{document}
\noindent
\begin{minipage}{0.5\linewidth}
\centering
\includegraphics[width=0.95\linewidth]{example-image}%
\captionsetup{width=0.95\linewidth}%
\captionsetup{singlelinecheck=false}%
\captionof{figure}{Caption on Left}%
\end{minipage}%
\begin{minipage}{0.5\linewidth}
\centering
\includegraphics[width=0.95\linewidth]{example-image}%
\captionsetup{width=0.95\linewidth}%
\captionof{figure}{Caption on Right}%
\end{minipage}%
\medskip\noindent
\begin{minipage}[t]{0.5\linewidth}
\centering
\includegraphics[width=0.95\linewidth]{example-image}%
\captionsetup{width=0.95\linewidth,style=singlelinecentered}%
\captionof{figure}{Caption Centered}%
\end{minipage}%
\begin{minipage}[t]{0.5\linewidth}
\centering
\includegraphics[width=0.95\linewidth]{example-image}%
\captionsetup{width=0.95\linewidth}%
\captionof{figure}{Caption taking up full width}%
\end{minipage}%
\end{document}
答案2
一个简单的解决方案floatrow
:
\documentclass{article}
\usepackage{showframe}
\usepackage{graphicx}
\usepackage{floatrow, caption}
\captionsetup{%
format=plain,%
textformat=period,
justification=RaggedRight,
singlelinecheck=true,
}%
\renewcommand\ShowFrameLinethickness{0.3pt}
\begin{document}
\begin{figure}[!htb]
\centering\floatsetup{floatrowsep=qquad}
\captionsetup{font=small}
\begin{floatrow}\captionsetup{singlelinecheck=false}
\ffigbox[\FBwidth]{%
\includegraphics[width=0.4\textwidth]{example-image}}%
{\caption{Caption on Left}}%
%%%
\ffigbox[\FBwidth]{%
\includegraphics[width=0.4\textwidth]{example-image}}%
{\captionsetup{justification=raggedleft}\caption[]{Caption on Right}}%
\end{floatrow}%
\par
\vspace{3ex}
%%%%%%
\begin{floatrow}
\ffigbox[\FBwidth]{%
\includegraphics[width=0.4\textwidth]{example-image}}%
{ \caption{Caption Centered}}%
%%%
\ffigbox[\FBwidth]{%
\includegraphics[width=0.4\textwidth]{example-image}}%
{\captionsetup{format=hang}\caption[]{Long caption taking up full width}}%
\end{floatrow}%
\end{figure}
\end{document}