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 would like to draw the following diagram in tikz,

    \documentclass[b5paper,10pt,twoside]{book}
    \usepackage[hmarginratio=1:1]{geometry}
    \usepackage{tikz}
    \usetikzlibrary{arrows,calc,through,backgrounds,matrix,decorations.pathmorphing}
    \begin{document}

    \begin{center}
    \begin{tikzpicture}
    \matrix(m)[matrix of math nodes, row sep=2em, column sep=2em, text height=1.5ex, text depth=0.25ex]
    {X        & \,        & Z         & \,        & Z/Y      & \,       & (Y/X)[1]   \\
    \,        & Y         & \,        & Z/X       & \,       & Y[1]     &         \,         \\
    \,        & \,        & Y/X       & \,        & X[1]     & \,       &         \,         \\};
    \path[->,font=\scriptsize]
    %top arrows
    (m-1-1) edge[bend left =45] node[above] {$g\circ f    $} (m-1-3)
    (m-1-3) edge[bend left =45] node[above] {$            $} (m-1-5)
    (m-1-5) edge[bend left =45] node[above] {$\theta      $} (m-1-7)
    %lower edge border arrows
    (m-1-1) edge                node[below] {$            $} (m-2-2)
    (m-2-2) edge                node[below] {$            $} (m-3-3)
    (m-3-3) edge[bend right=45] node[below] {$            $} (m-3-5)
    (m-3-5) edge                node[below] {$            $} (m-2-6)
    (m-2-6) edge                node[below] {$            $} (m-1-7)

    %completing second dt
    (m-2-2) edge                node[below] {$            $} (m-1-3)
    (m-1-5) edge                node[below] {$            $} (m-2-6)
    ;
    \path[dashed,->,font=\scriptsize]
    (m-1-3) edge                node[above] {$            $} (m-2-4)
    (m-2-4) edge                node[above] {$            $} (m-3-5)

    (m-3-3) edge                node[above] {$            $} (m-2-4)
    (m-2-4) edge                node[above] {$            $} (m-1-5)
    ;
    \end{tikzpicture}
    \end{center}

    \end{document}

But it seems like, since the text in the right nodes are longer than the text in the left nodes that, the gadgets "pizza slices" on the left are smaller than the gadgets on the right. enter image description here

Does anyone know how to force the distances between the nodes to be equal, that might work in this particular diagram. For some other diagrams in the same document I guess that I cannot change the premable. Cheers!

share|improve this question
    
Use the \node (Z) [right=0.3cm of X] with the tikz library 'positioning. you can fix the alignment of a node using align=center`. –  selwyndd21 Jan 12 at 14:39
    
Please, look at updated answer. It's easier than original one. –  Ignasi Jan 13 at 9:31

2 Answers 2

up vote 6 down vote accepted

Updated answer

Sometimes it's worth to better look at pgfmanual before answering a question. My previous answer was correct but rereading "Matrices and Alignment" section I've found between origins option which better solves nunatak's problem.

/tikz/column sep=<spacing list>

This option sets a default space that is added between every two columns. [...]

More generally, the may contain a whole list of numbers, separated by commas, and occurrences of the two key words between origins and between borders. [...] However, if the last occurs is between origins, then the following happens: The distance between the columns is adjusted such that the difference between the origins of all the cells in the first column (remember that they all lie on straight line) and the origins of all the cells in the second column is exactly the given distance.

The between origins option can only be used for columns mentioned in the first row, that is, you cannot specify this option for columns introduced only in later rows.

So, just changing column sep=3em with column sep={3em, betweens origins} in matrix options, the adjustment problem is solved.

enter image description here

Original answer

A matrix helps you to easily place nodes but row and column dimensions are computed according nodes text. If you want to avoid missplacements due to differences in nodes sizes, you can use on grid with certain node distance to easily position nodes according their centers instead of their borders.

Next code shows how to solve your problem. I've kept node's names to avoid changing edge commands. I've also drawn a grid to show how nodes are placed.

\documentclass[b5paper,10pt,twoside]{book}
\usepackage[hmarginratio=1:1]{geometry}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{center}
\begin{tikzpicture}

\draw[black!30] (0,0) grid [xstep=1.5cm, ystep=1.5cm] (9,-3.5);
\begin{scope}[on grid, node distance=3cm]
\node (m-1-1) at (0,0) {$X$};
\node[right=of m-1-1] (m-1-3) {$Z$};
\node[right=of m-1-3] (m-1-5) {$Z/Y$};
\node[right=of m-1-5] (m-1-7) {$(Y/X)[1]$};

