2

I have a communicative graph in a tikzcd environment, here is the code:

\begin{tikzcd}[row sep=5ex, column sep=0.01ex]
                                       &                                  &                         &                                   &                          &                                   &                          &                                   &                                                    & \text{Drop the coins}             &                          &                                              &                          &                                   &                         &                                  &                         &                          \\
1^\text{st}\text{ Layer}               &                                  &                         &                                   &                          &                                   &                          &                                   &                                                    & 1 \arrow[ld] \arrow[rd]           &                          &                                              &                          &                                   &                         &                                  &                         &                          \\
2^\text{nd}\text{ Layer}               &                                  &                         &                                   &                          &                                   &                          &                                   & 1 \arrow[ld] \arrow[rd]                            &                                   & 1 \arrow[rd] \arrow[ld]  &                                              &                          &                                   &                         &                                  &                         &                          \\
3^\text{rd}\text{ Layer}               &                                  &                         &                                   &                          &                                   &                          & 1 \arrow[ld] \arrow[rd]           &                                                    & 2 \arrow[ld] \arrow[rd]           &                          & 1 \arrow[ld] \arrow[rd]                      &                          &                                   &                         &                                  &                         &                          \\
4^\text{th}\text{ Layer}               &                                  &                         &                                   &                          &                                   & 1 \arrow[ld] \arrow[rd]  &                                   & 3 \arrow[ld, Rightarrow] \arrow[rd, dashed, hook'] &                                   & 3 \arrow[ld] \arrow[rd]  &                                              & 1 \arrow[ld] \arrow[rd]  &                                   &                         &                                  &                         &                          \\
5^\text{th}\text{ Layer}               &                                  &                         &                                   &                          & 1 \arrow[ld] \arrow[rd]           &                          & 7 \arrow[ld] \arrow[rd]           &                                                    & 3 \arrow[ld] \arrow[rd]           &                          & 4 \arrow[ld] \arrow[rd]                      &                          & 1 \arrow[ld] \arrow[rd]           &                         &                                  &                         &                          \\
6^\text{th}\text{ Layer}               &                                  &                         &                                   & 1 \arrow[ld] \arrow[rd]  &                                   & 8 \arrow[ld] \arrow[rd]  &                                   & 10 \arrow[ld] \arrow[rd]                           &                                   & 7 \arrow[ld] \arrow[rd]  &                                              & 5 \arrow[ld] \arrow[rd]  &                                   & 1 \arrow[ld] \arrow[rd] &                                  &                         &                          \\
7^\text{th}\text{ Layer}               &                                  &                         & 1 \arrow[ld] \arrow[rd]           &                          & 9 \arrow[ld] \arrow[rd]           &                          & 18 \arrow[ld] \arrow[rd]          &                                                    & 17 \arrow[ld] \arrow[rd]          &                          & 12 \arrow[ld, dashed] \arrow[rd, Rightarrow] &                          & 6 \arrow[ld] \arrow[rd]           &                         & 1 \arrow[ld] \arrow[rd]          &                         &                          \\
8^\text{th}\text{ Layer}               &                                  & 1 \arrow[ld] \arrow[rd] &                                   & 10 \arrow[ld] \arrow[rd] &                                   & 27 \arrow[ld] \arrow[rd] &                                   & 35 \arrow[ld] \arrow[rd]                           &                                   & 17 \arrow[ld] \arrow[rd] &                                              & 30 \arrow[ld] \arrow[rd] &                                   & 7 \arrow[ld] \arrow[rd] &                                  & 1 \arrow[ld] \arrow[rd] &                          \\
9^\text{th}\text{ Layer}               & 1                                &                         & 11                                &                          & 37                                &                          & 62                                &                                                    & 52                                &                          & 47                                           &                          & 37                                &                         & 8                                &                         & 1                        \\
\text{Outcome}                         & 1^\text{st}\text{ Slot}          &                         & 2^\text{nd}\text{ Slot}           &                          & 3^\text{rd}\text{ Slot}           &                          & 4^\text{th}\text{ Slot}           &                                                    & 5^\text{th}\text{ Slot}           &                          & 6^\text{th}\text{ Slot}                      &                          & 7^\text{th}\text{ Slot}           &                         & 8^\text{th}\text{ Slot}          &                         & 9^\text{th}\text{ Layer} \\
\text{Probability of hitting it once}  & \frac{1}{2^{9-1}}                &                         & \frac{11}{2^{9-1}}                &                          & \frac{37}{2^{9-1}}                &                          & \frac{62}{2^{9-1}}                &                                                    & \frac{52}{2^{9-1}}                &                          & \frac{47}{2^{9-1}}                           &                          & \frac{37}{2^{9-1}}                &                         & \frac{8}{2^{9-1}}                &                         & \frac{1}{2^{9-1}}        \\
\text{Probability of hitting it twice} & \left(\frac{1}{2^{9-1}}\right)^2 &                         & \left(\frac{11}{2^{9-1}}\right)^2 &                          & \left(\frac{37}{2^{9-1}}\right)^2 &                          & \left(\frac{62}{2^{9-1}}\right)^2 &                                                    & \left(\frac{52}{2^{9-1}}\right)^2 &                          & \left(\frac{47}{2^{9-1}}\right)^2            &                          & \left(\frac{37}{2^{9-1}}\right)^2 &                         & \left(\frac{8}{2^{9-1}}\right)^2 &                         & \frac{1}{2^{9-1}}       
\end{tikzcd}

However, the output is distorted and does not fit onto the page:

enter image description here

The diagram I'm trying to draw is here https://tinyurl.com/znyhpd5c

JamesT
  • 3,169
  • 3
    Welcome! I'd argue it's not distorted. Every column gets the space the widest node requires. (The same is true for the vertical dimension but less noticeable here.) Try column sep={2.3em,between origins}, /tikz/column 1/.append style={nodes={anchor=base east}} as options to your tikzcd environment. (The Drop the coins node is the doing most damage. You can also add |[overlay]| to the this cell only but that still makes the columns of different width. Or you could remove that node from the matrix and add it as a label to the matrix. But I think you should use between origins anyway.) – Qrrbrbirlbel May 17 '23 at 15:20
  • It worked thank you! – Andi Tse May 17 '23 at 18:42

1 Answers1

3

You can use between origins and some more adjustments.

The following still yields an overfull by 60pt, solving it is up to you.

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

\begin{document}

\begin{center} \newcommand{\ly}[2]{\text{#1#2 Layer}} \newcommand{\st}[2]{\smash{\begin{tabular}{@{}c@{}}#1#2 \Slot\end{tabular}}} \newcommand{\prob}[1]{\smash{\begin{tabular}{@{}l@{}}Probability of\hitting it #1\end{tabular}}} \newcommand{\pb}[1]{\frac{#1}{2^{9-1}}} \newcommand{\pbb}[1]{\left(\frac{#1}{2^{9-1}}\right)^{2}}

\begin{tikzcd}[ row sep=5ex, column sep={1.8em,between origins}, /tikz/column 1/.append style={nodes={anchor=base west}}, ] &[7.5em] &&&&&&&& \makebox[0pt]{Drop the coins} \[-4ex] \ly{1}{st} & & & & & & & & & 1 \ar[ld] \ar[rd] & & & & & & & & \ \ly{2}{nd} & & & & & & & & 1 \ar[ld] \ar[rd] & & 1 \ar[rd] \ar[ld] & & & & & & & \ \ly{3}{rd} & & & & & & & 1 \ar[ld] \ar[rd] & & 2 \ar[ld] \ar[rd] & & 1 \ar[ld] \ar[rd] & & & & & & \ \ly{4}{th} & & & & & & 1 \ar[ld] \ar[rd] & & 3 \ar[ld, Rightarrow] \ar[rd, dashed, hook'] & & 3 \ar[ld] \ar[rd] & & 1 \ar[ld] \ar[rd] & & & & & \ \ly{5}{th} & & & & & 1 \ar[ld] \ar[rd] & & 7 \ar[ld] \ar[rd] & & 3 \ar[ld] \ar[rd] & & 4 \ar[ld] \ar[rd] & & 1 \ar[ld] \ar[rd] & & & & \ \ly{6}{th} & & & & 1 \ar[ld] \ar[rd] & & 8 \ar[ld] \ar[rd] & & 10 \ar[ld] \ar[rd] & & 7 \ar[ld] \ar[rd] & & 5 \ar[ld] \ar[rd] & & 1 \ar[ld] \ar[rd] & & & \ \ly{7}{th} & & & 1 \ar[ld] \ar[rd] & & 9 \ar[ld] \ar[rd] & & 18 \ar[ld] \ar[rd] & & 17 \ar[ld] \ar[rd] & & 12 \ar[ld, dashed] \ar[rd, Rightarrow] & & 6 \ar[ld] \ar[rd] & & 1 \ar[ld] \ar[rd] & & \ \ly{8}{th} & & 1 \ar[ld] \ar[rd] & & 10 \ar[ld] \ar[rd] & & 27 \ar[ld] \ar[rd] & & 35 \ar[ld] \ar[rd] & & 17 \ar[ld] \ar[rd] & & 30 \ar[ld] \ar[rd] & & 7 \ar[ld] \ar[rd] & & 1 \ar[ld] \ar[rd] & \ \ly{9}{th} & 1 & & 11 & & 37 & & 62 & & 52 & & 47 & & 37 & & 8 & & 1 \[-3ex] \text{Outcome} & \st{1}{st} & & \st{2}{nd} & & \st{3}{th} & & \st{4}{th} & & \st{5}{th} & & \st{6}{th} & & \st{7}{th} & & \st{8}{th} & & \st{9}{th} \[-2ex] \prob{once} & \pb{1} & & \pb{11} & & \pb{37} & & \pb{62} & & \pb{52} & & \pb{47} & & \pb{37} & & \pb{8} & & \pb{1} \[-2ex] \prob{twice} & \pbb{1} & & \pbb{11} & & \pbb{37} & & \pbb{62} & & \pbb{52} & & \pbb{47} & & \pbb{37} & & \pbb{8} & & \pbb{1} \ \end{tikzcd}

\end{center}

\end{document}

Note the helper local macros to ease input. You can easily change the position of the ordinal markers (don't use superscripts, please).

enter image description here

egreg
  • 1,121,712