I would like to add a footnote to a node in a TikZ picture, but every solution I could imagine fails. I tried using a minipage, too.
\documentclass[a4paper,10pt]{scrartcl}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\foreach \x/\y/\number/\year in {
0.5/0.46/ 4.624/2001,
1.5/0.89/ 8.965/2002\footnotemark,
2.5/1.18/11.892/2003
}
{
\draw (\x cm, 0 cm) rectangle (0.5 cm + \x cm, \y cm) node at (0.25 cm + \x cm, \y cm + 0.25 cm) {\tiny\number};
\node[rotate=45, left] at (0.6 cm +\x cm,-0.1cm) {\year};
};
\end{tikzpicture}
\footnotetext{foo}
\end{document}
The output shown is
! Missing number, treated as zero.
<to be read again>
}
l.18 }
;
The footnote text is displayed correctly, but the footnote mark is not.
I tried using a minipage as following. I replaced
\node[rotate=45, left] at (0.6 cm +\x cm,-0.1cm) {\year};
with
\node[rotate=45, left] at (0.6 cm +\x cm,-0.1cm) {\begin{minipage}{2em}\year\end{minipage}};
Follow-up question: How to create multiple footnotes with the hyperref package?
\documentclass[a4paper,10pt]{scrartcl}
\usepackage{tikz}
\usepackage[
pdfpagelabels,
pdfstartview=FitH,
plainpages=false,
hypertexnames=false
]{hyperref}
\begin{document}
\begin{tikzpicture}
\foreach \x/\y/\Number/\Year in {
0.5/0.46/ 4.624/2001,
1.5/0.89/ 8.965/2002\footnotemark,
2.5/1.18/11.892/2003\footnotemark
}
{
\draw (\x cm, 0 cm) rectangle (0.5 cm + \x cm, \y cm) node at (0.25 cm + \x cm, \y cm + 0.25 cm) {\tiny\Number};
\node[rotate=45, left] at (0.6 cm +\x cm,-0.1cm) {\Year};
};
\end{tikzpicture}
\footnotetext{foo1}
\footnotetext{foo2}
\end{document}
Best Answer
It's quite dangerous using
\number
in that context, because it's an important primitive of TeX that's indeed used for printing the footnote number; that's why TeX gets very confused: it means something completely unexpected when it's necessary to use its original meaning.Also
\year
is a primitive; better using another name also for it.