3

This is minimal (not) working example that comes from much bigger document:

\documentclass{article}
\usepackage{adjustbox}
\usepackage{hyperref}

\begin{document}

\newcommand\hreftt[2]{%
    \href{#1}{\texttt{#2}}%
}
\newcommand{\rubylink}{\href{https://en.wikipedia.org/wiki/Ruby_(programming_language)}{Ruby}}
\newcommand{\erlanglink}{\href{https://en.wikipedia.org/wiki/Erlang_(programming_language)}{Erlang}}
\newcommand{\pythonlink}{\href{https://en.wikipedia.org/wiki/Python_(programming_language)}{Python}}
\newcommand{\powershelllink}{\href{https://en.wikipedia.org/wiki/PowerShell}{PowerShell}}
\begin{table}
    \begin{adjustbox}{max width=\textwidth}
    \begin{tabular}{l|l|l|l|l}
        Programming language & \rubylink         & \rubylink, \erlanglink  & \pythonlink, \powershelllink  & \pythonlink           \\\hline
        Something            & aaaaaaaaaaaaaaaaa & bbbbbbbbbbbbb           & ccccccccccccc                 & dddddddddddddddddddd
    \end{tabular}
    \end{adjustbox}
    \caption{This is test}
\end{table}

\end{document}

When I compile it with the command latexmk -pdf it produces correct PDF:

Correct output

But when I compile with XeLaTeX, like that: latexmk -pdf -pdflatex=xelatex it produces:

enter image description here

Unfortunately I need to use XeLaTeX and the above example needs to produce correct PDF. How can I fix misplaced hyperlinks?

  • I think this has come up before (scaling pdf links is tricky) but scaling tables should only be a last resort, is there really no alternative? – David Carlisle May 5 '17 at 20:37
  • I have 5-columns table with comparison of some software. Unfortunately this table is (a little bit) too wide to fit \textwidth. On the one hand too wide table looks ugly, but on the other hand, as @Ulrike Fischer mentioned, scaling a tabular is bad typesetting. – patryk.beza May 6 '17 at 8:24
  • yes but you would not justify a paragraph of text by applying arbitrary scale so having inconsistent fonts and spacing, so why do it to the text if it is in a tabular ? It should always be possible to use \small or reduce \tabcolsep or some other way of adjusting the table. – David Carlisle May 6 '17 at 8:44
  • I've changed table's font to \footnotesize and it looks much better now. Thank you! – patryk.beza May 6 '17 at 8:53
6

Scaling a tabular is bad typesetting. It leads to uneven font sizes.

Your problem is due to a change in xetex.def which broke skaling of link areas. This problem affects a current texlive 2016, texlive 2017 pretest and a current miktex.

As a workaround until the problem is resolved you can try to revert to the older definition by adding to your document.

\makeatletter
\def\Gscale@start{%
  \special{x:gsave}\special{x:scale \Gscale@x\space\Gscale@y}}
\makeatletter

You can also use tikz instead as it scales links area when xelatex is used correctly (it doesn't with pdflatex)

\documentclass{article}
\usepackage{adjustbox,tikz}
\usepackage{hyperref}

\begin{document}\parskip1cm
\newcommand{\rubylink}{\href{https://en.wikipedia.org/wiki/Ruby_(programming_language)}{Ruby}}

abc \rubylink cde

\scalebox{2}{abc \rubylink cde}

\tikz[scale=2,transform shape]\node[inner sep=0]{abc \rubylink cde};

\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.