10

Just including the hyperref package seems to be inserting spurious space before a minipage and before a list. The MWE below produces the image on the right, but if the

\usepackage[colorlinks,breaklinks=true]{hyperref}

line is commented out, we get the spacing on the left.

Note that additional space is inserted

  • before the minipage and
  • before the first list item.

I would like to eliminate both of these.

enter image description here enter image description here


Update: 2019-05-08

Using

\vspace*{-\topskip}%
\nointerlineskip\noindent

as per Heiko's answer, indeed remove the excess space before the minipage (second MWE), but does not remove the excess vertical space before the first list \item:

enter image description here

By commenting out the \usepackage[colorlinks,breaklinks=true]{hyperref} in the second MWE you can see the desired spacing before the first \item.

Note:

  • Using being{NoHyper}... \end{NoHyper} is not really an option as I have links within the text. I don't need to be able to link back to the list \item though (in case that helps).

Listfiles

 article.cls    2014/09/29 v1.4h Standard LaTeX document class
  size10.clo    2014/09/29 v1.4h Standard LaTeX file (size option)
enumitem.sty    2011/09/28 v3.5.2 Customized lists
geometry.sty    2010/09/12 v5.6 Page Geometry
  keyval.sty    2014/10/28 v1.15 key=value parser (DPC)
   ifpdf.sty    2017/03/15 v3.2 Provides the ifpdf switch
  ifvtex.sty    2016/05/16 v1.6 Detect VTeX and its facilities (HO)
 ifxetex.sty    2010/09/12 v0.6 Provides ifxetex conditional
showframe.sty    2011/02/24 v0.1i showframe (new impl., RN)
 eso-pic.sty    2015/07/21 v2.0g eso-pic (RN)
atbegshi.sty    2016/06/09 v1.18 At begin shipout hook (HO)
infwarerr.sty    2016/05/16 v1.4 Providing info/warning/error messages (HO)
 ltxcmds.sty    2016/05/16 v1.23 LaTeX kernel commands for general use (HO)
  xcolor.sty    2016/05/11 v2.12 LaTeX color extensions (UK)
   color.cfg    2016/01/02 v1.6 sample color configuration
  pdftex.def    2018/01/08 v1.0l Graphics/color driver for pdftex
hyperref.sty    2018/02/06 v6.86b Hypertext links for LaTeX
hobsub-hyperref.sty    2016/05/16 v1.14 Bundle oberdiek, subset hyperref (HO)
hobsub-generic.sty    2016/05/16 v1.14 Bundle oberdiek, subset generic (HO)
  hobsub.sty    2016/05/16 v1.14 Construct package bundles (HO)
ifluatex.sty    2016/05/16 v1.4 Provides the ifluatex switch (HO)
 intcalc.sty    2016/05/16 v1.2 Expandable calculations with integers (HO)
etexcmds.sty    2016/05/16 v1.6 Avoid name clashes with e-TeX commands (HO)
kvsetkeys.sty    2016/05/16 v1.17 Key value parser (HO)
kvdefinekeys.sty    2016/05/16 v1.4 Define keys (HO)
pdftexcmds.sty    2018/01/21 v0.26 Utility functions of pdfTeX for LuaTeX (HO)
pdfescape.sty    2016/05/16 v1.14 Implements pdfTeX's escape features (HO)
bigintcalc.sty    2016/05/16 v1.4 Expandable calculations on big integers (HO)
  bitset.sty    2016/05/16 v1.2 Handle bit-vector datatype (HO)
uniquecounter.sty    2016/05/16 v1.3 Provide unlimited unique counter (HO)
letltxmacro.sty    2016/05/16 v1.5 Let assignment for LaTeX macros (HO)
 hopatch.sty    2016/05/16 v1.3 Wrapper for package hooks (HO)
xcolor-patch.sty    2016/05/16 xcolor patch
atveryend.sty    2016/05/16 v1.9 Hooks at the very end of document (HO)
refcount.sty    2016/05/16 v3.5 Data extraction from label references (HO)
 hycolor.sty    2016/05/16 v1.8 Color options for hyperref/bookmark (HO)
 auxhook.sty    2016/05/16 v1.4 Hooks for auxiliary files (HO)
kvoptions.sty    2016/05/16 v3.12 Key value format for package options (HO)
  pd1enc.def    2018/02/06 v6.86b Hyperref: PDFDocEncoding definition (HO)
hyperref.cfg    2002/06/06 v1.2 hyperref configuration of TeXLive
     url.sty    2013/09/16  ver 3.4  Verb mode for urls, etc.
 hpdftex.def    2018/02/06 v6.86b Hyperref driver for pdfTeX
rerunfilecheck.sty    2016/05/16 v1.8 Rerun checks for auxiliary files (HO)
supp-pdf.mkii
 nameref.sty    2016/05/21 v2.44 Cross-referencing by name of section
gettitlestring.sty    2016/05/16 v1.5 Cleanup title references (HO)

Code: Original

\documentclass{article}

