라텍스에서 파스칼의 삼각형을 사용하여 구멍이 있는 통로 그리드를 만들려고 합니다. 나침반도요

라텍스에서 파스칼의 삼각형을 사용하여 구멍이 있는 통로 그리드를 만들려고 합니다. 나침반도요

아래 그림은 내가 무엇을 하려는지에 대한 아이디어를 제공합니다.

또한 이 특정 질문에 어떤 태그를 사용해야 할지 잘 모르겠습니다.

새 사진

내가 사용하는 코드:

 \documentclass[28pt]{article}

 \usepackage{fancyhdr}

 \usepackage[includeheadfoot,margin=1.0cm]{geometry} 
 \usepackage{amsmath,amsthm,amssymb}
 \usepackage{enumitem}
 \usepackage{mathtools}
 \usepackage{framed}
 \usepackage{chessfss} %chess figure for HW #2
 \usepackage[english]{babel} %table for problem A.43
 \usepackage{multirow} %table for problem A.43
%\usepackage[table]{xcolor} color certain blocks in a table
%\usepackage[pass,showframe]{geometry}  just to show the margins
 \usepackage[makeroom]{cancel}
 \usepackage{array}  %BETWEEN TWO 2-DIGIT NUMBERS

 \newcommand{\N}{\mathbb{N}}
 \newcommand{\Z}{\mathbb{Z}}
 \newcommand{\thedate}{\today}

 \newtheoremstyle{case}{}{}{}{}{}{:}{ }{}
 \theoremstyle{case}
 \newtheorem{case}{Case}


 \newenvironment{theorem}[2][Theorem]{\begin{trivlist}
 \item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
 \newenvironment{lemma}[2][Lemma]{\begin{trivlist}
 \item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
 \newenvironment{exercise}[2][Exercise]{\begin{trivlist}
 \item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
 \newenvironment{problem}[2][Problem]{\begin{trivlist}
 \item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
 \newenvironment{question}[2][Question]{\begin{trivlist}
 \item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
 \newenvironment{corollary}[2][Corollary]{\begin{trivlist}
 \item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}

 \begin{document}

 \end{document}

답변1

나는 이것이 효과가 있다고 생각합니다:

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{math}
\begin{document}
\begin{tikzpicture}[x=2cm,y=-2cm, node 0/.style={fill=red!20}]
\tikzmath{%
  int \i, \j, \m, \n, \t;
  \m = 6; \n = 6;
  % Initialise board.
  for \i in {0,...,\m}{
    for \j in {0,...,\n}{
      \t{\i,\j} = 0;
    };
  };
  % Create holes.
  \t{0,3} = -1;
  \t{4,4} = -1;
  \t{5,1} = -1;
  \t{2,5} = -1;
  % Perform calculations.
  for \i1 in {0,...,\m}{
    for \j1 in {0,...,\n}{
      if (\t{\i1,\j1} == -1) then {
          \t{\i1,\j1} = 0;
      } else {
        if (\i1 == 0 || \j1 == 0) then  {
          \t{\i1,\j1} = 1;            
        } else {
          \i2 = \i1 - 1;
          \j2 = \j1 - 1;
          \t{\i1,\j1} = \t{\i2,\j1} + \t{\i1,\j2}; 
        };
      };
    };
  };
  % Draw nodes.
  for \i1 in {0,...,\m}{
    for \j1 in {0,...,\n}{
    { \node [circle, fill=blue!20, minimum size=1cm, node \t{\i1,\j1}/.try] 
        (n-\i1-\j1) at (\j1, \i1) {\t{\i1,\j1}}; };
    };   
  };
  % Draw edges.
  for \i1 in {0,...,\m}{
    for \j1 in {0,...,\n}{
      \i2 = \i1 + 1;
      \j2 = \j1 + 1;
      if (\i1 < \m) then {
        if (\t{\i2,\j1} > 0) then { 
              { \draw [thick, -stealth] (n-\i1-\j1) -- (n-\i2-\j1); };
          }; 
        };
        if (\j1 < \n) then {
        if (\t{\i1,\j2} > 0) then { 
              { \draw [thick, -stealth] (n-\i1-\j1) -- (n-\i1-\j2); };
        }; 
      };
    };
  };
}
\end{tikzpicture}
\end{document}

여기에 이미지 설명을 입력하세요

'구멍'이 없으면 훨씬 더 간단하게 수행할 수 있습니다.

\documentclass[tikz,border=5]{standalone}
\usepackage{xintexpr}
\begin{document}
\begin{tikzpicture}[x=2cm,y=2cm]
\draw [help lines] grid [step=1] (6,-6);
\foreach \x in {0,...,6}
  \foreach \y in {0,...,6}
    \node [circle, fill=blue!20, minimum size=1cm]
      at (\x, -\y) {\xinttheiiexpr binomial(\x+\y,\x)\relax};
\end{tikzpicture}
\end{document}

여기에 이미지 설명을 입력하세요

관련 정보