# How can I do this diagram with tikz?

How can I do this diagram with tikz?

-
Could you name this kind of diagram? Then you should add such term in question title and body, making it less vague when you don't see a picture and more useful for googlers/searchers. –  przemoc Jul 12 '11 at 14:02

My tikz answer is a little longer than with egreg's xy-pic solution. Here is the code.

\documentclass{minimal}

\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{matrix}
\usetikzlibrary{decorations.pathreplacing}

%this shifts a straight line perpendicular to its direction
\tikzstyle{s}=[decorate,decoration={show path construction,
lineto code={
\draw let
\p1 = (\tikzinputsegmentfirst),
\p2 = (\tikzinputsegmentlast),
\p3 = ($(\p2)-(\p1)$),
\p4 = ($(\p1)+{2/veclen(\x3,\y3)}*(\p3)$)
in
($(\p1)!1!90:(\p4)$) -- ++ (\p3)
;}}]

\begin{document}

\begin{tikzpicture}

\matrix[matrix of math nodes,column sep=1cm,row sep=1cm] (m) {
0&K&P&M&0\\
0&K'&P'&M&0\\};

\draw[->] (m-1-1) -- (m-1-2);
\draw[->] (m-1-2) -- (m-1-3);
\draw[->] (m-1-3) -- (m-1-4) node[above,midway] {$\scriptstyle\alpha$};
\draw[->] (m-1-4) -- (m-1-5);
\draw[->] (m-2-1) -- (m-2-2);
\draw[->] (m-2-2) -- (m-2-3);
\draw[->] (m-2-3) -- (m-2-4) node[above,midway] {$\scriptstyle\alpha'$} ;
\draw[->] (m-2-4) -- (m-2-5);

\draw[double equal sign distance,shorten <=5pt,shorten >=5pt] (m-1-4) -- (m-2-4);
\draw[s,->] (m-1-3) -- (m-2-3) node[right,midway] {$\scriptstyle\lambda$};
\draw[s,->] (m-2-3) -- (m-1-3) node[left,midway] {$\scriptstyle\lambda'$};
\end{tikzpicture}
\end{document}


The result is

From comments: There is problem with horizontal lines between node. Here are two solutions. 1- (suggested from the link in the comments) Add text height and width for the nodes. The beginning code for the matrix is then

\matrix[matrix of math nodes,column sep=1cm,row sep=1cm,text height=1.5ex, text depth=0.25ex]


2- Here are two styles you can use to make sure you get horizontal lines. You can also use small adjustments such as \vphantom{'} (see comments). They are a little like the -| and |- to get lines, but without the |.

%draws a horizontal line with the vertical position determined by
%the end point of the specified points.
%hwrend : hor. with respect to end
\tikzstyle{hwrend}=[decorate,decoration={show path construction,
lineto code={
\draw let
\p1 = (\tikzinputsegmentfirst),
\p2 = (\tikzinputsegmentlast),
\p3 = ($(\p2)-(\p1)$)
in
(\x1,\y2) -- ++ (\x3,0)
;}}]

%hwrstart : hor. with respect to start
\tikzstyle{hwrstart}=[decorate,decoration={show path construction,
lineto code={
\draw let
\p1 = (\tikzinputsegmentfirst),
\p2 = (\tikzinputsegmentlast),
\p3 = ($(\p2)-(\p1)$)
in
(\x1,\y1) -- ++ (\x3,0)
;}}]

-
Interesting; I'd add \scriptstyle for the arrow labels and \vphantom{'} to better align the bottom row. –  egreg Jul 11 '11 at 21:29
Yes, it works. But if I write \path instead of \draw it doesn't work, could you tell me the difference between them, please? –  Peter E Jul 11 '11 at 21:45
@Frederic: Replace double by double equal sign distance to get correctly spaced lines. –  Caramdir Jul 11 '11 at 22:01
@Peter: \path basically only creates the graphic, but does not actually draw it (there are situations where this is quite useful). –  Caramdir Jul 11 '11 at 22:03
@Caramdir: thanks for the suggestion. –  Frédéric Jul 12 '11 at 0:55

I don't know with TikZ, but with Xy-pic it's quite easy:

\usepackage[all,pdf,cmtip]{xy}

\begin{document}
\xymatrix{
0 \ar[r] &
K \ar[r] &
P \ar@<3pt>[d]^{\lambda} \ar[r]^{\alpha}  &
M \ar@{=}[d] \ar[r] &
0 \\
0\vphantom{'} \ar[r] &
K' \ar[r] &
P' \ar@<3pt>[u]^{\lambda'} \ar[r]^{\alpha'} &
M\vphantom{'} \ar[r] &
0\vphantom{'}
}
\end{document}


-