7

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}%
  • It works with a simple \parbox{3.5cm} however – user31729 Mar 24 '18 at 22:29
  • @ChristianHupfer: That resolves the issue with the space before the parbox, but still has additional space before the list. – Peter Grill Mar 24 '18 at 22:31
  • True, I thought you want to remove the space before the box only – user31729 Mar 24 '18 at 22:32
  • @ChristianHupfer: Good point. Have updated the question to make it explicit that both additional spaces are not deisred. – Peter Grill Mar 24 '18 at 22:36
  • @ChristianHupfer Option t is important for the problem here, try \parbox[t]{3.5cm}. – Heiko Oberdiek Mar 24 '18 at 22:38
6

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}
  • 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
4
+200

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:

\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}
\makeatletter
\newcommand\nohyperitem{\measuring@true \item \measuring@false}
\makeatother
\begin{document}%
\noindent
\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

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.