5

I use hyperref and pgf packages.

I need pgf to include and position an image:

\pgfputat{\pgfxy(-0.2, -2.4)}{
    \pgfbox[left,base]{
        \includegraphics[width=0.19\textwidth]{\@universitylogo}
    }
}

\href{http://www.example.com}{www.example.com}   % Shows link with broken anchor

But after each \pgfbox[left,base]{} call the \href anchor moves lower and lower below the link title. Any ideas how to fix the anchor?

Here is minimal example to demonstrate the broken \href anchor:

\documentclass{article}
\usepackage{pgf}
\usepackage{hyperref}

\begin{document}

\begin{center}
  \pgfputat{\pgfxy(-1.3, -2.1)}{\pgfbox[left,base]{
      \includegraphics[width=0.19\textwidth]{img/sun}}}
  \pgfputat{\pgfxy(10.9, -2.0)}{\pgfbox[left,base]{
      \includegraphics[width=0.15\textwidth]{img/moon}}}

  \parbox[b]{0.5\textwidth}{
     \centering \large\bf
     My University \\
     Institute of Science and Technology \\
     C O U N T R Y
  } 

\vskip 1cm
\href{http://www.example.com}{www.example.com}
\end{center}
\end{document}

Here is the result: enter image description here

niekas
  • 499
  • Are you using the raiselinks option? – John Kormylo Oct 09 '14 at 15:10
  • No. Just tried setting it to true|false, but no effect. – niekas Oct 09 '14 at 15:15
  • Never mind. I presume this whole thing is sitting inside an \href command. Perhaps you you put the \href inside the \pgfbox instead. – John Kormylo Oct 09 '14 at 15:21
  • Nope, the \href and \pgfputat are in the same block. – niekas Oct 09 '14 at 15:29
  • Do you need to use this lowlevel commands instead of regular TikZ syntax ? – percusse Oct 09 '14 at 17:12
  • @percusse I don't need. But I simply don't know how to use TikZ. Someone suggested me to use this lowlevel code snippet for image positioning. – niekas Oct 09 '14 at 17:27
  • I can imagine. Can you extend your example to a real use case? I have some sort of an idea what your intention is but it's best if you just describe it. – percusse Oct 09 '14 at 17:31
  • I want to have logos on top left and top right corners and post the link somewhere on the same page. I have added working example. – niekas Oct 09 '14 at 18:51
  • I assume any alternative the reproduces the output without the \href problem is okay. – Werner Oct 09 '14 at 19:08
  • @Werner Yes, since the link is clickable and looks like url. I tried using other hyperref package commands, such as \url, but the problem remains. – niekas Oct 09 '14 at 19:10

2 Answers2

3

Here is a very mild alternative that provides the output you're after:

enter image description here

\documentclass{article}
\usepackage[margin=0.5in]{geometry}% Just for this example
\usepackage{tabularx,graphicx,hyperref}

\begin{document}

\begin{center}
  \renewcommand{\tabularxcolumn}[1]{>{\centering\arraybackslash}m{#1}}
  \begin{tabularx}{\linewidth}{@{}m{.2\linewidth}Xm{.2\linewidth}@{}}
    \includegraphics[width=\linewidth]{example-image-a} &
    \large\bfseries
    My University \par
    Institute of Science and Technology \par
    C O U N T R Y &
    \includegraphics[width=\linewidth]{example-image-b} \\ \\[1cm]
    &
    \href{http://www.example.com}{www.example.com}
  \end{tabularx}
\end{center}

\end{document}

The m-column specification is similar to a p-column, but vertically centres its contents (supplied by the array package which is loaded by tabularx).

Werner
  • 603,163
0

I came here because I have had the same issue with moderncv when I would want to keep link clickable and put a logo. pgfbox it's clearly incompatible with hyperref if you don't use it, the link anchor is again at the right place. However, you can't get rid of it, because your images will become float (in my opinion), yielding an incorrect alignment.

I found a working solution, from Werner's link in comments where the initial author was Peter Grill : (https://tex.stackexchange.com/a/169836/125774). Amazing solution! You can once again use coordinates to place anythings.

MWE

\documentclass{article}
\usepackage{hyperref}

\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand*{\BottomLeftX}{1.0in+\hoffset+\oddsidemargin}%
\newcommand*{\BottomLeftY}{\paperheight-1.0in-\voffset-\topmargin-\headheight-\headsep-\textheight}%
\newcommand*{\AbsolutePosition}[4][]{%
    % #1 = tikz options
    % #2 = x (from south west corner of page
    % #3 = y
    % #4 = text
    \begin{tikzpicture}[remember picture,overlay, ultra thick]
        %\draw [shift={(#2,#3)},#1]  (current page.south west) circle (2pt) 
        \draw [#1]  ($(current page.south west) + (\BottomLeftX,\BottomLeftY) + (#2,#3)$)  
                node[above right] {#4};
    \end{tikzpicture}%
}

\begin{document}

\begin{center}
  \AbsolutePosition{8.9cm}{17.5cm}{\includegraphics[width=0.19\textwidth]{example-image-a}}
  \AbsolutePosition{0.9cm}{17.5cm}{\includegraphics[width=0.19\textwidth]{example-image-b}}
  \parbox[b]{0.5\textwidth}{
     \centering \large\bf
     My University \\
     Institute of Science and Technology \\
     C O U N T R Y
  } 
\vskip 1cm
\href{http://www.example.com}{www.example.com}
\end{center}


\end{document}