10

I have a minipage, and inside of it I have a footnote and a tikZ picture. Now my problem is, that the footnote text goes inside the last node of my tikZ picture. That is not what I want – and it's very weird actually.

Code and output

\documentclass{article}

\usepackage{tikz,lipsum}

\begin{document}

\begin{minipage}{\textwidth}
\lipsum[1]\footnote{a footnote}% I cannot use \footnotemark etc
    \begin{tikzpicture}[overlay, remember picture]% I need these two options
        \draw[ultra thick, black] (0,0) -- node[sloped,below,text width=12cm,text centered]
{\lipsum[4]} (11,-3);% the text has to have a maximal width
    \end{tikzpicture}
\end{minipage}

\end{document}

Screenshot

First workaround

When I remove the text width = 12cm completely, the footnote moves back under the end of the text:

Screenshot after workaround

But I need the text to have a maximal width. So this is not very satisfying. Any ideas?

3 Answers3

7

where we learn tikz uses minipage internally:-)

this saves and restores the footnotes to stop tikz seeing it, so the footnote comes in the right place, the rotated tikz picture overprints but I guess someone who knows tikz can fix that...

enter image description here

\documentclass{article}

\usepackage{tikz,lipsum}

\begin{document}

\begin{minipage}{\textwidth}
\lipsum[1]\footnote{a footnote}% I cannot use \footnotemark etc
    \setbox0\box\csname@mpfootins\endcsname
    \begin{tikzpicture}[overlay, remember picture]% I need these two options
        \draw[ultra thick, black] (0,0) -- node[sloped,below,text width=12cm,text centered]
{\lipsum[4]} (11,-3);% the text has to have a maximal width
    \end{tikzpicture}\global\setbox\csname@mpfootins\endcsname\box0
\end{minipage}

\end{document}
David Carlisle
  • 757,742
  • 2
    TikZ normally uses an hbox to store the node content but when a line breaking is needed, it switches to a minipage to allow for text width or align=center etc such that the line breaks are respected and/or inserted. That's why removing text width works. – percusse Apr 02 '13 at 13:45
  • 1
    @percusse clearly yes although it probably ought just use \vbox{{\@parboxrerstore so an internal version of minipage that doesn't hijack footnotes. (although you could say that latex could handle nested minipages better:-) – David Carlisle Apr 02 '13 at 13:53
  • Thank you, very nice! I use the code inside a custom package, so I had to change \csname@mpfootins\endcsname to \@mpfootins. But I really like the \csname-method, I think it is much nicer than a \makeatletter :) – Peater de Xel Apr 02 '13 at 14:00
  • 1
    @ralfix I should probably have used \csname @mpfootins\endcsname then it would have worked in both contexts – David Carlisle Apr 02 '13 at 14:11
3

This is why LaTeX is beautiful... Another solution :)

\documentclass{article}

\usepackage{tikz,lipsum}
\usepackage{footnote}

\begin{document}

\begin{minipage}{\textwidth}
\savenotes
\lipsum[1]\footnote{a footnote}% I cannot use \footnotemark etc
    \begin{tikzpicture}[overlay, remember picture]% I need these two options
        \draw[ultra thick, black] (0,0) -- node[sloped,below,text width=12cm,text centered]
{\lipsum[4]} (11,-3);% the text has to have a maximal width
    \end{tikzpicture}
\spewnotes
\end{minipage}

\end{document}
cacamailg
  • 8,405
2

A possible solution (which is not a real solution) is to do something like:

\documentclass{article}

\usepackage{tikz,lipsum}
\usepackage{tabu}

\begin{document}

\begin{minipage}{\textwidth}
\lipsum[1]\footnote{a footnote}% I cannot use \footnotemark etc
    \begin{tikzpicture}[overlay, remember picture]% I need these two options
        \draw[ultra thick, black] (0,0) -- node[sloped,below]
{
    \begin{tabu}to 12cm {X[c]}
    \lipsum[4]
    \end{tabu}
} (11,-3);% the text has to have a maximal width
    \end{tikzpicture}
\end{minipage}

\end{document}
cacamailg
  • 8,405
  • This is a nice (and a real!) solution, but I needed the text to be centered, not justified – I sometimes have only a few words "under the line", these get left-aligned in your solution. But you couldn't know, it wasn't clear from the MWE. – Peater de Xel Apr 02 '13 at 14:05
  • In that case I think you can use the tabu package with X[c] identifier. – cacamailg Apr 02 '13 at 14:08
  • @ralfix just add \centering or (much more efficiently) instead of tabularx use \parbox{12cm}{\centering....} – David Carlisle Apr 02 '13 at 14:09
  • I edited my answer to work with tabu and get the text centered. However, I think the previous comment by @DavidCarlisle probably is the best approach. – cacamailg Apr 02 '13 at 14:15
  • @cacamailg the tabu-solution does not hyphenate words – is there another identifier which does that? @DavidCarlisle another answere? :) – Peater de Xel Apr 02 '13 at 14:15
  • @ralfix It is not tabu stopping the hyphenation it is centering If you ask for (the default latex) centering then lines can be short so hyphenation will only be used for words that are longer than a line. Perhaps you want ragged2e package and \Centering instead which limits how short the lines can get (so tex will hyphenate if necessary) – David Carlisle Apr 02 '13 at 14:21
  • @ralfix I am not sure about the hyphenation in tabu. I meant the solution \parbox{12cm}{\centering....} – cacamailg Apr 02 '13 at 14:21