3

I would like to draw a cube with TikZ-cd. The entries have different sizes, which causes the same problems as in my former question, because I want the arrows to be parallel.

 \[\begin{tikzcd}[row sep=25,column sep=0,nodes={inner sep=2pt},
      cells={nodes={align=center,text width=\widthof{$X_2 \times_{S_2} Y_2$}}}]
    & X_1 \times_{S_1} Y_1  \ar{rr} \ar{dd} \ar{dl} & &   Y_1  \ar{dd} \ar{dl} \\
    X_1 \ar[crossing over]{rr} \ar{dd} & & S_1 \\
      & X_2 \times_{S_2} Y_2  \ar{rr} \ar{dl} & &  Y_2  \ar{dl} \\
    X_2 \ar{rr} && S_2 \ar[from=uu,crossing over]
 \end{tikzcd}\]

enter image description here

How to achieve that the arrows really end and start at the nodes? Of course they do start and end at the nodes formally, but I mean for example that the upper arrow really ends in the near of Y_1.

4
  • This is a complete duplicate. You already got three answers over there. What do you want to achieve? Please clarify! If you just use \begin{tikzcd}[row sep=25, column sep=25] It looks nice and symmetric.
    – LaRiFaRi
    Mar 20 '15 at 9:05
  • 1
    It is not a duplicate. I want the parallel arrows to be parallel. This doesn't happen without further adjustments, and sep=25 is not enough. Mar 20 '15 at 9:19
  • 1
    The between origins approach is the “right“ one for both this question and your previous question about triangles. I suggest that you accept LaRiFaRi's answer.
    – Augusto
    Apr 2 '15 at 14:30
  • Yes, I agree. Meanwhile I have also used this in my file. Apr 2 '15 at 17:06
7

If you separate your columns not with a certain width between borders, but with a width between origins (centre of nodes), it should look better.

% arara: lualatex

\documentclass{article}
\usepackage{tikz-cd}
\usepackage{lua-visual-debug} % just for proove of symmetry. Without that, you may compile with pdfLaTeX

\begin{document}
\[\begin{tikzcd}[row sep={40,between origins}, column sep={40,between origins}]
      & X_1 \times_{S_1} Y_1 \ar{rr}\ar{dd}\ar{dl} & & Y_1\vphantom{\times_{S_1}} \ar{dd}\ar{dl} \\
    X_1 \ar[crossing over]{rr} \ar{dd} & & S_1 \\
      & X_2 \times_{S_2} Y_2  \ar{rr} \ar{dl} & &  Y_2\vphantom{\times_{S_1}} \ar{dl} \\
    X_2 \ar{rr} && S_2 \ar[from=uu,crossing over]
\end{tikzcd}\]
\end{document}

enter image description here


If you want to have it really realistic, I would recommend to add some perspective tweaking:

% arara: pdflatex

\documentclass{article}
\usepackage{tikz-cd}
\newlength{\perspective}

