7

How can I draw a previously named path in TikZ?

\documentclass[tikz]{standalone}
\usetikzlibrary{intersections}

\begin{document}
\begin{tikzpicture}
    
    \path[name path=mypath] (0,0) -- (5,5);
    
    %\draw[use path=mypath]; % This does not work
    
    %\path[mypath, draw]; % This does not work

\end{tikzpicture}   
\end{document}

The answer given here has a macro for use path option. Is there a solution within TikZ?

1 Answer 1

10

It is just wrong syntax. After you name a path via [save path], you can recall it with [use path].

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\path[save path=\mypath] (0,0) -- (5,5);
\draw[use path=\mypath]; % This works now
\end{tikzpicture}   
\end{document}

The key [name path] of the library intersections has totally different use. The keys [name path] and [save path] can be combined. See Section 14.22 in pgfmanual for more details.

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .