Hyperref 在列表和小页面前插入虚假空格

Hyperref 在列表和小页面前插入虚假空格

仅包含该hyperref包似乎会插入虚假空间Aminipage 列表。下面的 MWE 生成右侧的图像,但如果

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

行被注释掉后,我们得到了左边的间距。

注意插入了额外的空格

  • minipage
  • 第一个列表项。

我想消除两个都这些。

enter image description here enter image description here


更新日期:2019-05-08

使用

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

根据 Heiko 的回答,确实删除了多余的空间(第二minipage个 MWE),但确实不是删除多余的垂直空间第一个列表\item

enter image description here

通过注释掉\usepackage[colorlinks,breaklinks=true]{hyperref}第二个 MWE 中的 ,您可以在第一个 之前看到所需的间距\item

笔记:

  • 使用being{NoHyper}... \end{NoHyper}并不是一个真正的选择,因为我在文本中有链接。但我不需要能够链接回列表\item(如果有帮助的话)。

列表文件

 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)

代碼:原始

\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}%

更新代码:修复间距 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}%

答案1

hyperref必须插入锚点,否则文档内链接将不起作用。因此,环境的最顶层元素enumerate是第一个的锚点\item。作为副作用,minipagewith 选项t不再与最顶层行的基线对齐,而是与最顶层元素(锚点)对齐。这会导致完整\topskip显示在页面的开头。

解决方法:

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

如果hyperref里面不需要这些功能\fbox,那么可以通过以下方式禁用锚点:

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

间距和锚点可以通过以下方式查看\showlists,例如:

\showboxdepth=\maxdimen
\showboxbreadth=\maxdimen

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

  \showlists
\end{document}

答案2

[2023-10 更新]

如果您知道不需要链接到第一个项目,则可以在当前 LaTeX 中像这样抑制 whatsit(以及空格):

\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

相关内容