Take the 2-minute tour ×
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.

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}
share|improve this question
2  
Take a look at the snake lemma (tex.stackexchange.com/a/3894/86), the bit starting "(Added in edit)". –  Loop Space Mar 19 '12 at 13:52
    
Though looking in more detail at your code, that's the explanation but the solutions are different. –  Loop Space Mar 19 '12 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. –  Torbjørn T. Mar 19 '12 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 .... –  Roelof Spijker Mar 19 '12 at 14:28

1 Answer 1

up vote 8 down vote accepted

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

share|improve this answer
    
thank you! the "on grid" option fixes it perfectly. –  Sam Lisi Mar 19 '12 at 17:06

Your Answer

 
discard

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.