GeneralHow can we make hyperlinks for footnote?

LaTeX specific issues not fitting into one of the other forums of this category.
ggyyree
Posts: 21
Joined: Mon Sep 15, 2008 6:32 pm

How can we make hyperlinks for footnote?

Post by ggyyree »

How can we make hyperlinks for footnote? I use hyperref package and the codes below but I got not hyperlinks for footnotes. Any suggestions? Thanks a lot! :ugeek:

Code: Select all

hyperfootnotes = true

Code: Select all

\footnotemark[1]
\footnotetext[1]{nnn}

Recommended reading 2024:

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

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

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

How can we make hyperlinks for footnote?

Post by localghost »

There two points to be taken into account.
If these suggestions don't help, provide your complete preamble. There may be other package that cause conflicts with hyperref.


Best regards
Thorsten¹
ggyyree
Posts: 21
Joined: Mon Sep 15, 2008 6:32 pm

Re: How can we make hyperlinks for footnote?

Post by ggyyree »

It's solved. Thanks a lot!!!
Last edited by ggyyree on Tue Oct 28, 2008 4:49 pm, edited 1 time in total.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Re: How can we make hyperlinks for footnote?

Post by localghost »

Remember the first point of my list.
ggyyree
Posts: 21
Joined: Mon Sep 15, 2008 6:32 pm

How can we make hyperlinks for footnote?

Post by ggyyree »

localghost wrote:Remember the first point of my list.
I have put the hyperref at the last of the preamble but it doesn't work...
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

How can we make hyperlinks for footnote?

Post by Stefan Kottwitz »

Hi,

have a look at the hyperref README file, the footnote support is explained near its end, further it provides a compilable example demonstrating hyperlinks even with \footnotemark and \footnotetext.

Stefan
LaTeX.org admin
ggyyree
Posts: 21
Joined: Mon Sep 15, 2008 6:32 pm

How can we make hyperlinks for footnote?

Post by ggyyree »

Stefan_K wrote:Hi,

have a look at the hyperref README file, the footnote support is explained near its end, further it provides a compilable example demonstrating hyperlinks even with \footnotemark and \footnotetext.

Stefan
Yes, thanks a lot! I have tested with the nasty example. It works! But it doesn't applicable for my report because I use the \footnotemark inside a table. What I did is like following and anything wrong?

Code: Select all

\makeatletter
\begin{center}
\setlength{\floatsep}{10pt plus 3pt minus 2pt} 
\begin{tabular}{c||p{4.2cm}|p{4.2cm}|p{4.2cm}}
\toprule
N &aaa &bbb &ccc \footnotemark  \let\saved@Href@A\Hy@footnote@currentHref \\
\midrule
N &111 &222 \footnotemark \let\saved@Href@B\Hy@footnote@currentHref &333
\bottomrule
\end{tabular}
\tabcaption{\small\bf\it Table}
\label{table:Table1}
\end{center}

\addtocounter{footnote}{-2}%
  \let\Hy@footnote@currentHref\saved@Href@A
\footnotetext[1]{Test1}
  \addtocounter{footnote}{1}%
  \let\Hy@footnote@currentHref\saved@Href@B
\footnotetext[2]{Test2}
[/color]
Nasty example:

Code: Select all

\documentclass{article}
\usepackage{hyperref}
\begin{document}
\makeatletter
A%
  \footnotemark
  \let\saved@Href@A\Hy@footnote@currentHref
  % remember link name
B%
  \footnotemark
  \let\saved@Href@B\Hy@footnote@currentHref
b%
  \addtocounter{footnote}{-1}%
  \addtocounter{Hfootnote}{-1}% generate the same anchor
  \footnotemark
C%
  \footnotemark
  \let\saved@Href@C\Hy@footnote@currentHref
  \addtocounter{footnote}{-2}%
  \let\Hy@footnote@currentHref\saved@Href@A
\footnotetext{AAAA}%
  \addtocounter{footnote}{1}%
  \let\Hy@footnote@currentHref\saved@Href@B
\footnotetext{BBBBB}%
  \addtocounter{footnote}{1}%
  \let\Hy@footnote@currentHref\saved@Href@C
\footnotetext{CCCC}%
\end{document}
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

How can we make hyperlinks for footnote?

Post by Juanjo »

ggyyree wrote: What I did is like following and anything wrong?

Code: Select all

\begin{center}
......................
N &aaa &bbb &ccc \footnotemark  \let\saved@Href@A\Hy@footnote@currentHref \\
.....................
N &111 &222 \footnotemark \let\saved@Href@B\Hy@footnote@currentHref &333
.....................
\end{center}
.....................
\footnotetext[1]{Test1}
 .....................
\footnotetext[2]{Test2}
[/color]
The \let commands need to be \global to take effect out of the group where they lie and \footnotetext has an optional argument.

The following code defines and exemplifies the commands \Footnotemark and \Footnotetext to automatize tasks. You can always use them instead of \footnotemark and \footnotetext, except when the optional argument of these commands is required. Instead of having to manually define \saved@Href@A, \saved@Href@B, \saved@Href@C, etc., \Footnotemark defines \saved@Href@<aa>, where <aa> stands for an alphabetic version of the footnote counter. For preventing the case of more that 27 footnotes, this is done with the \alphalph command defined in the alphalph package. If you never have a large number of footnotes, the code can be slightly simplified.