\begin{document}
\setlength{\perspective}{2pt}
\[\begin{tikzcd}[row sep={40,between origins}, column sep={40,between origins}]
      &[-\perspective] X_1 \times_{S_1} Y_1 \ar{rr}\ar{dd}\ar{dl} &[\perspective] &[-\perspective] Y_1\vphantom{\times_{S_1}} \ar{dd}\ar{dl} \\[-\perspective]
    X_1 \ar[crossing over]{rr} \ar{dd} & & S_1 \\[\perspective]
      & X_2 \times_{S_2} Y_2  \ar{rr} \ar{dl} & &  Y_2\vphantom{\times_{S_1}} \ar{dl} \\[-\perspective]
    X_2 \ar{rr} && S_2 \ar[from=uu,crossing over]
\end{tikzcd}\]
\setlength{\perspective}{5pt}
\[\begin{tikzcd}[row sep={40,between origins}, column sep={40,between origins}]
      &[-\perspective] X_1 \times_{S_1} Y_1 \ar{rr}\ar{dd}\ar{dl} &[\perspective] &[-\perspective] Y_1\vphantom{\times_{S_1}} \ar{dd}\ar{dl} \\[-\perspective]
    X_1 \ar[crossing over]{rr} \ar{dd} & & S_1 \\[\perspective]
      & X_2 \times_{S_2} Y_2  \ar{rr} \ar{dl} & &  Y_2\vphantom{\times_{S_1}} \ar{dl} \\[-\perspective]
    X_2 \ar{rr} && S_2 \ar[from=uu,crossing over]
\end{tikzcd}\]
\setlength{\perspective}{8pt}
\[\begin{tikzcd}[row sep={40,between origins}, column sep={40,between origins}]
      &[-\perspective] X_1 \times_{S_1} Y_1 \ar{rr}\ar{dd}\ar{dl} &[\perspective] &[-\perspective] Y_1\vphantom{\times_{S_1}} \ar{dd}\ar{dl} \\[-\perspective]
    X_1 \ar[crossing over]{rr} \ar{dd} & & S_1 \\[\perspective]
      & X_2 \times_{S_2} Y_2  \ar{rr} \ar{dl} & &  Y_2\vphantom{\times_{S_1}} \ar{dl} \\[-\perspective]
    X_2 \ar{rr} && S_2 \ar[from=uu,crossing over]
\end{tikzcd}\]
\setlength{\perspective}{11pt}
\[\begin{tikzcd}[row sep={40,between origins}, column sep={40,between origins}]
      &[-\perspective] X_1 \times_{S_1} Y_1 \ar{rr}\ar{dd}\ar{dl} &[\perspective] &[-\perspective] Y_1\vphantom{\times_{S_1}} \ar{dd}\ar{dl} \\[-\perspective]
    X_1 \ar[crossing over]{rr} \ar{dd} & & S_1 \\[\perspective]
      & X_2 \times_{S_2} Y_2  \ar{rr} \ar{dl} & &  Y_2\vphantom{\times_{S_1}} \ar{dl} \\[-\perspective]
    X_2 \ar{rr} && S_2 \ar[from=uu,crossing over]
\end{tikzcd}\]
\end{document}

enter image description here


Actually, you should even rotate it a bit into isometric view. I guess, there are other solutions for TikZ around. But just to be complete:

% arara: pdflatex

\documentclass[twocolumn]{article}
\usepackage{tikz-cd}
\newlength{\perspective}