\usepackage{enumitem}
\usepackage[textwidth=4.5cm]{geometry}% For better images to compare

\usepackage{showframe}

%% Correct spacing if this is commented out
\usepackage[colorlinks,breaklinks=true]{hyperref}

\begin{document}%
\noindent
\fbox{%
    \begin{minipage}[t][3.0cm][t]{3.5cm}
        \begin{enumerate}
            \item First Item
            \item Second Item
            \item Third Item
            \item Fourth Item
        \end{enumerate}%
    \end{minipage}%
}%
\end{document}%

Updated Code: Fixes spacing before minipage

\documentclass{article}

\usepackage{enumitem}
\usepackage[textwidth=4.5cm]{geometry}% For better images to compare

\usepackage{showframe}

%% Correct spacing if this is commented out
\usepackage[colorlinks,breaklinks=true]{hyperref}

\begin{document}%
\vspace*{-\topskip}%
\nointerlineskip\noindent
\fbox{%
    \begin{minipage}[t][3.0cm][t]{3.5cm}
        \begin{enumerate}
            \item First Item
            \item Second Item
            \item Third Item
            \item Fourth Item
        \end{enumerate}%
    \end{minipage}%
}%
\end{document}%
Peter Grill
  • 223,288

2 Answers2

10

Package hyperref has to insert anchors, otherwise inner-document links would not work. Thus, the topmost element of the enumerate environment is the anchor for the first \item. As side effect, the minipage with option t is no longer aligned at the base line of the topmost line, but the topmost element, the anchor. This causes the full \topskip to be shown at the start of the page.

Workaround:

\vspace*{-\topskip}%
\nointerlineskip
\noindent
\fbox{...}

If the hyperref features are not needed inside the \fbox, then the anchors can be disabled by:

\begin{NoHyper}
...
\end{NoHyper}

The spacing and anchors can be seen by \showlists, e.g.:

\showboxdepth=\maxdimen
\showboxbreadth=\maxdimen

\begin{document}
  \noindent
  \fbox{...}

  \showlists
\end{document}
Heiko Oberdiek
  • 271,626
  • That resolves the spacing before the minipage, but still insertes additional space before the first list items. – Peter Grill Mar 24 '18 at 22:33
  • I do not need hyperref to refer to the list items, but do need to be able to have hyperref linked text/math in the body. – Peter Grill Mar 24 '18 at 22:39
  • @PeterGrill Then you can use environment NoHyper for the parts, where the anchors of hyperref messes up the spacing and it is not needed. – Heiko Oberdiek Mar 24 '18 at 22:43
  • I think I would need the apply NoHyper around the \item but then the lsit complains about missing \item. The \vspace hack is fine, but need an equivalent hack for the the enumitem list so that the first item is moved above the correct amount, but I don't know what that amount is. Also, I thought that perhaps setting topsep to a negative amount would move the first item up but doesn't seem to. – Peter Grill Mar 24 '18 at 22:55
  • @PeterGrill a) Put the whole list in NoHyper. b) The amount can be seen/calculated from the output of \showlists. – Heiko Oberdiek Mar 24 '18 at 23:05
  • If I put the whole list in NoHyper, the links in the body are disabled. I need the text in the body to have links such as \href{run:foo.pdf}{My PDF}, just don't need to be able to link back to the list. Thus, don't think the NoHyper is an option for me. As I don't know how to read the output of showlists, I will post a separate question for that. – Peter Grill Mar 24 '18 at 23:42
10

[updated 2023-10]

If you know that you don't need to link to the first item you can suppress the whatsit (and so the space) like this in a current LaTeX:

\documentclass{article}

\usepackage{enumitem} \usepackage[textwidth=4.5cm]{geometry}% For better images to compare

\usepackage{showframe}

\usepackage[colorlinks,breaklinks=true]{hyperref} \newcommand\nohyperitem{\LinkTargetOff \item \LinkTargetOn}

\begin{document}% \noindent xx\fbox{% \begin{minipage}[t][3.0cm][t]{3.5cm} \begin{enumerate} \nohyperitem First Item \item Second Item \item Third Item \item Fourth Item \end{enumerate}% \end{minipage}% }%

\end{document}%

enter image description here

muzimuzhi Z
  • 26,474
Ulrike Fischer
  • 327,261
  • Starting with hyperref v7.01a (2023-06-25), amsmath is required to make the trick work. This is because hyperref changed the way it patches amsmath. Before, in \refstepcounter the whatsit (more specifically an anchor) is not inserted if \ifmeasuring@ is true, no matter amsmath is loaded or not. After, the whatsit will still be inserted if \ifmeasuring@ is true but amsmath is not loaded. What's unchanged is \ifmeasuring@ is always available. – muzimuzhi Z Oct 26 '23 at 19:53
  • See related hyperref commits 19abb836 and 8c7758a4. – muzimuzhi Z Oct 26 '23 at 19:53
  • 1
    @muzimuzhiZ right. I have updated the answer to avoid internals. – Ulrike Fischer Oct 29 '23 at 13:32