1

When using \subref from the subfig package I occasionally encounter an overfull hbox. A MWE is provided below and gives me the following warning:

Overfull \hbox (7.1673pt too wide) in paragraph at lines 16--17

The margin is indeed violated: Margin violation

Does anyone have an idea on how to fix this?

\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}
  • Off-topic: with the cleveref package you could automatically insert Figure~ – user36296 May 8 '18 at 16:39
  • 1
    The comparison with \ref is not fair . If one changes saa to same, to make both lines the same length, "Figure" is also hyphenated for \subref. The other way round, I can provoke an overfull box with \ref if I change the chapter counter to 100. – user36296 May 8 '18 at 16:42
  • 1
    rephrase sentence ... – Zarko May 8 '18 at 16:51
  • see tex.stackexchange.com/q/168480/36296 how to circumvent the overfull box. For example \emergencystretch=.5em – user36296 May 8 '18 at 16:52
1

By using Figure~\subref*{sfig:sfig1} the only possible breaking points are to hyphenate "Figure" or to break after the whole expression. With the default settings LaTeX does not do the linebreak by hyphenating "Figure" because then the line would be underful. If you make the spaces a bit stretchier by using \emergencystretch=.5em, the new linebreak will hyphenate "Figure".

Of course this might result in spaces which are larger than desired from a typographical point of few. In this case rephrasing the sentence can avoid the problem.

\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}

enter image description here


A small suggestion: With the cleveref package it is not necessary to manually write 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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.