7

The two lower diagonal arrows in the following diagram are obviously not exactly parallel. How can I arrange them correctly? enter image description here

\documentclass{article}
\usepackage{tikz-cd}
\usepackage{amsmath}
\begin{document}
\begin{center}
\begin{tikzcd}[column sep={{{{3em,between origins}}}}]%[bo column sep=3em]

  A' \arrow{rr}[pos=0.25]{f} \arrow{dd}[swap,pos=0.25]{a} \arrow{rd}[inner sep=1pt]{1_{A'}} && B'' \arrow{dd}[pos=0.25]{\iota_{B''}} \arrow{rd}[inner sep=1pt]{\iota_{B''}}\
 {} & A' \arrow{ld}[swap,inner sep=1pt]{a} \arrow{rr}[pos=0.25]{\iota_A\circ a} &&{A}\amalg_{A'}{B''} \arrow{dl}[inner sep=1pt]{1_{{A}\amalg_{A'}{B''}}}\
 A \arrow[swap]{rr}[pos=0.25]{\iota_A} && \smash[b]{{A}\amalg_{A'}{B''}}\
\end{tikzcd}
\end{center}
\end{document}
2
  • 1
    I would say that the same goes for the two upper diagonal arrows.
    – Ludovic C.
    Aug 30, 2013 at 10:52
  • Interestingly, this does not happen with the CVS version of TikZ. There are a few changes to pgfmodulematrix.code.tex that fix this, though as a side effect the bounding box for the matrix is not correctly computed. — By the way, you can drop the \smash[b] by using text depth=0pt. Aug 30, 2013 at 15:09

2 Answers 2

1

In this case, I'd suggest you to hide the width of the widest terms using \makebox:

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

\begin{document}

\begin{center}
\begin{tikzcd}[column sep={3em}]
A' 
  \arrow{rr}[pos=0.25]{f} 
  \arrow{dd}[swap,pos=0.25]{a} 
  \arrow{rd}[inner sep=1pt]{1_{A'}} 
& & 
B'' 
  \arrow{dd}[pos=0.25]{\iota_{B''}} 
  \arrow[shorten >= 10pt]{rd}[inner sep=1pt]{\iota_{B''}}
\\
& 
A' 
  \arrow{ld}[swap,inner sep=1pt]{a} 
  \arrow[shorten >= 20pt]{rr}[pos=0.25]{\iota_A\circ a} 
& &
\makebox[0pt][c]{$A\amalg_{A'}{B''}$} 
  \arrow[shorten <= 6pt,shorten >= 8pt]{dl}[inner sep=1pt]{1_{{A}\amalg_{A'}{B''}}}
\\
A
  \arrow[swap,shorten >= 20pt]{rr}[pos=0.25]{\iota_A} 
& & 
\makebox[0pt][c]{$A\amalg_{A'}{B''}$}
\\
\end{tikzcd}
\end{center}

\end{document}

enter image description here

0
4

This is/was a bug in PGF which has been fixed in the current CVS version (although the bounding box of the matrix is not computed correctly). The problem lies in the last column (or rather in the detection of it).

The easiest fix here is to indicate the last column with an explicit & (even though TikZ doesn’t need it). Then the lines are straight (more or less, see below).

You have used \smash[b] from amsmath which is usually not a bad idea. TikZ though provides an easier interface for this, namely the text depth option. Setting it to zero has the same effect as \smash[b] only that you do not need to provide it every time.
(Of course, if you have a node/cell with very high/deep contents you probably shoudn’t use it then; but setting it to an empty string, i.e. text depth={}, disables the option.)

With this option set, we get

enter image description here

The dimension we see are the length of the lines. You will notice that the arrow from A' to A has a slightly greater length than the others. This is not due to an inaccuracy from TeX but because of the smaller height of A compared to all other nodes who have a prime ' in them.

Setting text height to a fixed length (say .7em) or using text height=height("$A'$") (or $A$?) we can also correct this. We can also use the font key to add a vertical zero-width rule with font=\vphantom{A'} so that every node has at least the height of A'.
There also exists a \mathstrut macro we can use here which is nothing else but \vphantom{(} but this is actually lower as A'.

The big difference between \vphantom and text height/text depth is that the settings of the latter will be forced no matter the content. The \vphantom only stretches the node to a minimum height/depth.

The usage will come down to the content of the nodes and each case. Here I would use height("$A'$").

Also, don’t add \\ after the last line. tikz-cd will insert this itself, another only adds an otherwise empty line and thus vertical space.

Code

\documentclass[tikz,convert=false]{standalone}
\usepackage{tikz-cd}
\usetikzlibrary{calc} % only for the tm style
\tikzset{tm/.style={to path={% Do not use this!
      coordinate (a) -- coordinate[at end] (b)
        (\tikztotarget) \tikztonodes
        let \p1=($(b)-(a)$), \n1={veclen(\p1)} in node[midway] {\footnotesize\n1}}}}
\begin{document}
\begin{tikzcd}[
  text depth=0pt, text height=height("$A'$"),
  column sep={{{{3em,between origins}}}}]
  A' \arrow[tm]{rd} &                    & B'' \arrow[tm]{rd}   & \\ % <- extra & here
                    & A' \arrow[tm]{ld}  &                      & {A}\amalg_{A'}{B''} \arrow[tm]{dl} \\
  A                 &                    & {{A}\amalg_{A'}{B''}} % <- no \\ here
\end{tikzcd}
\end{document}

Output

enter image description here

1
  • @CarLaTeX Interesting. Yes, \heightof doesn't work here, use PGF's own height function here. Also, a backslash seems to have been vanished. Mar 7, 2017 at 23:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .