3

I am using the positioning TikZ library to make a commutative diagram. I am having trouble getting the bottom arrow to be horizontal.

Here is the output with my problem: the positioning library is on the left, and the output I thought I should get (done with the matrix library) is on the right. The problem is the arrow above $\psi^{-1}$: it is not exactly horizontal on the left version of the diagram.

What am I doing wrong? Is there a reason I shouldn't be getting the same picture on the left and on the right?

output exhibiting problem

And here is my code:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning}


\begin{document}


\[
\begin{tikzpicture}[  baseline=(current bounding box.center)]
  % Tell it where the nodes are
  \node (F) {$M^P \cap \pi_W^{-1}( U) $};
  \node (E) [right=of F] {$V$};
  \draw[->] (F)-- node [above] {\footnotesize $\pi_V$} (E);
   \node (C) [below=of F] {$U \subset W$};
   \draw[->] (F)-- node [left] {\footnotesize $\pi_W$} (C);
  \node (B) [below=of E] {$I \times V$};
  \draw[->] (C)-- node [below] {\footnotesize $\psi^{-1}$} (B);
  \draw[<-] (E)-- (B);
\end{tikzpicture}
=
\begin{tikzpicture}[every node/.style={midway},  baseline=(current bounding box.center)]
\matrix[column sep={6em,between origins},
        row sep={3em}] at (0,0)
{ 
  \node (F) {$M^P \cap \pi_W^{-1}( U) $}; & 
  \node (E) {$V$};\\
     \node (C) {$U \subset W$};&
      \node (B) {$I \times V$};\\};
        \draw[->] (F)-- node [above] {\footnotesize $\pi_V$} (E);
   \draw[->] (F)-- node [left] {\footnotesize $\pi_W$} (C);
  \draw[->] (C)-- node [below] {\footnotesize $\psi^{-1}$} (B);
  \draw[<-] (E)-- (B);
\end{tikzpicture}
\]
\end{document}
4
  • 2
    Take a look at the snake lemma (tex.stackexchange.com/a/3894/86), the bit starting "(Added in edit)". Mar 19, 2012 at 13:52
  • Though looking in more detail at your code, that's the explanation but the solutions are different. Mar 19, 2012 at 13:54
  • 3
    Not directly related to the question itself, but there is a package for creating commutative diagrams that uses TikZ, tikz-cd. Mar 19, 2012 at 14:02
  • 1
    The top left node has a subscript, hence it has a greater depth. The below=of x on both nodes simply positions the new node some standard distance below x (node distance actually, which is 1cm and 1cm by default). below uses the south anchor, so if one of the nodes has a greater depth it will also have a slightly lower anchor (since the centers are aligned, due to the placement using right=of...). This causes the new nodes to not be aligned horizontally. You can remedy this by using the center anchor explicitly. when saying below=of .... Mar 19, 2012 at 14:28

1 Answer 1

8

This is normal. The node of the first lines are different heights. You need to use option on grid

You can remove every node/.style={midway} in the second picture

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning}

\begin{document}

\begin{tikzpicture}[every node/.style={on grid},  baseline=(current bounding box.center),node distance=2]
  % Tell it where the nodes are
  \node (F) {$M^P \cap \pi_W^{-1}( U) $};
  \node (E) [right=of F] {$V$};
  \draw[->] (F)-- node [above] {\footnotesize $\pi_V$} (E);
   \node (C) [below=of F] {$U \subset W$};
   \draw[->] (F)-- node [left] {\footnotesize $\pi_W$} (C);
  \node (B) [below=of E] {$I \times V$};
  \draw[->] (C)-- node [below] {\footnotesize $\psi^{-1}$} (B);
  \draw[<-] (E)-- (B);
\end{tikzpicture}
=
\begin{tikzpicture}[  baseline=(current bounding box.center)]
\matrix[column sep={6em,between origins},
        row sep={3em}] at (0,0)
{ 
  \node (F) {$M^P \cap \pi_W^{-1}( U) $}; & 
  \node (E) {$V$};\\
     \node (C) {$U \subset W$};&
      \node (B) {$I \times V$};\\};
        \draw[->] (F)-- node [above] {\footnotesize $\pi_V$} (E);
   \draw[->] (F)-- node [left] {\footnotesize $\pi_W$} (C);
  \draw[->] (C)-- node [below] {\footnotesize $\psi^{-1}$} (B);
  \draw[<-] (E)-- (B);
\end{tikzpicture}

\end{document} 

enter image description here

0

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.