15

What’s the most straightforward/idiomatic way to shift the text for the node West a little to the left, so that there’s a reasonable gap between the text for nodes West and East? I would like to keep the text for the node East where it is, and for all the arrows to retain their present orientation. (I didn’t find this question particularly helpful, despite the title.)

enter image description here

I thought I might be able to use xshift, as mentioned here, but I wasn’t able to make that work. Maybe this is because West is the node relative to which the others are placed?

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[node distance=1.5cm, auto]
  \node (West) {
    $\Gamma \vdash A, B, C, D, E, F, G$
  };
  \node (North) [right of=West, above of=West] {
    $\Gamma’$
  };
  \node (South) [below of=West, right of=West] {
    $\Delta’$
  };
  \node (East) [right of=North, below of=North] {
    $\Delta \vdash I, J, K, L, M$
  };
  \draw[->] (West) to node [yshift=-1ex] {$f$} (North);
  \draw[->] (West) to node [yshift=1ex,swap] {$g$} (South);
  \draw[dotted,->] (North) to node [yshift=-1ex] {$f’$} (East);
  \draw[dotted,->] (South) to node [yshift=1ex,swap] {$g’$} (East);
\end{tikzpicture}
\end{document}
5
  • I've been able to hack it by adding \hspace{-2em} to the node text for West, but is there anything closer to idiomatic Tikz?
    – Roly
    Commented Nov 17, 2015 at 15:00
  • A couple of options. Brute force: \node[] (West) { $\Gamma \vdash A, B, C, D, E, F, G\qquad$ };. Use xshift but for East: \node (East) [xshift=1em,right of=North, below of=North] { $\Delta \vdash I, J, K, L, M$ };.
    – sgmoye
    Commented Nov 17, 2015 at 15:02
  • This is possibly related.
    – Roly
    Commented Nov 18, 2015 at 15:21
  • @sgmoye Thanks. Those suggestions unfortunately move the arrows too, whereas I would just like to move the node text. (See my answer below.)
    – Roly
    Commented Nov 18, 2015 at 15:24
  • The keys above of=… and so on are considered deprecated and the positioning library with above=of … should be used. See Q9386 and Q94396. Since you've updated this question anyway: Do you want the connecting lines to be orthogonal to each other but just more horizontal space between the nodes? Commented Sep 16, 2022 at 10:51

3 Answers 3

11

Just add \hspace{-2em} to the node text for West.

