href 无法与图像配合使用(但可以与文本配合使用)

href 无法与图像配合使用(但可以与文本配合使用)

当我使用文本时,文本\href很好,但如果我使用图像,它根本不会生成链接。

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

\href{http://www.yahoo.com}{\includegraphics[scale=.3]{care}} \\
\href{http://www.yahoo.com}{Text works fine!}

\end{document}

我看到其他人也用过它,但不知道为什么它对我不起作用。这是我的日志文件

This is XeTeX, Version 3.1415926-2.2-0.9995.2 (TeX Live 2009/Debian) (format=xelatex 2011.4.6)  29 NOV 2012 22:21
entering extended mode
 %&-line parsing enabled.
**min.tex
(./min.tex
LaTeX2e <2009/09/24>
Babel <v3.8l> and hyphenation patterns for english, usenglishmax, dumylang, noh
yphenation, loaded.
(/usr/share/texmf-texlive/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/share/texmf-texlive/tex/latex/base/size10.clo
File: size10.clo 2007/10/19 v1.4h Standard LaTeX file (size option)
)
\c@part=\count80
\c@section=\count81
\c@subsection=\count82
\c@subsubsection=\count83
\c@paragraph=\count84
\c@subparagraph=\count85
\c@figure=\count86
\c@table=\count87
\abovecaptionskip=\skip41
\belowcaptionskip=\skip42
\bibindent=\dimen102
)
(/usr/share/texmf-texlive/tex/latex/hyperref/hyperref.sty
Package: hyperref 2009/10/09 v6.79a Hypertext links for LaTeX

(/usr/share/texmf-texlive/tex/latex/graphics/keyval.sty
Package: keyval 1999/03/16 v1.13 key=value parser (DPC)
\KV@toks@=\toks14
)
(/usr/share/texmf-texlive/tex/generic/oberdiek/ifpdf.sty
Package: ifpdf 2009/04/10 v2.0 Provides the ifpdf switch (HO)
Package ifpdf Info: pdfTeX in pdf mode not detected.
)
(/usr/share/texmf-texlive/tex/generic/oberdiek/ifvtex.sty
Package: ifvtex 2008/11/04 v1.4 Switches for detecting VTeX and its modes (HO)
Package ifvtex Info: VTeX not detected.
)
(/usr/share/texmf-texlive/tex/generic/ifxetex/ifxetex.sty
Package: ifxetex 2009/01/23 v0.5 Provides ifxetex conditional
)
(/usr/share/texmf-texlive/tex/latex/oberdiek/hycolor.sty
Package: hycolor 2009/10/02 v1.5 Code for color options of hyperref/bookmark (H
O)

(/usr/share/texmf-texlive/tex/latex/oberdiek/xcolor-patch.sty
Package: xcolor-patch 2009/10/02 xcolor patch
))
\@linkdim=\dimen103
\Hy@linkcounter=\count88
\Hy@pagecounter=\count89

(/usr/share/texmf-texlive/tex/latex/hyperref/pd1enc.def
File: pd1enc.def 2009/10/09 v6.79a Hyperref: PDFDocEncoding definition (HO)
)
(/usr/share/texmf-texlive/tex/generic/oberdiek/etexcmds.sty
Package: etexcmds 2007/12/12 v1.2 Prefix for e-TeX command names (HO)

(/usr/share/texmf-texlive/tex/generic/oberdiek/infwarerr.sty
Package: infwarerr 2007/09/09 v1.2 Providing info/warning/message (HO)
)
Package etexcmds Info: Could not find \expanded.
(etexcmds)             That can mean that you are not using pdfTeX 1.50 or
(etexcmds)             that some package has redefined \expanded.
(etexcmds)             In the latter case, load this package earlier.
)
(/usr/share/texmf-texlive/tex/xelatex/xetexconfig/hyperref.cfg
File: hyperref.cfg 2008/07/11 v1.2 hyperref configuration for XeLaTeX
)
(/usr/share/texmf-texlive/tex/latex/oberdiek/kvoptions.sty
Package: kvoptions 2009/08/13 v3.4 Keyval support for LaTeX options (HO)

(/usr/share/texmf-texlive/tex/generic/oberdiek/kvsetkeys.sty
Package: kvsetkeys 2009/07/30 v1.5 Key value parser with default handler suppor
t (HO)
))
Package hyperref Info: Hyper figures OFF on input line 2975.
Package hyperref Info: Link nesting OFF on input line 2980.
Package hyperref Info: Hyper index ON on input line 2983.
Package hyperref Info: Plain pages OFF on input line 2990.
Package hyperref Info: Backreferencing OFF on input line 2995.

Implicit mode ON; LaTeX internals redefined
Package hyperref Info: Bookmarks ON on input line 3191.
(/usr/share/texmf-texlive/tex/latex/ltxmisc/url.sty
\Urlmuskip=\muskip10
Package: url 2006/04/12  ver 3.3  Verb mode for urls, etc.
)
LaTeX Info: Redefining \url on input line 3428.

(/usr/share/texmf-texlive/tex/generic/oberdiek/bitset.sty
Package: bitset 2007/09/28 v1.0 Data type bit set (HO)

(/usr/share/texmf-texlive/tex/generic/oberdiek/intcalc.sty
Package: intcalc 2007/09/27 v1.1 Expandable integer calculations (HO)
)
(/usr/share/texmf-texlive/tex/generic/oberdiek/bigintcalc.sty
Package: bigintcalc 2007/11/11 v1.1 Expandable big integer calculations (HO)

(/usr/share/texmf-texlive/tex/generic/oberdiek/pdftexcmds.sty
Package: pdftexcmds 2009/09/23 v0.6 LuaTeX support for pdfTeX utility functions
 (HO)

(/usr/share/texmf-texlive/tex/generic/oberdiek/ifluatex.sty
Package: ifluatex 2009/04/17 v1.2 Provides the ifluatex switch (HO)
Package ifluatex Info: LuaTeX not detected.
)
(/usr/share/texmf-texlive/tex/generic/oberdiek/ltxcmds.sty
Package: ltxcmds 2009/08/05 v1.0 Some LaTeX kernel commands for general use (HO
)
)
Package pdftexcmds Info: LuaTeX not detected.
Package pdftexcmds Info: pdfTeX >= 1.30 not detected.
Package pdftexcmds Info: \pdf@primitive is available.
Package pdftexcmds Info: \pdf@ifprimitive is available.
)))
\Fld@menulength=\count90
\Field@Width=\dimen104
\Fld@charsize=\dimen105
\Field@toks=\toks15
Package hyperref Info: Hyper figures OFF on input line 4377.
Package hyperref Info: Link nesting OFF on input line 4382.
Package hyperref Info: Hyper index ON on input line 4385.
Package hyperref Info: backreferencing OFF on input line 4392.
Package hyperref Info: Link coloring OFF on input line 4397.
Package hyperref Info: Link coloring with OCG OFF on input line 4402.
Package hyperref Info: PDF/A mode OFF on input line 4407.

(/usr/share/texmf-texlive/tex/generic/oberdiek/atbegshi.sty
Package: atbegshi 2008/07/31 v1.9 At begin shipout hook (HO)
)
\Hy@abspage=\count91
\c@Item=\count92
\c@Hfootnote=\count93
)
*hyperref using default driver hdvipdfm*
(/usr/share/texmf-texlive/tex/latex/hyperref/hdvipdfm.def
File: hdvipdfm.def 2009/10/09 v6.79a Hyperref driver for dvipdfm
\pdfm@box=\box26
\c@Hy@AnnotLevel=\count94
\HyField@AnnotCount=\count95
\Fld@listcount=\count96
)
(/usr/share/texmf-texlive/tex/latex/graphics/graphicx.sty
Package: graphicx 1999/02/16 v1.0f Enhanced LaTeX Graphics (DPC,SPQR)

(/usr/share/texmf-texlive/tex/latex/graphics/graphics.sty
Package: graphics 2009/02/05 v1.0o Standard LaTeX Graphics (DPC,SPQR)

(/usr/share/texmf-texlive/tex/latex/graphics/trig.sty
Package: trig 1999/03/16 v1.09 sin cos tan (DPC)
)
(/etc/texmf/tex/latex/config/graphics.cfg
File: graphics.cfg 2009/08/28 v1.8 graphics configuration of TeX Live
)
Package graphics Info: Driver file: xetex.def on input line 91.

(/usr/share/texmf-texlive/tex/xelatex/xetex-def/xetex.def
File: xetex.def 2009/11/22 v0.94 LaTeX color/graphics driver for XeTeX (RRM/JK)

))
\Gin@req@height=\dimen106
\Gin@req@width=\dimen107
) (./min.aux)
\openout1 = `min.aux'.

LaTeX Font Info:    Checking defaults for OML/cmm/m/it on input line 4.
LaTeX Font Info:    ... okay on input line 4.
LaTeX Font Info:    Checking defaults for T1/cmr/m/n on input line 4.
LaTeX Font Info:    ... okay on input line 4.
LaTeX Font Info:    Checking defaults for OT1/cmr/m/n on input line 4.
LaTeX Font Info:    ... okay on input line 4.
LaTeX Font Info:    Checking defaults for OMS/cmsy/m/n on input line 4.
LaTeX Font Info:    ... okay on input line 4.
LaTeX Font Info:    Checking defaults for OMX/cmex/m/n on input line 4.
LaTeX Font Info:    ... okay on input line 4.
LaTeX Font Info:    Checking defaults for U/cmr/m/n on input line 4.
LaTeX Font Info:    ... okay on input line 4.
LaTeX Font Info:    Checking defaults for PD1/pdf/m/n on input line 4.
LaTeX Font Info:    ... okay on input line 4.
Package hyperref Info: Link coloring OFF on input line 4.

(/usr/share/texmf-texlive/tex/latex/hyperref/nameref.sty
Package: nameref 2007/05/29 v2.31 Cross-referencing by name of section

(/usr/share/texmf-texlive/tex/latex/oberdiek/refcount.sty
Package: refcount 2008/08/11 v3.1 Data extraction from references (HO)
)
\c@section@level=\count97
)
LaTeX Info: Redefining \ref on input line 4.
LaTeX Info: Redefining \pageref on input line 4.
 (./min.out)
(./min.out)
\@outlinefile=\write3
\openout3 = `min.out'.

\AtBeginShipoutBox=\box27
File: care.jpg Graphic file (type QTm)
 <use  "care.jpg" > [1

] (./min.aux) ) 
Here is how much of TeX's memory you used:
 3759 strings out of 495724
 55201 string characters out of 1189347
 114991 words of memory out of 3000000
 6876 multiletter control sequences out of 15000+50000
 3640 words of font info for 14 fonts, out of 3000000 for 9000
 28 hyphenation exceptions out of 8191
 38i,5n,28p,269b,291s stack positions out of 5000i,500n,10000p,200000b,50000s

Output written on min.pdf (1 page).

答案1

自 2012/08/18 版本起,v6.83b 软件包hyperref提供了\XeTeXLinkBox此用途,其内容如下README

\XeTeXLinkBox
-------------
  When XeTeX generates a link annotation, it does not look
  at the boxes (as the other drivers), but only at the character
  glyphs. If there are no glyphs (images, rules, ...), then
  it does not generate a link annotation. Macro \XeTeXLinkBox
  puts its argument in a box and adds spaces at the lower left
  and upper right corners. An additional margin can be specified
  by setting it to the dimen register \XeTeXLinkMargin. The default
  is 2pt.

  Example:
    % xelatex
    \documentclass{article}
    \usepackage{hyperref}
    \setlength{\XeTeXLinkMargin}{1pt}
    \begin{document}
    \section{Hello World}
    \newpage
    \label{sec:hello}
    \hyperref[sec:hello]{%
      \XeTeXLinkBox{\rule{10mm}{10mm}}%
    }
    \end{document}

下面的示例重新定义自动\includgraphics添加\XeTeXLinkBox

\documentclass{article}
\usepackage{hyperref}[2012/08/18]
\usepackage{graphicx}

\ifxetex
  \usepackage{letltxmacro}
  \setlength{\XeTeXLinkMargin}{1pt}
  \LetLtxMacro\SavedIncludeGraphics\includegraphics
  \def\includegraphics#1#{% #1 catches optional stuff (star/opt. arg.)
    \IncludeGraphicsAux{#1}%
  }%
  \newcommand*{\IncludeGraphicsAux}[2]{%
    \XeTeXLinkBox{%
      \SavedIncludeGraphics#1{#2}%
    }%
  }%
\fi

\begin{document}
  \href{http://www.example.com/}{\XeTeXLinkBox{\rule{10mm}{10mm}}}

  \href{http://www.example.com/}{\includegraphics[scale=3]{care}}

  \href{http://www.example.com/}{Text works fine!}
\end{document}

相关内容