10

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}
  • 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 8 '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 8 '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 8 '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 8 '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 8 '13 at 21:32
8

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

  • Thanks a lot @egreg! So easy and it explains everything. I will remember to avoid TeX primitives in the future. – nathanori Apr 9 '13 at 8: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 9 '13 at 9:14
  • @nathanori If I were you, I'd avoid footnotes; the caption is the best place for explanations. – egreg Apr 9 '13 at 9:45
  • @nathanori In any case, you have to "step back" the footnote counter; see tex.stackexchange.com/a/43694/4427 – egreg Apr 9 '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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.