Forgot password?
 Create new account
View 1647|Reply 2

杨辉三角

[Copy link]

701

Threads

110K

Posts

910K

Credits

Credits
94177
QQ

Show all posts

kuing Posted at 2019-11-14 16:07:28 |Read mode
585:
QQ截图20191114160250.jpg
咋画
kuing: 嗯,咋画呢?
585: 嗯,咋画呢?
kuing: 除了暴力tikz外有啥办法吗?
585: 只能矩阵现随便搞一个了
kuing: [笑哭]
……
585: 网上有两个复杂的版本
texample.net/tikz/examples/pascals-triangle-a … sierpinski-triangle/

太高端了
kuing:

701

Threads

110K

Posts

910K

Credits

Credits
94177
QQ

Show all posts

 Author| kuing Posted at 2019-11-14 16:19:15
其实仔细看下链接里的代码,也不算是高深,应该说是花俏。
去掉那些装饰之后,剩下的东西其实很简单,再经补上左边的东西之后,代码如下:
  1. \begin{tikzpicture}[x=2em,y=\baselineskip]
  2. \foreach \row in {1,...,10} {
  3.     \node (L-\row) at (-8,-\row) {$(a+b)^{\row}$};
  4.     \node (R-\row) at (-\row/2,-\row) {1};
  5.     \draw[line width=1pt,loosely dotted] (L-\row)--(R-\row);
  6.     \pgfmathsetmacro{\val}{1};
  7.     \foreach \col in {1,...,\row} {
  8.       % iterative formula : val = precval * (row-col+1)/col
  9.       % (+ 0.5 to bypass rounding errors)
  10.       \pgfmathtruncatemacro{\val}{\val*((\row-\col+1)/\col)+0.5};
  11.       \global\let\val=\val
  12.       \node at (-\row/2+\col,-\row) {\val};
  13.       }}
  14. \end{tikzpicture}
Copy the Code
效果:
QQ截图20191114161904.png

65

Threads

414

Posts

3556

Credits

Credits
3556

Show all posts

Tesla35 Posted at 2019-11-14 16:30:17
这么简洁的?

手机版Mobile version|Leisure Math Forum

2025-4-20 22:28 GMT+8

Powered by Discuz!

× Quick Reply To Top Return to the list