使用 subfig 包时,\subref
我偶尔会遇到水平盒过满的情况。下面提供了 MWE,并向我发出以下警告:
段落第 16-17 行的 \hbox 过满(宽 7.1673pt)
有人知道如何解决这个问题吗?
\documentclass{report}
\usepackage[caption=false,subrefformat=parens,labelformat=parens]{subfig}
\begin{document}
\setcounter{chapter}{10}
\chapter{Chapter title}
\begin{figure}[h]
\centering
\subfloat[Subcaption.]{\rule{100pt}{50pt}\label{sfig:sfig1}}
\caption{Caption.}
\label{fig:Fig1}
\end{figure}
sample text sample text sample text sample text sample text saa Figure~\subref*{sfig:sfig1} sample text sample text sample text sample text
\end{document}
答案1
通过使用,Figure~\subref*{sfig:sfig1}
唯一可能的断行点是将“Figure”连字符化或在整个表达式后断行。使用默认设置,LaTeX 不会通过连字符“Figure”来断行,因为这样行会太短。如果使用 使空格稍微有弹性\emergencystretch=.5em
,新的断行将连字符“Figure”。
当然,这可能会导致空格从印刷角度来看比预期的要大。在这种情况下,重新措辞句子可以避免这个问题。
\documentclass{report}
\usepackage[caption=false,subrefformat=parens,labelformat=parens]{subfig}
\emergencystretch=.5em
\begin{document}
\setcounter{chapter}{10}
\chapter{Chapter title}
\begin{figure}[h]
\centering
\subfloat[Subcaption.]{\rule{100pt}{50pt}\label{sfig:sfig1}}
\caption{Caption.}
\label{fig:Fig1}
\end{figure}
sample text sample text sample text sample text sample text saa Figure~\subref*{sfig:sfig1} sample text sample text sample text sample text
\end{document}
一个小建议:使用该cleveref
包,无需手动编写Figure~
:
\documentclass{report}
\usepackage[caption=false,subrefformat=simple,labelformat=simple]{subfig}
\usepackage[capitalise,noabbrev]{cleveref}
\renewcommand{\thesubfigure}{(\alph{subfigure})}
\emergencystretch=.5em
\begin{document}
\setcounter{chapter}{10}
\chapter{Chapter title}
\begin{figure}[h]
\centering
\subfloat[Subcaption.]{\rule{100pt}{50pt}\label{sfig:sfig1}}
\caption{Caption.}
\label{fig:Fig1}
\end{figure}
sample text sample text sample text sample text sample text saa Figure~\subref*{sfig:sfig1} sample text sample text sample text sample text
sample text sample text sample text sample text sample text saa \cref{sfig:sfig1} sample text sample text sample text sample text
\end{document}