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.

Compiling the following document using xelatex results in unwanted vertical space above the wrapfigure caption. Removing either the inclusion of the polyglossia package or \centercaption usage eliminates the problem. However, this is not a viable solution.

\documentclass{article}
\usepackage{polyglossia}
\usepackage{wrapfig}
\usepackage{caption}
\usepackage{lipsum}

\newcommand\centercaption{%
  \captionsetup{format=plain,labelsep=newline,justification=centering}}

\begin{document}

\begin{wrapfigure}{r}{2cm}
  \rule{2cm}{2cm}
  \centercaption
  \caption{test}
\end{wrapfigure}

\lipsum[1]

\end{document}

Above document produces

Image 1

Without polyglossia the spacing is correct:

Image 2

Is there any other way to eliminate the excessive vertical space above the caption? Note that setting the number of lines to be consumed by wrapfigure doesn't have any effect.

share|improve this question
add comment

2 Answers

up vote 7 down vote accepted

I'm not sure why polyglossia adds extra space between the graphic and caption, maybe a bug. You can just use \centercaption at the beginning of the wrapfigure environment to prevent the extra space it produces.

BTW, wrapfig package's wrapfigure environment has several optional parameters. The first one is the number of lines it vertically occupies. For your example:

\begin{wrapfigure}[8]{r}{2cm}
  \centercaption
  \rule{2cm}{2cm}
  \caption{test}
\end{wrapfigure}

See the manual of wrapfig for more options and decriptions.

share|improve this answer
    
Using \centercaption at the beginning of the wrapfigure works indeed. Though the solution is not ideal, since it requires to update all \centercaption usages in a document which was previously compiled using pdflatex. –  caustic May 10 '11 at 18:05
add comment

The extra vertical space that you see is because of the redefinition of \@esphack macro in package fixltx2e (so obviously user Leo Liu is wrong in saying that this is a polyglossia bug, polyglossia loads fontspec and fontspec loads fixltx2e). The original definition of \@esphack in latex.ltx is:

\def\@esphack{%
  \relax
  \ifhmode
    \spacefactor\@savsf
    \ifdim\@savsk>\z@
      \ignorespaces
    \fi
  \fi}

And the redefinition of \@esphack in fixltx2e is:

\def\@esphack{%
  \relax
  \ifhmode
    \spacefactor\@savsf
    \ifdim\@savsk>\z@
      \nobreak \hskip\z@skip  % <------
      \ignorespaces
    \fi
  \fi}

So as you can see clearly \nobreak \hskip\z@skip causes that extra vertical space. The fixltx2e package documentation states that this was suggested by Donald Arseneau to fix the bug "No hyphenation in first word after float environment" (page 18).

Update: The actual bug report can be found here.

share|improve this answer
add comment

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.