TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to know if somebody know a way to define a path in TikZ and reuse the path's definition several times. For example, consider the following:

code example with duplicate paths

If I wanted to change the path (0,2) -- (0,2) -- (5,3) -- (5,2) I'd have to make two changes to the code. How can I avoid this?

share|improve this question
Why not \def it? \def\mypath{ (0,0) -- (5,5)} and then using it \tikz \draw {\mypath};. Not so elegant though. – percusse Jan 19 '12 at 17:30
@percusse Interesting how obvious the solution sometimes is. I'd never have thought TikZ would be able to parse the definition and expand it. The solution is good enough in the sense that you can keep defs local to a tikzpicture. Interestingly, and this is one of the reasons why I never thought of using a \def, TikZ's name path only seems to work for intersections but not for drawing.... – Marc van Dongen Jan 19 '12 at 17:49
I've written a library that does exactly this. I've limited internet access right now, though so can't paste much here. If you search this site for spath then you might get some idea of the sort of thing I do with my code. If it looks interesting, tell me and I'll try to see if it could do what you want. – Loop Space Jan 19 '12 at 23:06
For the interested people this is the question that @AndrewStacey mentions. – percusse Jan 20 '12 at 1:28
Similar question. – qubyte Jan 20 '12 at 2:17
up vote 5 down vote accepted

In a limited way, a postaction or a preaction may be viewed as repeated work on a path. For example, in the following code


\fill[postaction={draw=red,->},blue] (0,3) -- (5,3) -- (5,2) -- (0,2) -- (0,3);


the path is only entered once, but two actions are performed on it, the fill and afterwards the draw.

Again, this is limited in what you can do, but it saves on reentering a path.

share|improve this answer
@Fr\'ed\'eric Thanks. I have to study this in more detail. (I've never used postactions.) – Marc van Dongen Jan 19 '12 at 20:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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