2

I want to draw a line from one part of the text (on the page) to another part. I'm storing (relative) coordinates, and this is the reason why my MWE doesn't work. Is there any way, using TikZ, of doing so? (Note that I wish to keep apart the TikZ pictures, i.e., I do not want to include the whole text in one TikZ picture environment.)

I have the following MWE:

\documentclass{article}
\usepackage{tikz}
\begin{document}
  This is my text.\tikz\coordinate (one) at (0,0);

  \bigskip\ldots\bigskip\bigskip

  This is another text.\tikz{\coordinate (two) at (2,2); draw [red, thick, fill](one) --> (two);}
\end{document}

And this is, of course, what I get:

enter image description here


Update 1

According to the TikZ-PGF manual (p.249) I must use the remember picture and overlay options. This is the new code:

\documentclass{article}
\usepackage{tikz}
\begin{document}

This is my text.\tikz[remember picture] \node[circle,fill=red!50] (n1) {};

\bigskip\ldots\bigskip\bigskip

This is another text.\tikz[remember picture] \node[fill=blue!50] (n2) {};

\begin{tikzpicture} [remember picture, overlay]
draw [red, very thick](n2) --> (n1);
\end{tikzpicture}

\end{document}

But it doesn't work either:

enter image description here

  • 1
    Look up overlay picture – daleif Sep 28 '15 at 18:48
  • 2
    You can do it with tikzmark. – Salim Bou Sep 28 '15 at 19:36
  • 1
    Lacking backslash in front of draw – vaettchen Sep 28 '15 at 19:44
5

This is from the manual, adapted for your situation and using overlay as suggested by @daleif:

\documentclass{article}
\usepackage{tikz}

\begin{document}

Starting with a red dot,
\tikz[remember picture] \node[circle,fill=red!50] (n1) {};
we keep talking.

\bigskip\ldots\bigskip\bigskip

This is my text.
\tikz[remember picture] \node[fill=blue!50] (n2) {};
More to be said.

\begin{tikzpicture}[remember picture,overlay]
\draw[->,very thick] (n1) -- (n2);
\end{tikzpicture}

This is another text.

\end{document}

This yields

enter image description here

and hopefullly is good enough to get you started.

| improve this answer | |

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.