XeLaTeX、\includegraphics 和 \hyperlink

XeLaTeX、\includegraphics 和 \hyperlink

我对 XeLaTeX 有疑问。我已从 LaTeX 切换到 XeLaTeX,因为我想使用 ttf 字体,但现在我遇到了问题\hyperlink。它可以处理文本,但不处理图像。

例如,当我单击文本:Dit hjem 时,我将转到第 2 页。它不适用于图像。

我的代码:

\documentclass[landscape,a4paper,11pt]{article} 
\special{papersize=297mm,210mm}

\usepackage{graphicx}
%\usepackage[pdftex]{graphicx}

\usepackage{hyperref}

\usepackage[danish]{babel}

\DeclareGraphicsExtensions{.png,.pdf,.jpg,.mps}

\usepackage[top=2cm, bottom=2cm, left=3cm, right=3cm]{geometry}
\usepackage[absolute]{textpos}
\pagestyle{empty}

\setlength{\parindent}{0pt}

\usepackage{color}

\hypersetup{
    bookmarks=true,         % show bookmarks bar?
    unicode=false,          % non-Latin characters in Acrobat’s bookmarks
    pdftoolbar=true,        % show Acrobat’s toolbar?
    pdfmenubar=true,        % show Acrobat’s menu?
    pdffitwindow=false,     % window fit to page when opened
    pdfstartview={FitH},    % fits the width of the page to the window
    pdftitle={My title},    % title
    pdfauthor={Author},     % author
    pdfsubject={Subject},   % subject of the document
    pdfcreator={Creator},   % creator of the document
    pdfproducer={Producer}, % producer of the document
    pdfkeywords={keyword1} {key2} {key3}, % list of keywords
    pdfnewwindow=true,      % links in new window
    colorlinks=false,       % false: boxed links; true: colored links
    linkcolor=black,          % color of internal links
    citecolor=green,        % color of links to bibliography
    filecolor=magenta,      % color of file links
    urlcolor=cyan,           % color of external links
    pdfnonfullscreenpagemode=true,
    linktoc=none,
    pdfborder={ 0 0 0}
}


\begin{document}

\hyperlink{page.2}{\includegraphics[height=14.869mm, width=14.869mm]{images/tiger}} 
\hyperlink{page.2}{\textblockcolour{white}{\fontsize{3mm}{5mm} \selectfont Dit hjem}}

\null\newpage
Some text

\end{document}

答案1

我能够复制您的问题。我在这里找到了解决方案:http://www.tug.org/pipermail/xetex/2005-October/002480.html

来自网站:

您可以通过将图形包含内容包装在宏中来解决这个问题,该宏会在 图像的
两个对角处输出字形;它们可以是小的空白字形(例如 \char32),这样就不会显示在页面上,只要它们是 字体中的真实字形,xdv2pdf 就可以“看到”它们。我认为这会 诱使驱动程序创建正确的链接区域。



这是执行该工作的命令(再次来自网站):

\newsavebox{\ximagebox}
\newlength{\ximageheight}
\newsavebox{\xglyphbox}
\newlength{\xglyphheight}
\newcommand{\xbox}[1]%
  {\savebox{\ximagebox}{#1}%
  \settoheight{\ximageheight}{\usebox{\ximagebox}}%
  \savebox{\xglyphbox}{\char32}%
  \settoheight{\xglyphheight}{\usebox{\xglyphbox}}%
  \raisebox{\ximageheight}[0pt][0pt]{\raisebox{-\xglyphheight}[0pt][0pt]{%
    \makebox[0pt][l]{\usebox{\xglyphbox}}}}%
    \usebox{\ximagebox}%
    \raisebox{0pt}[0pt][0pt]{\makebox[0pt][r]{\usebox{\xglyphbox}}}}

用作

\hyperlink{page.2}{\xbox{\includegraphics[height=14cm, width=14cm]{tiger}}}

完整的 MWE 如下:

\documentclass[landscape,a4paper,11pt]{article} 
\special{papersize=297mm,210mm}

\usepackage{graphicx}
%\usepackage[pdftex]{graphicx}

\usepackage{hyperref}

\usepackage[danish]{babel}

\DeclareGraphicsExtensions{.png,.pdf,.jpg,.mps}

\usepackage[top=2cm, bottom=2cm, left=3cm, right=3cm]{geometry}
\usepackage[absolute]{textpos}
\pagestyle{empty}

\setlength{\parindent}{0pt}

\usepackage{color}

\hypersetup{
    bookmarks=true,         % show bookmarks bar?
    unicode=false,          % non-Latin characters in Acrobat’s bookmarks
    pdftoolbar=true,        % show Acrobat’s toolbar?
    pdfmenubar=true,        % show Acrobat’s menu?
    pdffitwindow=false,     % window fit to page when opened
    pdfstartview={FitH},    % fits the width of the page to the window
    pdftitle={My title},    % title
    pdfauthor={Author},     % author
    pdfsubject={Subject},   % subject of the document
    pdfcreator={Creator},   % creator of the document
    pdfproducer={Producer}, % producer of the document
    pdfkeywords={keyword1} {key2} {key3}, % list of keywords
    pdfnewwindow=true,      % links in new window
    colorlinks=false,       % false: boxed links; true: colored links
    linkcolor=black,          % color of internal links
    citecolor=green,        % color of links to bibliography
    filecolor=magenta,      % color of file links
    urlcolor=cyan,           % color of external links
    pdfnonfullscreenpagemode=true,
    linktoc=none,
    pdfborder={ 0 0 0}
}


\newsavebox{\ximagebox}
\newlength{\ximageheight}
\newsavebox{\xglyphbox}
\newlength{\xglyphheight}
\newcommand{\xbox}[1]%
   {\savebox{\ximagebox}{#1}%
    \settoheight{\ximageheight}{\usebox{\ximagebox}}%
    \savebox{\xglyphbox}{\char32}%
    \settoheight{\xglyphheight}{\usebox{\xglyphbox}}%
    \raisebox{\ximageheight}[0pt][0pt]{\raisebox{-\xglyphheight}[0pt][0pt]{%
      \makebox[0pt][l]{\usebox{\xglyphbox}}}}%
    \usebox{\ximagebox}%
    \raisebox{0pt}[0pt][0pt]{\makebox[0pt][r]{\usebox{\xglyphbox}}}}

\begin{document}

\hyperlink{page.2}{\xbox{\includegraphics[height=14cm, width=14cm]{images/tiger}}}
\hyperlink{page.2}{\textblockcolour{white}{\fontsize{3mm}{5mm} \selectfont Dit hjem}}

\null\newpage
Some text

\end{document}

相关内容