I am reproducing the following figure in TikZ:

tikz advanced positioning example

The upper right '}' curly brace and its full label is produced by the TikZ code that looks like:

\tikzstyle{ssbrace} = [decorate, decoration = {brace, amplitude = 6pt}, xshift = 8pt]
\tikzstyle{ssbracemath} = [midway, anchor = west, xshift = 4pt]
\draw [ssbrace] (\xvrr,\yGt) -- (\xvrr,\yPb)
    node [ssbracemath] (upperss) {$\in \mathbb{S}_d \oplus 0_{n_\text{sl}}$};

where \xvrr, \yGt, and yPb are macros that expand to strings such as e.g. 0.5/2+0.85/2+10pt/2-3pt, meaning: sum half the unit width for the figure -with- half of 85% of the unit width of the figure -with- half of 10 points -and then subtract- 3 points. The complex syntax is because the various components of the string come from more primitive macros that define numerous adjustable parameters. Assume


for sake of the example.

What I would then like to do is render the \mathbb{S}_{n_\text{P}} "S" part of the lower label so that its x center is equal to the x center of the upper label (node upperss) and with a parameteric y coordinate of \yyPc. That is,

\draw (upperss.center,\yyPc) node [anchor=center] (lowerss) {$\mathbb{S}_{n_\text{P}}$};

although the above raises the error "Package PGF Math Error: Unknown function `upperss' (in 'upperss.center'). \draw (upperss.center,\yyPc)" among others, hence my attempts at intuiting TikZ syntax have evidently failed.

With the lowerss node in place, I'd finally like to render the 'in' (\in) for the lower label centered between the rightmost extent of the lower brace and the leftmost extent of lowerss. For this, I attach an empty node named lowerssbrace to the lower brace, and then invoke

\draw (lowerssbrace.east/2+lowerss.west/2,\yyPc) node [anchor=center] {$\in$};

I don't know whether this will work either. In fact, my knowledge of what permutations of which kinds of coordinate arithmetic TikZ supports is limited to "It seems to understand what both (1/2+1/2,1-1/2) and (lowerss.center) mean as coordinates." Whether or not it can mix relative and absolute dimensions, mix named coordinates and dimensions, or perform basic arithmetic such as lowerssbrace.east/2: I have no idea, although my hopes are high.

Note also that the rightmost labeled arrow relies on coordinates (upperss.center,upperss.south+\eqmarg) and (upperss.center,lowerss.north-\eqmarg), hence I also have cases where named coordinates are summed with absolute dimensions.

Everything else in the figure is working as expected.

Is what I'm trying to accomplish here possible to do in TikZ? If so, what is the required syntax?

Many thanks for any assistance. You will have saved me days of spelunking through documentation, assuming this is even possible.

  • yes, it is possible. with some effort and pations, using matrix and positioning libraries. for details read tikz & pgf manual. request "do-it-for-me here aren't very welcome. show us what you try so far. – Zarko Mar 11 '18 at 17:39
  • for starting point search for answers/questions with tag tikz-matrix. – Zarko Mar 11 '18 at 17:47
  • You can probably use the let operation, see chapter 14.15 in the TikZ manual, which lets you access the x- and y-components of a coordinate. Note also that when you mix numbers and units, the unitless numbers are seen as pt. Try for example \tikz \draw [->] (0.5,0) -- (0.5+10pt,0); which doesn't do what it seems you think it does. – Torbjørn T. Mar 11 '18 at 17:47

First of all, note that if you mix unitless numbers and lengths in a coordinate specifications, the unitless numbers are read as lengths in pt, as described in the manual section 13.2 Specifying coordinates. Hence, 1+0.1+10pt becomes 11.1pt, and thus the following code makes an arrow pointing left:

enter image description here

\draw [->] (1,0) -- (\yyPc,0);

There are various methods that can be applied.

To get the x-component of one node and the y-component of another, the easiest way is to use perpendicular coordinates, which I explain in TikZ: What EXACTLY does the the |- notation for arrows do?.

To place a node midway between two other nodes, you can do

\path (a) -- node{this is halfway between a and b} (b);

To place a node a given distance from another node, one method is to use relative coordinates,

\path (lowerssbrace) ++(20pt,0) node {20pt right of lowerssbrace};

You could also study the features of the calc library, described in section 13.5 Coordinate calculations of the TikZ manual.

If you want more specific advice, please add a complete example to your question.

enter image description here

\node [draw] (upperss) {};
\node [draw, red] (lowerssbrace) at (-2,0) {};

\draw (upperss.center |- 0,\yyPc) node (lowerss) {$\mathbb{S}_{n_\text{P}}$};

\path (lowerssbrace |- lowerss) -- node {$\in$} (lowerss);

\node at ($(lowerssbrace) + (20pt,0)$) {a};
| improve this answer | |
  • I was able to make everything work with these tricks. Many thanks. – COTO Mar 11 '18 at 23:17

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.