我在一个环境中有一个通信图tikzcd
,这里是代码:
\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}
但是,输出是扭曲的并且不适合页面:
我想要绘制的图表在这里 https://tinyurl.com/znyhpd5c
答案1
您可以使用between origins
并进行一些调整。
以下仍然会产生 60pt 的溢出,解决方法取决于你。
\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}
注意辅助本地宏可以简化输入。您可以轻松更改序数标记的位置(请不要使用上标)。