8

This question arises from my attempt to answer vertical spacing on enumitem. Originally, I was able to answer the OP's question, but then the OP mentioned that the problem re-emerged if the hyperref package was used.

The following is a MWE:

\documentclass{article}
\usepackage{hyperref}
\begin{document}

\noindent
  Hello
  \fbox{%
    \begin{minipage}[t]{9cm}
      \begin{enumerate}
        \item the first item
        \item the second item
        \item the third item
      \end{enumerate}
    \end{minipage}}

\end{document}

Resulting in:

enter image description here

When expecting:

enter image description here

which is easily obtained from the MWE by commenting out the call to use hyperref.

After playing a bit with the contents hyperref, the problem seems to lie with how hyperref redefines how \item used in an enumerate environment. In particular, the macro \hyper@refstepcounter seems to be at the root of the problem since by redefining it as

\def\hyper@refstepcounter#1{\relax}

eliminates the unwanted extra vertical space.

The definition of \hyper@refstepcounter is

\def\hyper@refstepcounter#1{%
  \edef\This@name{#1}%
  \ifx\This@name\name@of@eq
    \@ifundefined{theHequation}{%
      \make@stripped@name{\theequation}%
      \let\theHequation\newname
    }{}%
  \fi
  \HyCnt@ProvideTheHCounter{#1}%
  \hyper@makecurrent{#1}%
  \ifmeasuring@
  \else
    \Hy@raisedlink{%
%-->
      \hyper@anchorstart{\@currentHref}\hyper@anchorend
    }%
  \fi
}   

If you comment our the line following %-->, the extra vertical spacing disappears.

The raised link seems to be the problem, is this a bug in terms of how it's essentially counteracting how minipage eliminates the effects of \addvspace? Or is there some trick that is a work around (other than commenting out this line)?

EDIT

One option for fixing this seems to be writing

\let\ifmeasuring@\iftrue    

(or is this less drastic)

\measuring@true

after calling hyperref package. But, I'm not really sure what the raised link is supposed to be achieving here. Am I possibly throwing out too much by doing this? Or might amsmath simply override this later---which seems unlikely because \measuring@false is only called from within a group.

A.Ellett
  • 50,533
  • You could wrap up the enumerate environment in a NoHyper environment. –  Jun 13 '13 at 07:13
  • Two needs fight with each other: the hyperref anchor has to be placed above the item number, so that a click on a hyperlink will show the item and not place the view below it. On the other hand, this introduces an element in the vertical list (the minipage) that sets a different reference point than expected. – egreg Jun 13 '13 at 09:50

2 Answers2

4

Two needs fight with each other: the hyperref anchor has to be placed above the item number, so that a click on a hyperlink will show the item and not place the view below it. On the other hand, this introduces an element in the vertical list (the minipage) that sets a different reference point than expected.

Here's a workaround for this particular case:

\documentclass{article}
\usepackage{hyperref}
\begin{document}

\noindent
  Hello\rlap{\kern-2cm\vrule height 0pt depth 0.2pt width 11cm}
  \raisebox{\baselineskip}{\fbox{%
    \begin{minipage}[t]{9cm}
      \begin{enumerate}
        \item The duplicate ratio of $2a:3b$ is $4a^2:9b^2$.
        \item The subduplicate ratio of $49:25$ is $7:5$.
        \item The triplicate ratio of $2x:1$ is $8x^3:1$.
      \end{enumerate}
    \end{minipage}}}

\end{document}

The \rlap is used to draw a rule showing the baseline.

enter image description here

If no hyperlink to the first item is needed, one can do with

\noindent
  Hello\rlap{\kern-2cm\vrule height 0pt depth 0.2pt width 11cm}
  \fbox{%
    \begin{minipage}[t]{9cm}
      \begin{enumerate}
        \begin{NoHyper}
        \item The duplicate ratio of $2a:3b$ is $4a^2:9b^2$.
        \end{NoHyper}
        \item The subduplicate ratio of $49:25$ is $7:5$.
        \item The triplicate ratio of $2x:1$ is $8x^3:1$.
      \end{enumerate}
    \end{minipage}}

that producse the same result.

egreg
  • 1,121,712
  • Is there a reason this anchor is not placed in a box whose height is 0pt? – A.Ellett Jun 13 '13 at 14:54
  • The reason for my previous comment is that this anchor is also disrupting the height used by \fbox. – A.Ellett Jun 13 '13 at 14:57
  • @A.Ellett \fbox uses whatever is the reference point of its contents. It is raised because otherwise a click on a link pointing to the anchor would hide the text, not show it: PDF viewers go to the link placing it at the top of the screen. – egreg Jun 13 '13 at 16:21
1

use

\begin{minipage}[t]{9cm}\vspace{0pt}% define a line for vertical positioning
  \begin{enumerate}
    \item the first item
    [...]