我正在使用 KOMA-Script 类scrreprt
和ragged2e
包来实现文档文本的右侧不规则。我仍然想保留段落缩进(并且没有段落间距,即 parskip=0),所以我设置了\RaggedRightParindent{2em}
,但这似乎也会在加载 subcaption 包时影响我的浮动字幕。
例子:
\documentclass{scrreprt}
\usepackage {mwe}%
\usepackage[document]{ragged2e} % for creating ragged right edge etc
\setlength{\RaggedRightParindent}{2em}% sets the indent size of the first line
\usepackage{subcaption}% for creating figures in figures
\setcapindent{0em}
\begin{document}
\section{title}
\lipsum[11]
\begin{figure}[tbh]
\setcapindent{0em}
\centering
\includegraphics[width=0.4\linewidth]{example-image}
\caption{The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. }
\end{figure}
\end{document}
生成结果:
我怎样才能摆脱这个压痕?(如果可能的话我仍然想保留这些包裹......)
答案1
您可以通过在序言中添加以下三行代码将所有环境的值设置\RaggedRightParindent
为零:figure
table
\usepackage{etoolbox}
\AtBeginEnvironment{figure}{\setlength{\RaggedRightParindent}{0em}}
\AtBeginEnvironment{table}{\setlength{\RaggedRightParindent}{0em}}
完整的 MWE:
\documentclass{scrreprt}
\usepackage {mwe}
\usepackage[document]{ragged2e}
\setlength{\RaggedRightParindent}{2em}
\usepackage{subcaption}
\setcapindent{0em}
\usepackage{etoolbox}
\AtBeginEnvironment{figure}{\setlength{\RaggedRightParindent}{0em}}
\AtBeginEnvironment{table}{\setlength{\RaggedRightParindent}{0em}}
\begin{document}
\section{title}
\lipsum[11]
\begin{figure}[h!]
\centering
\includegraphics[width=0.4\linewidth]{example-image}
\caption{The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.}
\end{figure}
\begin{table}[h!]
\centering
\begin{tabular}{ccc}
\hline
u & v & w\\
\hline
\end{tabular}
\caption{The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.}
\end{table}
\lipsum[2-3]
\结束{文档}
答案2
定义标题样式:
\documentclass{scrreprt}
\usepackage[document]{ragged2e} % for creating ragged right edge etc
\usepackage{caption}% for creating figures in figures
\setlength{\RaggedRightParindent}{2em}% sets the indent size of the first line
\DeclareCaptionFormat{komaflush}{\noindent\hspace{-\RaggedRightParindent}#1#2#3\par}
\captionsetup{format=komaflush}
\begin{document}
\section{title}
\lipsum[11-12]
\begin{figure}[tbh]
\centering
\includegraphics[width=0.4\linewidth]{example-image}
\caption{The quick brown fox jumps over the lazy dog. The quick brown
fox jumps over the lazy dog. The quick brown fox jumps over the lazy
dog. The quick brown fox jumps over the lazy dog.}
\end{figure}
\end{document}