7

I want all the vertical lines parallel in this example. How can I manage that? Thanks a lot. Here is a picture.

picture

\documentclass{scrartcl}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{amsfonts}

\usetikzlibrary{matrix,arrows,calc}
\begin{document}
\begin{center}
\begin{tikzpicture}[]
\matrix (m) [matrix of math nodes, row sep=1.5em,
              column sep=1.5em, text height=1.5ex, text depth=0.25ex, text centered]
              {
                          & 0 &   & A &       & A\amalg_AB     &       & C     & & 0\\
                        0 &   & A &       & B     &                        & C     &       & 0\\    
                          & 0 &   & A &       & A\amalg_AB &       & C & & 0\\
                    0 &   & A &       & B &                        & C &       & 0\\
              };
              \path[->,font=\scriptsize]

                    (m-2-1) edge node[auto] {} (m-2-3)
                    (m-2-3) edge node[auto] {$f$} (m-2-5)               
                    (m-2-5) edge node[auto] {$g$} (m-2-7)
                    (m-2-7) edge node[auto] {} (m-2-9)

                    (m-4-1) edge node[auto] {} (m-4-3)
                    (m-4-3) edge node[auto] {$f$} (m-4-5)               
                    (m-4-5) edge node[auto] {$g$} (m-4-7)
                    (m-4-7) edge node[auto] {} (m-4-9)

                    (m-1-2) edge node[auto] {} (m-1-4)
                    (m-1-4) edge node[auto] {$$} (m-1-6)                
                    (m-1-6) edge node[auto] {$$} (m-1-8)
                    (m-1-8) edge node[auto] {} (m-1-10)

                    (m-3-2) edge node[auto] {} (m-3-4)
                    (m-3-4) edge node[auto] {$$} (m-3-6)                
                    (m-3-6) edge node[auto] {$$} (m-3-8)
                    (m-3-8) edge node[auto] {} (m-3-10)

                    (m-2-3) edge node[auto] {} (m-1-4)
                    (m-2-5) edge node[auto] {} (m-1-6)
                    (m-2-7) edge node[auto] {} (m-1-8)

                    (m-4-3) edge node[auto] {} (m-3-4)
                    (m-4-5) edge node[auto] {} (m-3-6)
                    (m-4-7) edge node[auto] {} (m-3-8)
                    ;
            \end{tikzpicture}
           \end{center}
  \end{document}
Jack
  • 73
  • 1
    Adding text width=1cm counts? – percusse Jun 28 '13 at 17:52
  • Same problem like here: How to ensure consecutive diagonal arrows form a straight line?. The tikz-cd package uses a \matrix internally. For example, you could use column sep={between origins,3.5em} and get parallel arrows, although you have to make sure that the nodes are not overlapping or too narrow. – Qrrbrbirlbel Jun 28 '13 at 17:54
  • Could somebody "translate" me this solution into my example. I am totally no expert I never used "tikzcd", what is used in the solution you mentioned. – Jack Jun 28 '13 at 18:02
  • It's easier to type A' instead of A^\prime or A^\pr defining a new command. The result is precisely the same. – egreg Jun 28 '13 at 18:03
  • Thanks for the advice. But I still didn't solve my actual problem. – Jack Jun 28 '13 at 18:06
  • @Qrrbrbirlbel I hoped that column sep={3.5em,between origins} worked in tikz-cd; unfortunately it appears it doesn't. – egreg Jun 28 '13 at 18:11
  • @egreg I have re-defined \tikzcd@sep (and the … sep keys) mainly so that it works with the pre-defined styles normal, small etc. But the fix also provides a better interface to use between origins. Without the fix, you can use column sep={{{{3.5em,between origins}}}}; the key value gets handed down three times and is not protected properly. – Qrrbrbirlbel Jun 28 '13 at 18:38
  • @Qrrbrbirlbel Your code works, but I get four \end occurred when \ifx on line XY was incomplete messages – egreg Jun 28 '13 at 19:13

1 Answers1

3

With the help of Qrrbrbirlbel, here's a solution with tikz-cd:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz-cd}

\newcommand\push[3]{#1\amalg_{#2}#3}

\begin{document}
\begin{tikzcd}[column sep={{{{3em,between origins}}}}]%[bo column sep=3em]
{} & 
0 \arrow{rr} &&
A' \arrow{rr} &&
\smash[b]{\push{A'}{A}{B} \arrow{rr}} &&
C \arrow{rr} &&
0
\\
0 \arrow{rr} &&
A \arrow{rr}{f} \arrow{ur} &&
B \arrow{rr}{g} \arrow{ur} &&
C \arrow{rr} \arrow{ur} &&
0
\\
{} & 
0 \arrow{rr} &&
A' \arrow{rr} &&
\smash[b]{\push{A'}{A}{B'}} \arrow{rr} &&
C' \arrow{rr} &&
0
\\
0 \arrow{rr} &&
A \arrow{rr}{f'} \arrow{ur} &&
B' \arrow{rr}{g'} \arrow{ur} &&
C' \arrow{rr} \arrow{ur} &&
0
\end{tikzcd}
\end{document}

The only subtle points are

  1. column sep={{{{3em,between origins}}}} with four pairs of braces.
  2. the \smash[b]{...} around the push out, in order to get the same length for the middle arrows.

The syntax of tikz-cd is surely more friendly. I believe that a bug report to the author of tikz-cd in order to fix the column sep problem is in order.

enter image description here

egreg
  • 1,121,712
  • The bug fix is essentially only \patchcmd\tikzcd@sep{=#2}{={#2}}{}{}. Then only one pair of { } is needed (as usual for the ,). But then one cannot use pre-defined settings like normal and so on. – Qrrbrbirlbel Jun 28 '13 at 19:59
  • Thank you very much. I will begin using tikz-cd. I am only interested in drawing diagrams anyway. – Jack Jun 29 '13 at 11:44