12

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}
nathanori
  • 123
  • Hi nathanori, welcome to the site! Have you seen Minipage footnote is inside tikZ node, which sounds pretty similar to your problem? If not, could you add a bit more information to your question (what exactly have you tried, what do you mean by "fails"?) – Jake Apr 08 '13 at 20:56
  • Hi @Jake, thank you for your fast answer! I saw Minipage footnote is inside tikZ node but the footnote there is not used inside the tikzpicture, but outside of it. I added more information to my post and hope that helps. Please try the code sample, it will result in an error. – nathanori Apr 08 '13 at 21:11
  • TikZ picture can be placed in certain boxes minipages and footnote can be placed in them or beneath those boxes etc. so forcing a footnote mechanism inside the graphics part is like making coffee with the radiator water. They serve different purposes. – percusse Apr 08 '13 at 21:15
  • Hi @percusse, what would you propose to use then? I would like to draw a bar chart and found tutorials proposing tikz. I would appreciate a better solution. – nathanori Apr 08 '13 at 21:18
  • 1
    I mean a graphics object doesn't have a footer to place the footnote. If you have more details to explain then you might do it in the caption of the figure or use other ways of including data. – percusse Apr 08 '13 at 21:32
  • In the bar chart I would like to annotate some of the texts with a footnote. The footnote should not be placed in the bar chart or under the text, but somewhere else such as in the caption or at the bottom of the page. Something such as Using footnote in table, but for a tikzpicture. I tried to use savenotes/footnote but that did not work either. – nathanori Apr 08 '13 at 21:43

2 Answers2

11

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.

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

enter image description here

egreg
  • 1,121,712
  • Thanks a lot @egreg! So easy and it explains everything. I will remember to avoid TeX primitives in the future. – nathanori Apr 09 '13 at 08:11
  • Hey @egreg, there is a follow-up question: How do I use multiple footnotemark / footnotetext pairs without errors? All footnotetext elements get the number of the last footnotemark. The output displays a "footnote has been referenced but does not exist, replaced by a fixed one" error. The problem is caused by the hyperref package. – nathanori Apr 09 '13 at 09:14
  • @nathanori If I were you, I'd avoid footnotes; the caption is the best place for explanations. – egreg Apr 09 '13 at 09:45
  • @nathanori In any case, you have to "step back" the footnote counter; see http://tex.stackexchange.com/a/43694/4427 – egreg Apr 09 '13 at 10:24
  • Hey @egreg. Thank you very much for your suggestions! I took that into consideration and will try to find a better solution placing annotations = footnotes into the main text. – nathanori Apr 10 '13 at 10:13
0

I'd recommend footnotehyper package so that it can work for multiple links in the same document.

Pretty much the same analysis in my answer for "tables - Footnote in tabular environment - TeX - LaTeX Stack Exchange" apply.

Example: (note that you only need to add the 2 lines marked as % <<<, nothing else needs to be changed)

\documentclass{article}
\usepackage{tikz}
\usepackage{footnotehyper}     % <<<
\makesavenoteenv{tikzpicture}  % <<<
\usepackage{hyperref}
\begin{document}
\begin{tikzpicture}
    \draw (0, 0) -- (1, 2);
    \node at (0, 0) {Text\footnote{Footnote text}};
\end{tikzpicture}
\end{document}
user202729
  • 7,143