\begin{document}
    \setlength{\perspective}{12pt}
    \def\isofactor{0.5}
    \[\begin{tikzcd}[row sep={38,between origins}, column sep={38,between origins}]
    &[-\perspective] X_1 \times_{S_1} Y_1 \ar{rrd}\ar{dddd}\ar{ddl} &[\perspective] &[-\perspective] \\[-38+\isofactor\perspective]
    & & & Y_1\vphantom{\times_{S_1}} \ar{dddd}\ar{ddl} & \\[-\perspective-\isofactor\perspective]
    X_1 \ar[crossing over]{rrd} \ar{dddd} & & & \\[-38+\isofactor\perspective]
    & &  S_1 \\[\perspective-\isofactor\perspective]
    & X_2 \times_{S_2} Y_2  \ar{rrd} \ar{ddl} & &  \\[-38+\isofactor\perspective]
    & & & Y_2\vphantom{\times_{S_1}} \ar{ddl} \\[-\perspective-\isofactor\perspective]
    X_2 \ar{rrd} & & \\[-38+\isofactor\perspective]
    & & S_2 \ar[from=uuuu,crossing over] &
    \end{tikzcd}\]
    \setlength{\perspective}{10pt}
    \def\isofactor{1}
    \[\begin{tikzcd}[row sep={38,between origins}, column sep={38,between origins}]
    &[-\perspective] X_1 \times_{S_1} Y_1 \ar{rrd}\ar{dddd}\ar{ddl} &[\perspective] &[-\perspective] \\[-38+\isofactor\perspective]
    & & & Y_1\vphantom{\times_{S_1}} \ar{dddd}\ar{ddl} & \\[-\perspective-\isofactor\perspective]
    X_1 \ar[crossing over]{rrd} \ar{dddd} & & & \\[-38+\isofactor\perspective]
    & &  S_1 \\[\perspective-\isofactor\perspective]
    & X_2 \times_{S_2} Y_2  \ar{rrd} \ar{ddl} & &  \\[-38+\isofactor\perspective]
    & & & Y_2\vphantom{\times_{S_1}} \ar{ddl} \\[-\perspective-\isofactor\perspective]
    X_2 \ar{rrd} & & \\[-38+\isofactor\perspective]
    & & S_2 \ar[from=uuuu,crossing over] &
    \end{tikzcd}\]
    \vfill\break        
    \setlength{\perspective}{8pt}
    \def\isofactor{1.5}
    \[\begin{tikzcd}[row sep={38,between origins}, column sep={38,between origins}]
    &[-\perspective] X_1 \times_{S_1} Y_1 \ar{rrd}\ar{dddd}\ar{ddl} &[\perspective] &[-\perspective] \\[-38+\isofactor\perspective]
    & & & Y_1\vphantom{\times_{S_1}} \ar{dddd}\ar{ddl} & \\[-\perspective-\isofactor\perspective]
    X_1 \ar[crossing over]{rrd} \ar{dddd} & & & \\[-38+\isofactor\perspective]
    & &  S_1 \\[\perspective-\isofactor\perspective]
    & X_2 \times_{S_2} Y_2  \ar{rrd} \ar{ddl} & &  \\[-38+\isofactor\perspective]
    & & & Y_2\vphantom{\times_{S_1}} \ar{ddl} \\[-\perspective-\isofactor\perspective]
    X_2 \ar{rrd} & & \\[-38+\isofactor\perspective]
    & & S_2 \ar[from=uuuu,crossing over] &
    \end{tikzcd}\]
    \setlength{\perspective}{6pt}
    \def\isofactor{2}
    \[\begin{tikzcd}[row sep={38,between origins}, column sep={38,between origins}]
    &[-\perspective] X_1 \times_{S_1} Y_1 \ar{rrd}\ar{dddd}\ar{ddl} &[\perspective] &[-\perspective] \\[-38+\isofactor\perspective]
    & & & Y_1\vphantom{\times_{S_1}} \ar{dddd}\ar{ddl} & \\[-\perspective-\isofactor\perspective]
    X_1 \ar[crossing over]{rrd} \ar{dddd} & & & \\[-38+\isofactor\perspective]
    & &  S_1 \\[\perspective-\isofactor\perspective]
    & X_2 \times_{S_2} Y_2  \ar{rrd} \ar{ddl} & &  \\[-38+\isofactor\perspective]
    & & & Y_2\vphantom{\times_{S_1}} \ar{ddl} \\[-\perspective-\isofactor\perspective]
    X_2 \ar{rrd} & & \\[-40+\isofactor\perspective]
    & & S_2 \ar[from=uuuu,crossing over] &
    \end{tikzcd}\]
\end{document}

enter image description here

3
  • Thank you! This is a nice alternative. What does 'between origins' mean? Seems to be quite important in this solution, since otherwise the cube becomes non-parallel shaped again. Mar 20 '15 at 9:41
  • @MartinBrandenburg You are welcome. The between origins set the row sep or column sep between the very centres of the nodes/cells. Like this, they will behave like corners of a real cube. The default is to set the separator in between the borders. Just plot A & BBBBBBBBB & C & D and you will see the difference for between borders and between origins.
    – LaRiFaRi
    Mar 20 '15 at 9:53
  • Ah, that is an interesting option! Mar 20 '15 at 10:41
4

You can play with start anchor and end anchor.

MWE:

\documentclass{article}
\usepackage{tikz-cd}
\begin{document}
 \[\begin{tikzcd}[row sep=25,column sep=0,nodes={inner sep=2pt},
      cells={nodes={align=center,text width=\widthof{$X_2 \times_{S_2} Y_2$}}}]
    & X_1 \times_{S_1} Y_1  \ar[end anchor={[xshift=15pt]}]{rr} \ar{dd} \ar{dl} & &   Y_1  \ar{dd} \ar{dl} \\
    X_1 \ar[crossing over,start anchor={[xshift=-15pt]},end anchor={[xshift=15pt]}]{rr} \ar{dd} & & S_1 \\
      & X_2 \times_{S_2} Y_2  \ar[end anchor={[xshift=15pt]}]{rr} \ar{dl} & &  Y_2  \ar{dl} \\
    X_2 \ar[start anchor={[xshift=-15pt]},end anchor={[xshift=15pt]}]{rr} && S_2 \ar[from=uu,crossing over]
 \end{tikzcd}\]
\end{document} 

enter image description here

1
  • @MartinBrandenburg You're welcome Mar 20 '15 at 9:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.