4

Assume I have the following snippet/screenshot. How can I get Desc2 on the same line as Desc1. So Desc2 should be vertically placed below T2 but horizontally at the same level as Desc1 so that the descriptions are laid out on the same line.

More in general: how to position a node horizontally relatively from node X, but vertically from node Y?

Preferable a solution without calc or matrix (free node placement)

So I am looking something like:

 \node[below of=t2 left of d1] {Desc2};

What is the easiest way to do this?

MWE:

    \documentclass[tikz]{standalone}
    \usepackage{tikz}
    \usetikzlibrary{positioning}
    \begin{document}
        \begin{tikzpicture}[align=center,node distance=2cm]
         \node[style={circle}] (t1) {T1} -- (t1) 
                  node[above left of=t1,style={circle}] (t2) {T2};
          \path[draw,->] (t1) -- (t2);
                  \node[below of=t1]  (d1) {Desc1};
            \node[below of=t2] {Desc2};
          \end{tikzpicture}
    \end{document}

enter image description here

4

You can use perpendicular coordinate system at (t2|-d1) in

\node at (t2|-d1) {Desc2};

(t2|-d1) means - x coordinate same as t2 and y coordinate same as d1. So if (x1,y1) are coordinates of t2 and (x2,y2) are coordinates of d1 then (t2|-d1) (or equivalently {d1-|t2)) is equal to (x1,y2). For more details, read pgfmanual, page 137, section 13.3.1.

\documentclass[tikz]{standalone}
%\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
    \begin{tikzpicture}[align=center,node distance=2cm]
     \node[style={circle}] (t1) {T1} -- (t1)
              node[above left = of t1,style={circle}] (t2) {T2};
      \path[draw,->] (t1) -- (t2);
              \node[below = of t1]  (d1) {Desc1};
        \node at (t2|-d1) {Desc2};
      \end{tikzpicture}
\end{document}

enter image description here

Aside, when you use positioning library, use the syntax below = of (not below of =) and so forth.

| improve this answer | |

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