1

I am a bit new to tikz environment, but following the advices of the good experts of this site I am trying to replace all my commutative diagrams built with the amscd package with ones built with the tikzcd package.

Unfortunately, I notice the choice by default of the arrow lengths in tickcd IMHO looks less nice than the one in amscd in some instances.

Here is an MWE

\documentclass[11pt]{amsart}
\usepackage{amscd}

\usepackage{tikz-cd}

\begin{document}

\[\begin{CD}
    \kappa(q)=B_{q}/qB_{q}@<<< B_{q}\\
    @AAA @AAA\\
    B\otimes \kappa(p)=B_{p}/pB_{p}@<<< B\otimes A_{p}\\
    @AAA @AAA \\
    \kappa(p)=A_{p}/pA_{p}@<<< A_{p}
\end{CD}\]

\[\begin{tikzcd}
\kappa(q)=B_{q}/qB_{q}& B_{q}\ar[l]\\
B\otimes \kappa(p)=B_{p}/pB_{p}\ar[u]& B\otimes A_{p}\ar[u]\ar[l]\\
\kappa(p)=A_{p}/pA_{p}\ar[u]&A_{p}\ar[u]\ar[l]
\end{tikzcd}\]

\end{document} 

Here is my question : I know I can fiddle with the length of each of the horizontal arrows in the tikzcd diagram, in order to have them neatly aligned and roughly the same, like they appear in the amscd package (that seems to choose the minimum length of the horizontal arrows in a column). I want to have this behavior by default at the level of the whole diagram, or/and the document. What should I do ?

Edit : following the advice of egreg, now I just would like to know if there is a default parameter in tikzcd for a diagram and / or the whole document to allow more spaces between arrows tails and tips and nodes (the opposite of cramped option?)? I do not see that in the documentation.

2
  • The fact that the arrows extend to fill the available space is a feature (desirable, in my opinion).
    – egreg
    Sep 9, 2015 at 17:18
  • @egreg I was afraid you would say that :) In that case, I think I just need to train my sense of "neatness" to accept this feature and consider that the amscd formatting was the "primitive" way of doing things for lack of a better tool. I think soon it will appear to me as a much better & neater way of formatting diagrams (which is already clear in some instance). It is like getting a new phone (but I still miss the old HP calculators ...). So no need to spend time answering this question that I will edit for a much simpler one.
    – brunoh
    Sep 9, 2015 at 17:27

2 Answers 2

2

As egreg mentions in his comment, tikz-cd makes the arrows extend to fill the available space and (I agree with him) this is a desirable feature.

Regarding the second part of the question, you can use \tikzcdset to pass options to the path /tikz/commutative diagrams so they will affect all tikzcd diagrams; in the case of your question, you can use shorten:

\tikzcdset{
  shorten >= 5pt,
  shorten <= 5pt,
}

A complete example:

\documentclass[11pt]{amsart}
\usepackage{amscd}
\usepackage{tikz-cd}

\tikzcdset{
  shorten >= 5pt,
  shorten <= 5pt,
}

\begin{document}

\[\begin{CD}
    \kappa(q)=B_{q}/qB_{q}@<<< B_{q}\\
    @AAA @AAA\\
    B\otimes \kappa(p)=B_{p}/pB_{p}@<<< B\otimes A_{p}\\
    @AAA @AAA \\
    \kappa(p)=A_{p}/pA_{p}@<<< A_{p}
\end{CD}\]

\[\begin{tikzcd}
\kappa(q)=B_{q}/qB_{q}& B_{q}\ar[l]\\
B\otimes \kappa(p)=B_{p}/pB_{p}\ar[u]& B\otimes A_{p}\ar[u]\ar[l]\\
\kappa(p)=A_{p}/pA_{p}\ar[u]&A_{p}\ar[u]\ar[l]
\end{tikzcd}\]

\end{document}

enter image description here

If you want to use this options locally, use them in the optional argument of tikzcd:

\documentclass[11pt]{amsart}
\usepackage{amscd}
\usepackage{tikz-cd}

\begin{document}

\[\begin{CD}
    \kappa(q)=B_{q}/qB_{q}@<<< B_{q}\\
    @AAA @AAA\\
    B\otimes \kappa(p)=B_{p}/pB_{p}@<<< B\otimes A_{p}\\
    @AAA @AAA \\
    \kappa(p)=A_{p}/pA_{p}@<<< A_{p}
\end{CD}\]