enter image description here

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[node distance=1.5cm, auto]
  \node (West) {
    \hspace{-2em}$\Gamma \vdash A, B, C, D, E, F, G$
  };
  \node (North) [right of=West, above of=West] {
    $\Gamma'$
  };
  \node (South) [below of=West, right of=West] {
    $\Delta'$
  };
  \node (East) [right of=North, below of=North] {
    $\Delta \vdash I, J, K, L, M$
  };
  \draw[->] (West) to node [yshift=-1ex] {$f$} (North);
  \draw[->] (West) to node [yshift=1ex,swap] {$g$} (South);
  \draw[dotted,->] (North) to node [yshift=-1ex] {$f'$} (East);
  \draw[dotted,->] (South) to node [yshift=1ex,swap] {$g'$} (East);
\end{tikzpicture}
\end{document}
6

If you don't want to shift the node itself (since that would shift the arrows), either you have to play around with adding space to your node text (negative to the left or positive to the right), or you have to add another node that contains your text. This second option has the advantage that you can directly specify the amount of shifting and not rely on the alignment.

One possibility is to use the label option:

\begin{tikzpicture}[node distance=1.5cm, auto]
  \node [label={[xshift=-2em]center:$\Gamma \vdash A, B, C, D, E, F, G$}] (West) {\phantom{$\Gamma \vdash A, B, C$}};
  \node (North) [right of=West, above of=West] {
    $\Gamma'$
  };
  \node (South) [below of=West, right of=West] {
    $\Delta'$
  };
  \node (East) [right of=North, below of=North] {
    $\Delta \vdash I, J, K, L, M$
  };
  \draw[->] (West) to node [yshift=-1ex] {$f$} (North);
  \draw[->] (West) to node [yshift=1ex,swap] {$g$} (South);
  \draw[dotted,->] (North) to node [yshift=-1ex] {$f'$} (East);
  \draw[dotted,->] (South) to node [yshift=1ex,swap] {$g'$} (East);
\end{tikzpicture}

The label together with the center option adds a second node right at the same place as the original node. This node can then be shifted using xshift. Note that the text of the original node should not be empty, otherwise the arrows f and g start too closely to the label text. A phantom text on the original node ensures the right distance.

enter image description here

1
  • Thanks. This answer looks great, but in the end it seems the \hspace{-2em} 'hack' (if that's the right way to characterise it - see answer below) is the most appropriate for my needs. (Least painful, least intrusive.)
    – Roly
    Commented Dec 11, 2015 at 12:51
2

I'm back :-). After rethinking, what should be preserved and what should to be moved in desired image, I decided to edit my answer again ...

Edit (3): Since the question has not been clear to me, in prevous version of answer (which I erase, since they are not help you) I from your solution guess, again, what you like to obtain. Below is my (last) proposition :-).

My analysis of your answer show me, that it is not quit in "spirit" of correct use of TikZ. Let see, what you really obtain with your solution:

[![enter image description here][1]][1]

To get above picture I only add to nodes option draw=red that it can be seen, that text in West node protrude out of it. I like just to point out, that this is not good practice and should be avoided.

Possible solutions: I after longer guessing assume, that you like to obtain, that arrow (seen from North and South node) touch West node on the same distance from its north east corner as at East node from its north west corner, i.e., that slope of arrows would be preserved. To obtain this property are more possibilities. For example:

  1. guessin this distance and than use it as

    \draw ([xshift=-guessed distance>] West.north east) to node ... (North);

  2. make measurement of this distance

  3. some other solution (which not cross my mind)

For second possibilities one can exploit three TikZ libraries: calc, intersections and positioning. The last one is used for correct use node or coordinates placement sintax (right=of ... instead right of = ...). With helpintersectiond˙ is determined intersection of arrow from North node with border of East node and with calc is calculated distance (in x direction only) from middle point between West and East node to this intersection:

\documentclass[border=3mm,tikz]{standalone}
    \usetikzlibrary{calc,intersections,positioning}

    \begin{document}
\begin{tikzpicture}[
    node distance=1.5cm, 
                    ]
\node (West) {$\Gamma \vdash A, B, C, D, E, F, G$};
\node (East) [right=4mm% <-- distance between nodes West and East
                        of West] {$\Delta \vdash I, J, K, L, M$};
% coordinate in the middle of the West and EAST node
\coordinate (a) at ($(West.east)!0.5!(East.west)$);
%
\node (North) [above=of a] {$\Gamma'$};
\node (South) [below=of a] {$\Delta'$};
% determination of intersection between arrow from North to East
% with node East
    \path[name path=curve 1] (East.north west) -- (East.north);% auxiliary path
    \path[name path=curve 2] (North) -- (East);% auxiliary path
    \path[name intersections={of=curve 1 and curve 2, by={b}}] (b);
% caluculation of distance to intersection
\path   let \p1 = (a),
            \p2 = (b |- a),
            \n1 = {veclen(\y2-\y1,\x2-\x1)} in
        coordinate[left=\n1 of a ] (c);
% arrows
\draw[->]   (c |- West.north) to node[above] {$f$} (North) ;
\draw[->]   (c |- West.south) to node[below] {$g$}  (South) ;
\draw[dotted,->]    (North) to node[above] {$f'$}  (East);
\draw[dotted,->]    (South) to node[below] {$g'$}  (East);%,
\end{tikzpicture}
    \end{document}

With this solution the slope of arrows between nodes preserve their slope, the distance between West and East node can be explicit set and North and west node are always on the north and south of middle point between West and East node.

Below are two images, first with 4mm distance between West and East node, and second with 16mm. The MWE above is for the first image.

enter image description here enter image description here

3
  • Thanks, but no. (See the clarification I added to the question, in bold text. Maybe you wrote your answer before I added my clarification!) To be absolutely clear: I just want to move the node text, and keep everything else as it is. (Which is exactly what I would do if I were drawing the diagram by hand.)
    – Roly
    Commented Nov 17, 2015 at 15:07
  • @Roly, obvious I don't understand you. Your request move node West and East apart, but the arrows and other nodes should be on the same place ... ok, see my edited answer.
    – Zarko
    Commented Nov 17, 2015 at 15:29
  • thanks for the improved answer. Like I said, the idea is to keep everything the same, but move the node text associated with West slightly to the left. Actually \hspace{-2em} does the trick; maybe that's the best solution, so I added this as a candidate answer. Hope it's at least clear now what I was after.
    – Roly
    Commented Nov 18, 2015 at 15:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .