Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm experiencing a strange problem with memoir subfigure captions together with hyperref. Below is a working example:

\documentclass{memoir}

\usepackage{hyperref}
\newsubfloat{figure}

\begin{document}
\begin{figure}[tb]
  \rule{\textwidth}{4ex}
  \subcaption{}
\end{figure}
\end{document}

This produces the following result:

enter image description here

If I remove the hyperref package and recompile, the gap disappears: enter image description here

Anyone have any idea why this is happening, and how to solve it?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

The solution is to place % behind the \rule line:

\documentclass{memoir}

\usepackage{hyperref}
\newsubfloat{figure}

\begin{document}
\begin{figure}[tb]
  \rule{\textwidth}{4ex}%
  \subcaption{}
\end{figure}
\end{document}

I guess that \subcaption uses \unskip to remove the space cause by the line break, but hyperref adds some internal code which stops \unskip to go that far back. Because the \rule is \textwidth long the space is creating a new line if not removed. Alternatively add a manual \unskip before \subcaption if you have a more complicated content than \rule.

In general it is a good idea to place a % after } and { at the end of a source line. Such spurious spaces are appearing often if you are not careful.

share|improve this answer
    
In my document where this problem occurs (it's only in one subfigure - in all other subfigures there is no gap), I had to use both \unskip and place a % after the figure code. Anyhow, the gap is now gone. Thanks. –  gablin Oct 18 '11 at 13:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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