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.

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

Edit: It seems that this question (one of mine first here) is not so clear as I imagined, when ask them. So I -- stimulated by recently received comments on it -- rephrase it with hope, that now hopefully will be more clear, what bother me at that time. Here we go:

In one of my text books I had a great number of images made by TikZ package, which have only slightly different common elements. The definitions for this elements I store in \tikzset something like this:

   \tikzset{TCP/.style = {
tcpBOX/.style 2 args = {shape=rectangle,
     draw=##1, % border color
     fill=##2, % fill collor
     thick, inner sep= 2mm, outer sep=0mm, minimum height=11mm,
     % etc
% other common elements
and used in TikZ pictures as
\node (n1) [tcpBOX={black}{none}] at (0,0) {some text};
% ...

In some cases I need labels inside tcpBOX node. For this I use the solution which Mark Wibrow provided me years ago 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, how to merge code for tcpBOX and BOX in a way, that the tcpBOX can be used for example as:

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

In time of asked this question I haven't clue how to merge both style definition, because they have own arguments to be set in their use (tcpBOX for "draw" and "fill" and BOX for append command).

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
up vote 1 down vote accepted

Now the questions seems to be quite trivial and solution so obvious ... Any way, solution which I use now solve my problem on the following way:

  • for append after command={\pgfextra{\tikzsavelastnodename\tikzsavednodename}},##1 I define as new style named saveLNN (as acronym for save-Last-Node-Name)
  • to my definition of tcpBOX add this saveLNN

Complete code is:



   \tikzset{TCP/.style = {%
saveLNN/.style = {append after command={%
add text/.style args = {##1:##2}{%
        append after command={node[ATnode,anchor=##1]
        at (\tikzsavednodename.##1) {##2}}
ATnode/.style = {inner sep=0.5mm,
tcpBOX/.style 2 args = {shape=rectangle,
     draw=##1, % border color
     fill=##2, % fill collor
     thick, inner sep= 2mm, outer sep=0mm, minimum height=11mm,
            }% end of tikzset

which gives:

enter image description here

I'm still open for better solution(s).

share|improve this answer

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.