帕斯卡三角形 + 斐波那契数

帕斯卡三角形 + 斐波那契数

我该如何在 LaTeX 中绘制带有倾斜线条的这幅图?有什么提示吗?

在此处输入图片描述

答案1

编辑:按照 percusse 和 Heiko 的建议\ifthenelse进行更改。\ifnum

\documentclass[tikz,border=2mm]{standalone}
\begin{document}
    \begin{tikzpicture}
        \foreach \n in {0,...,6} {
            \foreach \k in {0,...,\n} {
                \node (\n\k) at (\k,-\n) {${\n \choose \k}$};
                \pgfmathtruncatemacro{\x}{(\n+1)/2}
                \pgfmathtruncatemacro{\y}{\n/2}
                \ifnum\k=0 \draw (\n\k.south west) -- (\x\y.north east);\fi
            }
        }
    \end{tikzpicture}
\end{document}

编辑2:按照Misch的建议消除了if语句:

\documentclass[tikz,border=2mm]{standalone}
\begin{document}
    \begin{tikzpicture}
        \foreach \n in {0,...,6} {
            \foreach \k in {0,...,\n} {
                \node (\n\k) at (\k,-\n) {${\n \choose \k}$};
            }
            \pgfmathtruncatemacro{\x}{(\n+1)/2}
            \pgfmathtruncatemacro{\y}{\n/2}
            \draw (\n0.south west) -- (\x\y.north east);
        }
    \end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

我认为这并不是 OP 所要求的,但它很类似......

\documentclass{book}
\usepackage{mathtools}
\usepackage{cancel}


\begin{document}
\LARGE \boldmath
% horizontal loop
\foreach \x in {0,...,6} {%
% vertical loop

\foreach \y in {0,...,\x} {%
$\cancel{\binom{\x}{\y}}$
}

}

\end{document}

在此处输入图片描述

答案3

\documentclass{article}
\usepackage{cancel,mathtools,stackengine}
\stackMath
\def\CBN#1#2{%
  \cancel{\addstackgap[6pt]{\kern6pt\displaystyle\binom{#1}{#2}\kern6pt}}%
  }
\def\BN#1#2{%
  \addstackgap[6pt]{\kern6pt\displaystyle\binom{#1}{#2}\kern6pt}%
  }
\begin{document}
\[
\def\stackalignment{l}
\setstackgap{S}{-5.2pt}
\setstackEOL{\cr}
\Shortstack{
\CBN{0}{0}\cr
\CBN{1}{0}\CBN{1}{1}\cr
\CBN{2}{0}\CBN{2}{1}\CBN{2}{2}\cr
\CBN{3}{0}\CBN{3}{1}\CBN{3}{2}\CBN{3}{3}\cr
\CBN{4}{0}\CBN{4}{1}\CBN{4}{2}\BN{4}{3}\BN{4}{4}\cr
\CBN{5}{0}\CBN{5}{1}\BN{5}{2}\BN{5}{3}\BN{5}{4}\BN{5}{5}\cr
\CBN{6}{0}\BN{6}{1}\BN{6}{2}\BN{6}{3}\BN{6}{4}\BN{6}{5}\BN{6}{6}
}
\]
\end{document}

在此处输入图片描述

相关内容