Graphics, Figures & TablesHow to make a hyperlink point to top of figure

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
mazatlanmexico
Posts: 10
Joined: Thu Jul 15, 2010 5:01 pm

How to make a hyperlink point to top of figure

Post by mazatlanmexico »

Hi:
I am trying to put some hyperlinks in my document but they point to the caption instead of the figure itself. I read about the hypcap package addressing this problem but it appears to be ignored. If I try to go to the last page then it shows the whole graphic but if the graphic is in the middle of the document,the hyperlink points to the caption. I have attached the graphic used for the example below: Thanks for your help

Code: Select all

\documentclass[11pt]{article}
\usepackage[usenames,dvipsnames]{color} % load all the colors
\usepackage[colorlinks=true,linkcolor=Peach]{hyperref}
\usepackage[all]{hypcap}
\begin{document}
Go to \hyperlink{bar}{bar graphic}\\
Go to \hyperlink{bar2}{bar graphic2}
\newpage
\begin{figure}[htp]
\centering
\includegraphics[width=6in,height=8in]{bar}
\caption{\hypertarget{bar}bar graphic}\label{bar}
\end{figure}
\newpage
\begin{figure}[htp]
\centering
\includegraphics[width=6in,height=8in]{bar}
\caption{\hypertarget{bar2}bar graphic}\label{bar2}
\end{figure}
\end{document}
Attachments
bar.JPG
bar.JPG (31.71 KiB) Viewed 6159 times
Last edited by mazatlanmexico on Sat Jul 24, 2010 12:07 am, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

Re: How to make a hyperlink point to top of figure

Post by sommerfee »

The hypcap package is only addressing hyperlinks made by \label and \ref.

But if you would like to use \hyperlink and \hypertarget instead, why don't you just put the \hypertarget at the beginning of the figure (and not into the caption)?
mazatlanmexico
Posts: 10
Joined: Thu Jul 15, 2010 5:01 pm

Re: How to make a hyperlink point to top of figure

Post by mazatlanmexico »

I did try to put the \hypertarget{} by the beginning of the figure but messes up my graphic and the \begin{landscape} gets ignored. I wouldn't mind using \ref if that fixes my problem but I am going to have to see how is done.
User avatar
sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

How to make a hyperlink point to top of figure

Post by sommerfee »

mazatlanmexico wrote:I wouldn't mind using \ref if that fixes my problem but I am going to have to see how is done.
Simply use \label and \ref (or \autoref). For example:

Code: Select all

\documentclass[11pt]{article}
\usepackage[usenames,dvipsnames]{color} % load all the colors
\usepackage{graphicx}
\usepackage[colorlinks=true,linkcolor=Peach]{hyperref}
\usepackage[all]{hypcap}
\begin{document}
Go to \autoref{bar}\\
Go to \autoref{bar2}
\newpage
\begin{figure}[htp]
\centering
\includegraphics[width=6in,height=8in]{bar}
\caption{bar graphic}\label{bar}
\end{figure}
\newpage
\begin{figure}[htp]
\centering
\includegraphics[width=6in,height=8in]{bar}
\caption{bar graphic}\label{bar2}
\end{figure}
\end{document}
mazatlanmexico
Posts: 10
Joined: Thu Jul 15, 2010 5:01 pm

Re: How to make a hyperlink point to top of figure

Post by mazatlanmexico »

Thanks sommerfee, I wanted to use \hyperlink because it colors the hyperlinked like in this case: Go to \hyperlink{bar}{bar graphic}\\, {bar graphic} is colored.
I think \ref and \autoref do the job and I will be getting familiar with it but from the top of your head do you know how \hyperlink and \hypertarget can be used with \begin{landscape}
mazatlanmexico
Posts: 10
Joined: Thu Jul 15, 2010 5:01 pm

Re: How to make a hyperlink point to top of figure

Post by mazatlanmexico »

It is all good now!!!, I just made it work. For some reason \hipertarget{} didn't like to be before my landscaped page and I went ahead and inserted \newpage right before it and it worked like a charm. Thanks for your time in this matter.
Post Reply