\node[below right= 1.5cm and 1.5cm of m-1-1] (m-2-2) {$Y$};
\node[right=of m-2-2] (m-2-4) {$Z/X$};
\node[right=of m-2-4] (m-2-6) {$Y[1]$};

\node[below right= 1.5cm and 1.5cm of m-2-2] (m-3-3) {$Y/X$};
\node[right=of m-3-3] (m-3-5) {$X[1]$};
\end{scope}

    \path[->,font=\scriptsize]
%top arrows
(m-1-1) edge[bend left =45] node[above] {$g\circ f    $} (m-1-3)
(m-1-3) edge[bend left =45] node[above] {$            $} (m-1-5)
(m-1-5) edge[bend left =45] node[above] {$\theta      $} (m-1-7)
%lower edge border arrows
(m-1-1) edge                node[below] {$            $} (m-2-2)
(m-2-2) edge                node[below] {$            $} (m-3-3)
(m-3-3) edge[bend right=45] node[below] {$            $} (m-3-5)
(m-3-5) edge                node[below] {$            $} (m-2-6)
(m-2-6) edge                node[below] {$            $} (m-1-7)

%completing second dt
(m-2-2) edge                node[below] {$            $} (m-1-3)
(m-1-5) edge                node[below] {$            $} (m-2-6)
;
\path[dashed,->,font=\scriptsize]
(m-1-3) edge                node[above] {$            $} (m-2-4)
(m-2-4) edge                node[above] {$            $} (m-3-5)

(m-3-3) edge                node[above] {$            $} (m-2-4)
(m-2-4) edge                node[above] {$            $} (m-1-5)
;
\end{tikzpicture}
\end{center}
\end{document}

enter image description here

share|improve this answer

One ugly way will be to use the corners of nodes to connect like:

(m-1-1.north east) edge[bend left =45] node[above] {$g\circ f    $} (m-1-3.north west)

with some minimum width defined (I kept it as the width of $(Y/X)$. you can adjust this.)

\documentclass[b5paper,10pt,twoside]{book}
\usepackage[hmarginratio=1:1]{geometry}
\usepackage{tikz}
\usetikzlibrary{arrows,calc,through,backgrounds,matrix,decorations.pathmorphing}
\begin{document}

\begin{center}
\begin{tikzpicture}
\matrix(m)[matrix of math nodes, row sep=2em, column sep=2em, text height=1.5ex, text depth=0.25ex,minimum width=\widthof{$(Y/X)$}]
{X        & \,        & Z         & \,        & Z/Y      & \,       & (Y/X)[1]   \\
\,        & Y         & \,        & Z/X       & \,       & Y[1]     &         \,         \\
\,        & \,        & Y/X       & \,        & X[1]     & \,       &         \,         \\};
\path[->,font=\scriptsize]
%top arrows
(m-1-1.north east) edge[bend left =45] node[above] {$g\circ f    $} (m-1-3.north west)
(m-1-3.north east) edge[bend left =45] node[above] {$            $} (m-1-5.north west)
(m-1-5.north east) edge[bend left =45] node[above] {$\theta      $} (m-1-7.north west)
%lower edge border arrows
(m-1-1.south east) edge                node[below] {$            $} (m-2-2.north west)
(m-2-2.south east) edge                node[below] {$            $} (m-3-3.north west)
(m-3-3.south east) edge[bend right=45] node[below] {$            $} (m-3-5.south west)
(m-3-5.north east) edge                node[below] {$            $} (m-2-6.south west)
(m-2-6.north east) edge                node[below] {$            $} (m-1-7.south west)

%completing second dt
(m-2-2.north east) edge                node[below] {$            $} (m-1-3.south west)
(m-1-5.south east) edge                node[below] {$            $} (m-2-6.north west)
;
\path[dashed,->,font=\scriptsize]
(m-1-3.south east) edge                node[above] {$            $} (m-2-4.north west)
(m-2-4.south east) edge                node[above] {$            $} (m-3-5.north west)

(m-3-3.north east) edge                node[above] {$            $} (m-2-4.south west)
(m-2-4.north east) edge                node[above] {$            $} (m-1-5.south west)
;
\end{tikzpicture}
\end{center}

\end{document}

enter image description here.

share|improve this answer

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.