\[\begin{tikzcd}[  shorten >= 5pt,shorten <= 5pt]
\kappa(q)=B_{q}/qB_{q}& B_{q}\ar[l]\\
B\otimes \kappa(p)=B_{p}/pB_{p}\ar[u]& B\otimes A_{p}\ar[u]\ar[l]\\
\kappa(p)=A_{p}/pA_{p}\ar[u]&A_{p}\ar[u]\ar[l]
\end{tikzcd}\]

\end{document}
4
  • Clear answer ! Before accepting your answer, one small complement to my question's edit : how is it possible to do this only for the horizontal arrows ?
    – brunoh
    Sep 9, 2015 at 17:57
  • 1
    @brunoh This I'd have to think about; it's not immediate to apply these options by default to just a subset of the arrows. Sep 9, 2015 at 18:04
  • 1
    I think you can apply shorten just to a single arrow; but I don't think it's possible to distinguish between horizontal and vertical ones “globally”.
    – egreg
    Sep 9, 2015 at 18:08
  • @GonzaloMedina Ok. I will go with that, and follow your opinion and the one of egreg to change my appreciation of arrow filling spaces.
    – brunoh
    Sep 9, 2015 at 19:00
1

There is also the psmatrix solution, from pst-node. Here are two ways of writing this diagram. As opposed to tikz-cd, the structure of the code describes first the nodes, then the arrows;

\documentclass[11pt]{amsart}

\usepackage{mathtools}
\usepackage{pst-node}
\usepackage{auto-pst-pdf}

\begin{document}
\psset{linewidth=0.6pt, arrowinset=0.2, arrowsize=2.5pt 2, arrows=->,nodesep=4pt}
\[
  \begin{psmatrix}
    %%% Nodes
    \kappa(q)=B_{q}/qB_{q}& B_{q}\\
    B\otimes \kappa(p)=B_{p}/pB_{p} & B\otimes A_{\mathrlap{p}}\\
    \kappa(p)=A_{p}/pA_{p}&A_{p}
    %%% Vertical arrows
    \ncline{2,1}{1,1}\ncline{2,2}{1,2}
    \ncline{3,1}{2,1}\ncline{3,2}{2,2}
    %%% Horizontal arrows
    \ncline{2,2}{2,1}
    \psset{nodesep=8pt}\ncline{1,2}{1,1}\ncline{3,2}{3,1}
  \end{psmatrix}\]


  \vskip1cm
  \[
    \begin{psmatrix}
      %%% Nodes
      \mathllap{\kappa(q)=}B_{q}/qB_{q}& B_{q}\\
      \mathllap{B\otimes \kappa(p)=}B_{p}/pB_{p} & B\otimes A_{p}\\
      \mathllap{\kappa(p)=}A_{p}/pA_{p}&A_{p}
      %%% Vertical arrows
      \ncline{2,1}{1,1}\ncline{2,2}{1,2}
      \ncline{3,1}{2,1}\ncline{3,2}{2,2}
      %%% Horizontal arrows
      \ncline{2,2}{2,1}
      \psset{nodesep=8pt}\ncline{1,2}{1,1}\ncline{3,2}{3,1}
    \end{psmatrix}\]

\end{document} 

enter image description here

5
  • +1 Very nice ! (I prefer the first version). Now I am haunted by this new metaphysical question : which package should I invest time in to learn ? tikz-cd or pst-node ? My needs are strictly for commutative diagrams in maths (for the moment). Where can I ponder advantages of each one of them ? Is pst-node well maintained and compatible with everything ? etc ...
    – brunoh
    Sep 9, 2015 at 19:13
  • 1
    I tried both. I had difficulties trying to customise tikz-cd, I suppose mainly because the programming language is different from latex, while pstricks is an interface between latex and postscript with latex-like commands so my opinion is it is easier to learn for a plain latex-user. Note that to make it work directly with pdflatex, you must use the -shell-escape switch (or --enable-write18 under MiKTeX), but it works natively under xelatex. Last point: there is a rich documentation, with many examples, but it is scattered among the different pstricks packages.
    – Bernard
    Sep 9, 2015 at 19:34
  • +1 Then I will do my homework (I noticed the \write18 problem and the multiple messages appearing on my console + more time for the typesetting process which is a bit an issue ...). What is clear for me is that if I want to customize a bit tikz-cd I have to go through tikz learning quite seriously ...
    – brunoh
    Sep 9, 2015 at 19:40
  • 1
    For the processing time, usually I write my diagrams as standalone files, and then include the corresponding pdfs. Usually, the write18 problem is a problem of configuration through the editor. It is not enabled by default for security reasons (personally I never had any problem…)
    – Bernard
    Sep 9, 2015 at 19:47
  • +1 Useful tips. (I solved \write18 through the editor option as suggested).
    – brunoh
    Sep 9, 2015 at 19:50

You must log in to answer this question.

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