Code: Select all

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{alphalph}
\usepackage{booktabs}
\usepackage{hyperref}

\makeatletter
\newcommand{\Footnotemark}{\footnotemark%
 \expandafter\global\expandafter\let\csname saved@Href@\alphalph{\value{footnote}}\endcsname%
    \Hy@footnote@currentHref}
\newcommand{\Footnotetext}[1]{%
   \expandafter\let\expandafter\Hy@footnote@currentHref\csname saved@Href@\alphalph{\value{footnote}}\endcsname%
   \footnotetext{#1}}
\makeatother

\begin{document}

\setcounter{footnote}{35}

Text before the table\footnote{A usual footnote.}. The number of the first footnote is \thefootnote.

\begin{center}
   \setlength{\floatsep}{10pt plus 3pt minus 2pt} 
   \begin{tabular}{c||p{4.2cm}|p{4.2cm}|p{4.2cm}}
      \toprule
      N &aaa &bbb &ccc\Footnotemark \\
      \midrule
      N &111 &222\Footnotemark   &333\Footnotemark \\
      \bottomrule
   \end{tabular}
\end{center}

\addtocounter{footnote}{-2}\Footnotetext{First footnote in the table}
\stepcounter{footnote}\Footnotetext{Second footnote}
\stepcounter{footnote}\Footnotetext{Third footnote}

Text after the table\Footnotemark\Footnotetext{Footnote done with 
\texttt{\textbackslash Footnotemark} and \texttt{\textbackslash Footnotetext}.}
Text after the table\footnote{Other usual footnote.}.

\end{document}
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
ggyyree
Posts: 21
Joined: Mon Sep 15, 2008 6:32 pm

How can we make hyperlinks for footnote?

Post by ggyyree »

Yes, it works quite well! Thank yo very much! However, I also met a problem that two footmarks need to be referred to the same footnote. How to do that please?

What I want is something like below, the footnote for "ccc" and "111" are the same.

Code: Select all

\begin{center}
N &aaa &bbb &ccc \footnotemark[1]\\
N &111 \footnotemark[1] &222 \footnotemark[2] &333
\end{center}
\footnotetext[1]{Test1}
\footnotetext[2]{Test2}

Juanjo wrote:
ggyyree wrote: What I did is like following and anything wrong?

Code: Select all

\begin{center}
......................
N &aaa &bbb &ccc \footnotemark  \let\saved@Href@A\Hy@footnote@currentHref \\
.....................
N &111 &222 \footnotemark \let\saved@Href@B\Hy@footnote@currentHref &333
.....................
\end{center}
.....................
\footnotetext[1]{Test1}
 .....................
\footnotetext[2]{Test2}
[/color]
The \let commands need to be \global to take effect out of the group where they lie and \footnotetext has an optional argument.

The following code defines and exemplifies the commands \Footnotemark and \Footnotetext to automatize tasks. You can always use them instead of \footnotemark and \footnotetext, except when the optional argument of these commands is required. Instead of having to manually define \saved@Href@A, \saved@Href@B, \saved@Href@C, etc., \Footnotemark defines \saved@Href@<aa>, where <aa> stands for an alphabetic version of the footnote counter. For preventing the case of more that 27 footnotes, this is done with the \alphalph command defined in the alphalph package. If you never have a large number of footnotes, the code can be slightly simplified.

Code: Select all

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{alphalph}
\usepackage{booktabs}
\usepackage{hyperref}

\makeatletter
\newcommand{\Footnotemark}{\footnotemark%
 \expandafter\global\expandafter\let\csname saved@Href@\alphalph{\value{footnote}}\endcsname%
    \Hy@footnote@currentHref}
\newcommand{\Footnotetext}[1]{%
   \expandafter\let\expandafter\Hy@footnote@currentHref\csname saved@Href@\alphalph{\value{footnote}}\endcsname%
   \footnotetext{#1}}
\makeatother

\begin{document}

\setcounter{footnote}{35}

Text before the table\footnote{A usual footnote.}. The number of the first footnote is \thefootnote.

\begin{center}
   \setlength{\floatsep}{10pt plus 3pt minus 2pt} 
   \begin{tabular}{c||p{4.2cm}|p{4.2cm}|p{4.2cm}}
      \toprule
      N &aaa &bbb &ccc\Footnotemark \\
      \midrule
      N &111 &222\Footnotemark   &333\Footnotemark \\
      \bottomrule
   \end{tabular}
\end{center}

\addtocounter{footnote}{-2}\Footnotetext{First footnote in the table}
\stepcounter{footnote}\Footnotetext{Second footnote}
\stepcounter{footnote}\Footnotetext{Third footnote}

Text after the table\Footnotemark\Footnotetext{Footnote done with 
\texttt{\textbackslash Footnotemark} and \texttt{\textbackslash Footnotetext}.}
Text after the table\footnote{Other usual footnote.}.

\end{document}
ggyyree
Posts: 21
Joined: Mon Sep 15, 2008 6:32 pm

How can we make hyperlinks for footnote?

Post by ggyyree »

I am sorry to bother again but how to change the color of the footmark now please?

I did and it doesn't work:

Code: Select all

\color{red}\Footnotemark\color{black}
Post Reply