Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

years ago Mark Wibrow provided me the following code to adding text in inside border of a (rectangle) shape on this comp.text.tex thread:

%%% code from ctt, December 1999
BOX/.style = {rectangle,
    minimum width=33mm,
    minimum height=22mm,
    append after command={\pgfextra{\tikzsavelastnodename\tikzsavednodename}},#1%
add text/.style args = {#1:#2}{append after command={%
    node[anchor=#1]  at (\tikzsavednodename.#1) {#2}}
%%% example of use
        add text=north:lorum,
        add text=south west:ipsum,
        add text=east:dolor
        ]   (a)             {box};

Its work fine, but I wonder, if it is possible extend definition of BOX with more parameters, for example for set shape width, shape fill or even give a name to shape in a way, that the BOX can be used for example as:

\node[box=<desired parameter>, ...
      add text=south:lorum] (<node name>) at (<coordinate>) {text in box}; 

or even better

\node[box=<desired parameter>, ...
      add text=south:lorum] (<node name>) at (<coordinate>) {text in box}; 

where desired parameters will influence on the box appearing (for example, change the shape width, shape fill etc). I haven't clue how to do this, because BOX implicite already use two (if I understand correctly above example), consequently my rude (I'm not familiar with with more than elementary use of keys) experiments so far fails ...

share|improve this question
I'm not sure I quite understand the question. If you want to change the fill, why don't you just add e.g. fill=blue (or whatever) to the parameters you pass? Why do you want to be able to write e.g. BOX={fill=blue} or something? (If that's the idea - I'm not really sure how you envisage this working.) Your parameters will override the defaults e.g. you can also add text=green to get "box" appearing in green rather than red. Maybe you should post what you tried. That might give a clearer sense of what you are trying to achieve. –  cfr Dec 22 '13 at 4:06
Of course i can define each shapes as you suggest. Actually, up to now i ding so. The idea behind of my questions is the following: for illustration my text book (few hundredths images) i prepare standard shapes which has i thair use small variations (width, fill color) which I wrote as parameters to shape. Some times hapens, that i like to add some text in this shapes in sense of given example. in such a cases I need to 'revrite' existing shapes as you suggest. I just like to escape this and if it is possible, to use 'standardized' form of predefined shapes collected in tikzset. –  Zarko Dec 22 '13 at 8:22
But why do you want to add the parameter to box=<> rather than just adding it? I could understand if you wanted to create a few standard options e.g. BOX, BOF, BOG etc. but I understood that you wanted to use the parameters when calling BOX i.e. for each instance. And I don't get why that would be more convenient that just adding the parameters directly. I still think showing what you tried might make this clearer. Failing that, maybe just give a concrete example of what you have in mind. Or have I misunderstood the point at which you want to specify the additional parameters? –  cfr Dec 22 '13 at 13:25
Meanwhile I rethinking my problem and your questions and find solution which fulfill my expectations. I define "append after command" as separate style and as such added to style for BOX. Now the definition for BOX style can have own parameters. Thank you very much for your attention, it helps me a lot. –  Zarko Dec 24 '13 at 23:37
Perhaps you could post your solution here so that other users can see exactly what you did and benefit from it? –  cfr Dec 28 '13 at 19:54

Your Answer


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

Browse other questions tagged or ask your own question.