How can I draw Pascal's triangle with some its properties?











up vote
4
down vote

favorite
5












At here Pascal's triangle in tikz we can draw Pascal's triangle. Now I want to note some properties of coefficients C_{n+3}^4 -C_{n+2}^4-C_{n+1}^4+C_{n}^4=n^2 (the first picture) as folowing pictures enter image description here



enter image description here



How can I draw this pictures?










share|improve this question




























    up vote
    4
    down vote

    favorite
    5












    At here Pascal's triangle in tikz we can draw Pascal's triangle. Now I want to note some properties of coefficients C_{n+3}^4 -C_{n+2}^4-C_{n+1}^4+C_{n}^4=n^2 (the first picture) as folowing pictures enter image description here



    enter image description here



    How can I draw this pictures?










    share|improve this question


























      up vote
      4
      down vote

      favorite
      5









      up vote
      4
      down vote

      favorite
      5






      5





      At here Pascal's triangle in tikz we can draw Pascal's triangle. Now I want to note some properties of coefficients C_{n+3}^4 -C_{n+2}^4-C_{n+1}^4+C_{n}^4=n^2 (the first picture) as folowing pictures enter image description here



      enter image description here



      How can I draw this pictures?










      share|improve this question















      At here Pascal's triangle in tikz we can draw Pascal's triangle. Now I want to note some properties of coefficients C_{n+3}^4 -C_{n+2}^4-C_{n+1}^4+C_{n}^4=n^2 (the first picture) as folowing pictures enter image description here



      enter image description here



      How can I draw this pictures?







      tikz-pgf






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 13 '17 at 12:35









      Community

      1




      1










      asked Sep 1 '14 at 6:28









      minthao_2011

      2,20142145




      2,20142145






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          9
          down vote



          accepted










          I'll left to you understand the code but next is a possible solution based in Paul Gaborit's example



          %%%%%%%%%%%%%%%%%%%%%%%%%%%
          % Author : Paul Gaborit (2009)
          % under Creative Commons attribution license.
          % Title : Pascal's triangle and Sierpinski triangle
          % Note : 17 lines maximum
          documentclass[border=2mm, tikz]{standalone}
          %usepackage[landscape,margin=1cm]{geometry}
          %pagestyle{empty}
          %usepackage[T1]{fontenc}
          %usepackage{lmodern}

          usepackage{tikz}
          usetikzlibrary{positioning,shadows,backgrounds,shapes.geometric}
          begin{document}
          centering

          %
          % x=sqrt{3/4}*minimum size
          % y=3/4*minimum size
          %
          begin{tikzpicture}[y=7.5mm,x=8.66mm]
          % some colors
          colorlet{even}{cyan!60!black}
          colorlet{odd}{orange!100!black}
          colorlet{links}{red!70!black}
          colorlet{back}{yellow!20!white}
          % some styles
          tikzset{
          box/.style={
          regular polygon,
          regular polygon sides=6,
          minimum size=10mm,
          inner sep=0mm,
          outer sep=0mm,
          text centered,
          font=smallbfseriessffamily,
          text=#1!50!black,
          draw=#1,
          line width=.25mm,
          rotate=30,
          },
          link/.style={black, shorten >=2mm, shorten <=2mm, line width=1mm},
          }
          % Pascal's triangle
          % row #0 => value is 1
          node[box=even] (p-0-0) at (0,0) {rotatebox{-30}{1}};
          foreach row in {1,...,11} {
          % col #0 =&gt; value is 1
          node[box=even] (p-row-0) at (-row/2,-row) {rotatebox{-30}{1}};
          pgfmathsetmacro{myvalue}{1};
          foreach col in {1,...,row} {
          % iterative formula : val = precval * (row-col+1)/col
          % (+ 0.5 to bypass rounding errors)
          pgfmathtruncatemacro{myvalue}{myvalue*((row-col+1)/col)+0.5};
          globalletmyvalue=myvalue
          % position of each value
          coordinate (pos) at (-row/2+col,-row);
          % odd color for odd value and even color for even value
          pgfmathtruncatemacro{rest}{mod(myvalue,2)}
          node[box=even] (p-row-col) at (pos) {rotatebox{-30}{myvalue}};
          }
          }
          begin{pgfonlayer}{background}
          foreach i/j in {4/1,5/1,5/2,6/2,7/6,8/6,8/7,9/7}
          node[box=even,fill=odd] at (p-i-j) {};
          end{pgfonlayer}

          draw[link] (p-4-1.center)--(p-6-2.center);
          draw[link] (p-5-1.center)--(p-5-2.center);
          draw[link] (p-7-6.center)--(p-9-7.center);
          draw[link] (p-8-6.center)--(p-8-7.center);
          node[right=5mm of p-8-8.center, align=left] {$(36-7)+(28-8)=49$};
          node[left=5mm of p-5-0.center, align=right] {$(15-4)+(10-5)=16$};

          end{tikzpicture}

          end{document}


          enter image description here



          (19/11/18) Code updated to avoid problems mentioned in Problem with Pascal triangle example






          share|improve this answer



















          • 1




            hi. There may be a problem in this code, an interaction with some other package. If you have trouble compiling it, see my other post : tex.stackexchange.com/questions/460463/…
            – Nicolas FRANCOIS
            Nov 17 at 18:14










          • Please consider replacing value by something less dangerous (OK, this expression sounds stronger than it should sound, this is not meant to sound strong) since value has a well-defined meaning in many packages/classes, so there could be problems, see e.g. this post. How about myvalue?
            – marmot
            Nov 17 at 18:17










          • @NicolasFRANCOIS Code updated.
            – Ignasi
            yesterday


















          up vote
          11
          down vote













          Not a complete answer, but just intended to show a different way of drawing the triangle and also calculating the values. Requires lualatex:



          documentclass[tikz,border=5]{standalone}
          usetikzlibrary{shapes.geometric}
          directlua{
          function factorial (f)
          if f < 2 then return 1 else return f*factorial(f-1) end
          end

          function nchoosek(n, k)
          return factorial(n) / (factorial(n-k) * factorial(k))
          end
          }
          tikzset{hexagon/.style={
          regular polygon, regular polygon sides=6, shape border rotate=30,
          minimum size=1cm, inner sep=0pt,
          draw, ultra thick, execute at begin node={setbox0hboxbgroup},
          execute at end node={egrouppgfmathparse{min(4ex,wd0)/wd0}%
          scalebox{pgfmathresult}{box0}}
          }}
          begin{document}
          tikz[x=1cm*sin 60, y=1.5cm*cos 60]
          foreach n in {0,...,11}
          foreach k in {0,...,n}
          node [hexagon] at (-n/2+k, -n) {directlua{tex.print("" .. nchoosek(n,k))}};
          end{document}


          enter image description here



          The advantage with using lualatex is that it is possible to bypass the limits on mathematical calculations in PGF (actually in TeX):



          enter image description here






          share|improve this answer





















          • This won't compile at my place as of today. The fix is explained here : add RequirePackage{luatex85} as the very first line, a temporary workaround until standalone is updated.
            – marsupilam
            Oct 25 '16 at 16:29












          • Hi @mark-wibrow, I would like to use your code with a little change: I would like to be able to change the background color of some hexagons, inserting some conditional code. I don't know where to insert it, though. A simple line like "ifthenelse{n=2}{fill=blue!30,}{}" won't work. How could I do?
            – zar
            Nov 2 '16 at 17:31











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "85"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f198887%2fhow-can-i-draw-pascals-triangle-with-some-its-properties%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          9
          down vote



          accepted










          I'll left to you understand the code but next is a possible solution based in Paul Gaborit's example



          %%%%%%%%%%%%%%%%%%%%%%%%%%%
          % Author : Paul Gaborit (2009)
          % under Creative Commons attribution license.
          % Title : Pascal's triangle and Sierpinski triangle
          % Note : 17 lines maximum
          documentclass[border=2mm, tikz]{standalone}
          %usepackage[landscape,margin=1cm]{geometry}
          %pagestyle{empty}
          %usepackage[T1]{fontenc}
          %usepackage{lmodern}

          usepackage{tikz}
          usetikzlibrary{positioning,shadows,backgrounds,shapes.geometric}
          begin{document}
          centering

          %
          % x=sqrt{3/4}*minimum size
          % y=3/4*minimum size
          %
          begin{tikzpicture}[y=7.5mm,x=8.66mm]
          % some colors
          colorlet{even}{cyan!60!black}
          colorlet{odd}{orange!100!black}
          colorlet{links}{red!70!black}
          colorlet{back}{yellow!20!white}
          % some styles
          tikzset{
          box/.style={
          regular polygon,
          regular polygon sides=6,
          minimum size=10mm,
          inner sep=0mm,
          outer sep=0mm,
          text centered,
          font=smallbfseriessffamily,
          text=#1!50!black,
          draw=#1,
          line width=.25mm,
          rotate=30,
          },
          link/.style={black, shorten >=2mm, shorten <=2mm, line width=1mm},
          }
          % Pascal's triangle
          % row #0 => value is 1
          node[box=even] (p-0-0) at (0,0) {rotatebox{-30}{1}};
          foreach row in {1,...,11} {
          % col #0 =&gt; value is 1
          node[box=even] (p-row-0) at (-row/2,-row) {rotatebox{-30}{1}};
          pgfmathsetmacro{myvalue}{1};
          foreach col in {1,...,row} {
          % iterative formula : val = precval * (row-col+1)/col
          % (+ 0.5 to bypass rounding errors)
          pgfmathtruncatemacro{myvalue}{myvalue*((row-col+1)/col)+0.5};
          globalletmyvalue=myvalue
          % position of each value
          coordinate (pos) at (-row/2+col,-row);
          % odd color for odd value and even color for even value
          pgfmathtruncatemacro{rest}{mod(myvalue,2)}
          node[box=even] (p-row-col) at (pos) {rotatebox{-30}{myvalue}};
          }
          }
          begin{pgfonlayer}{background}
          foreach i/j in {4/1,5/1,5/2,6/2,7/6,8/6,8/7,9/7}
          node[box=even,fill=odd] at (p-i-j) {};
          end{pgfonlayer}

          draw[link] (p-4-1.center)--(p-6-2.center);
          draw[link] (p-5-1.center)--(p-5-2.center);
          draw[link] (p-7-6.center)--(p-9-7.center);
          draw[link] (p-8-6.center)--(p-8-7.center);
          node[right=5mm of p-8-8.center, align=left] {$(36-7)+(28-8)=49$};
          node[left=5mm of p-5-0.center, align=right] {$(15-4)+(10-5)=16$};

          end{tikzpicture}

          end{document}


          enter image description here



          (19/11/18) Code updated to avoid problems mentioned in Problem with Pascal triangle example






          share|improve this answer



















          • 1




            hi. There may be a problem in this code, an interaction with some other package. If you have trouble compiling it, see my other post : tex.stackexchange.com/questions/460463/…
            – Nicolas FRANCOIS
            Nov 17 at 18:14










          • Please consider replacing value by something less dangerous (OK, this expression sounds stronger than it should sound, this is not meant to sound strong) since value has a well-defined meaning in many packages/classes, so there could be problems, see e.g. this post. How about myvalue?
            – marmot
            Nov 17 at 18:17










          • @NicolasFRANCOIS Code updated.
            – Ignasi
            yesterday















          up vote
          9
          down vote



          accepted










          I'll left to you understand the code but next is a possible solution based in Paul Gaborit's example



          %%%%%%%%%%%%%%%%%%%%%%%%%%%
          % Author : Paul Gaborit (2009)
          % under Creative Commons attribution license.
          % Title : Pascal's triangle and Sierpinski triangle
          % Note : 17 lines maximum
          documentclass[border=2mm, tikz]{standalone}
          %usepackage[landscape,margin=1cm]{geometry}
          %pagestyle{empty}
          %usepackage[T1]{fontenc}
          %usepackage{lmodern}

          usepackage{tikz}
          usetikzlibrary{positioning,shadows,backgrounds,shapes.geometric}
          begin{document}
          centering

          %
          % x=sqrt{3/4}*minimum size
          % y=3/4*minimum size
          %
          begin{tikzpicture}[y=7.5mm,x=8.66mm]
          % some colors
          colorlet{even}{cyan!60!black}
          colorlet{odd}{orange!100!black}
          colorlet{links}{red!70!black}
          colorlet{back}{yellow!20!white}
          % some styles
          tikzset{
          box/.style={
          regular polygon,
          regular polygon sides=6,
          minimum size=10mm,
          inner sep=0mm,
          outer sep=0mm,
          text centered,
          font=smallbfseriessffamily,
          text=#1!50!black,
          draw=#1,
          line width=.25mm,
          rotate=30,
          },
          link/.style={black, shorten >=2mm, shorten <=2mm, line width=1mm},
          }
          % Pascal's triangle
          % row #0 => value is 1
          node[box=even] (p-0-0) at (0,0) {rotatebox{-30}{1}};
          foreach row in {1,...,11} {
          % col #0 =&gt; value is 1
          node[box=even] (p-row-0) at (-row/2,-row) {rotatebox{-30}{1}};
          pgfmathsetmacro{myvalue}{1};
          foreach col in {1,...,row} {
          % iterative formula : val = precval * (row-col+1)/col
          % (+ 0.5 to bypass rounding errors)
          pgfmathtruncatemacro{myvalue}{myvalue*((row-col+1)/col)+0.5};
          globalletmyvalue=myvalue
          % position of each value
          coordinate (pos) at (-row/2+col,-row);
          % odd color for odd value and even color for even value
          pgfmathtruncatemacro{rest}{mod(myvalue,2)}
          node[box=even] (p-row-col) at (pos) {rotatebox{-30}{myvalue}};
          }
          }
          begin{pgfonlayer}{background}
          foreach i/j in {4/1,5/1,5/2,6/2,7/6,8/6,8/7,9/7}
          node[box=even,fill=odd] at (p-i-j) {};
          end{pgfonlayer}

          draw[link] (p-4-1.center)--(p-6-2.center);
          draw[link] (p-5-1.center)--(p-5-2.center);
          draw[link] (p-7-6.center)--(p-9-7.center);
          draw[link] (p-8-6.center)--(p-8-7.center);
          node[right=5mm of p-8-8.center, align=left] {$(36-7)+(28-8)=49$};
          node[left=5mm of p-5-0.center, align=right] {$(15-4)+(10-5)=16$};

          end{tikzpicture}

          end{document}


          enter image description here



          (19/11/18) Code updated to avoid problems mentioned in Problem with Pascal triangle example






          share|improve this answer



















          • 1




            hi. There may be a problem in this code, an interaction with some other package. If you have trouble compiling it, see my other post : tex.stackexchange.com/questions/460463/…
            – Nicolas FRANCOIS
            Nov 17 at 18:14










          • Please consider replacing value by something less dangerous (OK, this expression sounds stronger than it should sound, this is not meant to sound strong) since value has a well-defined meaning in many packages/classes, so there could be problems, see e.g. this post. How about myvalue?
            – marmot
            Nov 17 at 18:17










          • @NicolasFRANCOIS Code updated.
            – Ignasi
            yesterday













          up vote
          9
          down vote



          accepted







          up vote
          9
          down vote



          accepted






          I'll left to you understand the code but next is a possible solution based in Paul Gaborit's example



          %%%%%%%%%%%%%%%%%%%%%%%%%%%
          % Author : Paul Gaborit (2009)
          % under Creative Commons attribution license.
          % Title : Pascal's triangle and Sierpinski triangle
          % Note : 17 lines maximum
          documentclass[border=2mm, tikz]{standalone}
          %usepackage[landscape,margin=1cm]{geometry}
          %pagestyle{empty}
          %usepackage[T1]{fontenc}
          %usepackage{lmodern}

          usepackage{tikz}
          usetikzlibrary{positioning,shadows,backgrounds,shapes.geometric}
          begin{document}
          centering

          %
          % x=sqrt{3/4}*minimum size
          % y=3/4*minimum size
          %
          begin{tikzpicture}[y=7.5mm,x=8.66mm]
          % some colors
          colorlet{even}{cyan!60!black}
          colorlet{odd}{orange!100!black}
          colorlet{links}{red!70!black}
          colorlet{back}{yellow!20!white}
          % some styles
          tikzset{
          box/.style={
          regular polygon,
          regular polygon sides=6,
          minimum size=10mm,
          inner sep=0mm,
          outer sep=0mm,
          text centered,
          font=smallbfseriessffamily,
          text=#1!50!black,
          draw=#1,
          line width=.25mm,
          rotate=30,
          },
          link/.style={black, shorten >=2mm, shorten <=2mm, line width=1mm},
          }
          % Pascal's triangle
          % row #0 => value is 1
          node[box=even] (p-0-0) at (0,0) {rotatebox{-30}{1}};
          foreach row in {1,...,11} {
          % col #0 =&gt; value is 1
          node[box=even] (p-row-0) at (-row/2,-row) {rotatebox{-30}{1}};
          pgfmathsetmacro{myvalue}{1};
          foreach col in {1,...,row} {
          % iterative formula : val = precval * (row-col+1)/col
          % (+ 0.5 to bypass rounding errors)
          pgfmathtruncatemacro{myvalue}{myvalue*((row-col+1)/col)+0.5};
          globalletmyvalue=myvalue
          % position of each value
          coordinate (pos) at (-row/2+col,-row);
          % odd color for odd value and even color for even value
          pgfmathtruncatemacro{rest}{mod(myvalue,2)}
          node[box=even] (p-row-col) at (pos) {rotatebox{-30}{myvalue}};
          }
          }
          begin{pgfonlayer}{background}
          foreach i/j in {4/1,5/1,5/2,6/2,7/6,8/6,8/7,9/7}
          node[box=even,fill=odd] at (p-i-j) {};
          end{pgfonlayer}

          draw[link] (p-4-1.center)--(p-6-2.center);
          draw[link] (p-5-1.center)--(p-5-2.center);
          draw[link] (p-7-6.center)--(p-9-7.center);
          draw[link] (p-8-6.center)--(p-8-7.center);
          node[right=5mm of p-8-8.center, align=left] {$(36-7)+(28-8)=49$};
          node[left=5mm of p-5-0.center, align=right] {$(15-4)+(10-5)=16$};

          end{tikzpicture}

          end{document}


          enter image description here



          (19/11/18) Code updated to avoid problems mentioned in Problem with Pascal triangle example






          share|improve this answer














          I'll left to you understand the code but next is a possible solution based in Paul Gaborit's example



          %%%%%%%%%%%%%%%%%%%%%%%%%%%
          % Author : Paul Gaborit (2009)
          % under Creative Commons attribution license.
          % Title : Pascal's triangle and Sierpinski triangle
          % Note : 17 lines maximum
          documentclass[border=2mm, tikz]{standalone}
          %usepackage[landscape,margin=1cm]{geometry}
          %pagestyle{empty}
          %usepackage[T1]{fontenc}
          %usepackage{lmodern}

          usepackage{tikz}
          usetikzlibrary{positioning,shadows,backgrounds,shapes.geometric}
          begin{document}
          centering

          %
          % x=sqrt{3/4}*minimum size
          % y=3/4*minimum size
          %
          begin{tikzpicture}[y=7.5mm,x=8.66mm]
          % some colors
          colorlet{even}{cyan!60!black}
          colorlet{odd}{orange!100!black}
          colorlet{links}{red!70!black}
          colorlet{back}{yellow!20!white}
          % some styles
          tikzset{
          box/.style={
          regular polygon,
          regular polygon sides=6,
          minimum size=10mm,
          inner sep=0mm,
          outer sep=0mm,
          text centered,
          font=smallbfseriessffamily,
          text=#1!50!black,
          draw=#1,
          line width=.25mm,
          rotate=30,
          },
          link/.style={black, shorten >=2mm, shorten <=2mm, line width=1mm},
          }
          % Pascal's triangle
          % row #0 => value is 1
          node[box=even] (p-0-0) at (0,0) {rotatebox{-30}{1}};
          foreach row in {1,...,11} {
          % col #0 =&gt; value is 1
          node[box=even] (p-row-0) at (-row/2,-row) {rotatebox{-30}{1}};
          pgfmathsetmacro{myvalue}{1};
          foreach col in {1,...,row} {
          % iterative formula : val = precval * (row-col+1)/col
          % (+ 0.5 to bypass rounding errors)
          pgfmathtruncatemacro{myvalue}{myvalue*((row-col+1)/col)+0.5};
          globalletmyvalue=myvalue
          % position of each value
          coordinate (pos) at (-row/2+col,-row);
          % odd color for odd value and even color for even value
          pgfmathtruncatemacro{rest}{mod(myvalue,2)}
          node[box=even] (p-row-col) at (pos) {rotatebox{-30}{myvalue}};
          }
          }
          begin{pgfonlayer}{background}
          foreach i/j in {4/1,5/1,5/2,6/2,7/6,8/6,8/7,9/7}
          node[box=even,fill=odd] at (p-i-j) {};
          end{pgfonlayer}

          draw[link] (p-4-1.center)--(p-6-2.center);
          draw[link] (p-5-1.center)--(p-5-2.center);
          draw[link] (p-7-6.center)--(p-9-7.center);
          draw[link] (p-8-6.center)--(p-8-7.center);
          node[right=5mm of p-8-8.center, align=left] {$(36-7)+(28-8)=49$};
          node[left=5mm of p-5-0.center, align=right] {$(15-4)+(10-5)=16$};

          end{tikzpicture}

          end{document}


          enter image description here



          (19/11/18) Code updated to avoid problems mentioned in Problem with Pascal triangle example







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited yesterday

























          answered Sep 1 '14 at 10:05









          Ignasi

          90k4163302




          90k4163302








          • 1




            hi. There may be a problem in this code, an interaction with some other package. If you have trouble compiling it, see my other post : tex.stackexchange.com/questions/460463/…
            – Nicolas FRANCOIS
            Nov 17 at 18:14










          • Please consider replacing value by something less dangerous (OK, this expression sounds stronger than it should sound, this is not meant to sound strong) since value has a well-defined meaning in many packages/classes, so there could be problems, see e.g. this post. How about myvalue?
            – marmot
            Nov 17 at 18:17










          • @NicolasFRANCOIS Code updated.
            – Ignasi
            yesterday














          • 1




            hi. There may be a problem in this code, an interaction with some other package. If you have trouble compiling it, see my other post : tex.stackexchange.com/questions/460463/…
            – Nicolas FRANCOIS
            Nov 17 at 18:14










          • Please consider replacing value by something less dangerous (OK, this expression sounds stronger than it should sound, this is not meant to sound strong) since value has a well-defined meaning in many packages/classes, so there could be problems, see e.g. this post. How about myvalue?
            – marmot
            Nov 17 at 18:17










          • @NicolasFRANCOIS Code updated.
            – Ignasi
            yesterday








          1




          1




          hi. There may be a problem in this code, an interaction with some other package. If you have trouble compiling it, see my other post : tex.stackexchange.com/questions/460463/…
          – Nicolas FRANCOIS
          Nov 17 at 18:14




          hi. There may be a problem in this code, an interaction with some other package. If you have trouble compiling it, see my other post : tex.stackexchange.com/questions/460463/…
          – Nicolas FRANCOIS
          Nov 17 at 18:14












          Please consider replacing value by something less dangerous (OK, this expression sounds stronger than it should sound, this is not meant to sound strong) since value has a well-defined meaning in many packages/classes, so there could be problems, see e.g. this post. How about myvalue?
          – marmot
          Nov 17 at 18:17




          Please consider replacing value by something less dangerous (OK, this expression sounds stronger than it should sound, this is not meant to sound strong) since value has a well-defined meaning in many packages/classes, so there could be problems, see e.g. this post. How about myvalue?
          – marmot
          Nov 17 at 18:17












          @NicolasFRANCOIS Code updated.
          – Ignasi
          yesterday




          @NicolasFRANCOIS Code updated.
          – Ignasi
          yesterday










          up vote
          11
          down vote













          Not a complete answer, but just intended to show a different way of drawing the triangle and also calculating the values. Requires lualatex:



          documentclass[tikz,border=5]{standalone}
          usetikzlibrary{shapes.geometric}
          directlua{
          function factorial (f)
          if f < 2 then return 1 else return f*factorial(f-1) end
          end

          function nchoosek(n, k)
          return factorial(n) / (factorial(n-k) * factorial(k))
          end
          }
          tikzset{hexagon/.style={
          regular polygon, regular polygon sides=6, shape border rotate=30,
          minimum size=1cm, inner sep=0pt,
          draw, ultra thick, execute at begin node={setbox0hboxbgroup},
          execute at end node={egrouppgfmathparse{min(4ex,wd0)/wd0}%
          scalebox{pgfmathresult}{box0}}
          }}
          begin{document}
          tikz[x=1cm*sin 60, y=1.5cm*cos 60]
          foreach n in {0,...,11}
          foreach k in {0,...,n}
          node [hexagon] at (-n/2+k, -n) {directlua{tex.print("" .. nchoosek(n,k))}};
          end{document}


          enter image description here



          The advantage with using lualatex is that it is possible to bypass the limits on mathematical calculations in PGF (actually in TeX):



          enter image description here






          share|improve this answer





















          • This won't compile at my place as of today. The fix is explained here : add RequirePackage{luatex85} as the very first line, a temporary workaround until standalone is updated.
            – marsupilam
            Oct 25 '16 at 16:29












          • Hi @mark-wibrow, I would like to use your code with a little change: I would like to be able to change the background color of some hexagons, inserting some conditional code. I don't know where to insert it, though. A simple line like "ifthenelse{n=2}{fill=blue!30,}{}" won't work. How could I do?
            – zar
            Nov 2 '16 at 17:31















          up vote
          11
          down vote













          Not a complete answer, but just intended to show a different way of drawing the triangle and also calculating the values. Requires lualatex:



          documentclass[tikz,border=5]{standalone}
          usetikzlibrary{shapes.geometric}
          directlua{
          function factorial (f)
          if f < 2 then return 1 else return f*factorial(f-1) end
          end

          function nchoosek(n, k)
          return factorial(n) / (factorial(n-k) * factorial(k))
          end
          }
          tikzset{hexagon/.style={
          regular polygon, regular polygon sides=6, shape border rotate=30,
          minimum size=1cm, inner sep=0pt,
          draw, ultra thick, execute at begin node={setbox0hboxbgroup},
          execute at end node={egrouppgfmathparse{min(4ex,wd0)/wd0}%
          scalebox{pgfmathresult}{box0}}
          }}
          begin{document}
          tikz[x=1cm*sin 60, y=1.5cm*cos 60]
          foreach n in {0,...,11}
          foreach k in {0,...,n}
          node [hexagon] at (-n/2+k, -n) {directlua{tex.print("" .. nchoosek(n,k))}};
          end{document}


          enter image description here



          The advantage with using lualatex is that it is possible to bypass the limits on mathematical calculations in PGF (actually in TeX):



          enter image description here






          share|improve this answer





















          • This won't compile at my place as of today. The fix is explained here : add RequirePackage{luatex85} as the very first line, a temporary workaround until standalone is updated.
            – marsupilam
            Oct 25 '16 at 16:29












          • Hi @mark-wibrow, I would like to use your code with a little change: I would like to be able to change the background color of some hexagons, inserting some conditional code. I don't know where to insert it, though. A simple line like "ifthenelse{n=2}{fill=blue!30,}{}" won't work. How could I do?
            – zar
            Nov 2 '16 at 17:31













          up vote
          11
          down vote










          up vote
          11
          down vote









          Not a complete answer, but just intended to show a different way of drawing the triangle and also calculating the values. Requires lualatex:



          documentclass[tikz,border=5]{standalone}
          usetikzlibrary{shapes.geometric}
          directlua{
          function factorial (f)
          if f < 2 then return 1 else return f*factorial(f-1) end
          end

          function nchoosek(n, k)
          return factorial(n) / (factorial(n-k) * factorial(k))
          end
          }
          tikzset{hexagon/.style={
          regular polygon, regular polygon sides=6, shape border rotate=30,
          minimum size=1cm, inner sep=0pt,
          draw, ultra thick, execute at begin node={setbox0hboxbgroup},
          execute at end node={egrouppgfmathparse{min(4ex,wd0)/wd0}%
          scalebox{pgfmathresult}{box0}}
          }}
          begin{document}
          tikz[x=1cm*sin 60, y=1.5cm*cos 60]
          foreach n in {0,...,11}
          foreach k in {0,...,n}
          node [hexagon] at (-n/2+k, -n) {directlua{tex.print("" .. nchoosek(n,k))}};
          end{document}


          enter image description here



          The advantage with using lualatex is that it is possible to bypass the limits on mathematical calculations in PGF (actually in TeX):



          enter image description here






          share|improve this answer












          Not a complete answer, but just intended to show a different way of drawing the triangle and also calculating the values. Requires lualatex:



          documentclass[tikz,border=5]{standalone}
          usetikzlibrary{shapes.geometric}
          directlua{
          function factorial (f)
          if f < 2 then return 1 else return f*factorial(f-1) end
          end

          function nchoosek(n, k)
          return factorial(n) / (factorial(n-k) * factorial(k))
          end
          }
          tikzset{hexagon/.style={
          regular polygon, regular polygon sides=6, shape border rotate=30,
          minimum size=1cm, inner sep=0pt,
          draw, ultra thick, execute at begin node={setbox0hboxbgroup},
          execute at end node={egrouppgfmathparse{min(4ex,wd0)/wd0}%
          scalebox{pgfmathresult}{box0}}
          }}
          begin{document}
          tikz[x=1cm*sin 60, y=1.5cm*cos 60]
          foreach n in {0,...,11}
          foreach k in {0,...,n}
          node [hexagon] at (-n/2+k, -n) {directlua{tex.print("" .. nchoosek(n,k))}};
          end{document}


          enter image description here



          The advantage with using lualatex is that it is possible to bypass the limits on mathematical calculations in PGF (actually in TeX):



          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Sep 1 '14 at 12:34









          Mark Wibrow

          61.1k4108172




          61.1k4108172












          • This won't compile at my place as of today. The fix is explained here : add RequirePackage{luatex85} as the very first line, a temporary workaround until standalone is updated.
            – marsupilam
            Oct 25 '16 at 16:29












          • Hi @mark-wibrow, I would like to use your code with a little change: I would like to be able to change the background color of some hexagons, inserting some conditional code. I don't know where to insert it, though. A simple line like "ifthenelse{n=2}{fill=blue!30,}{}" won't work. How could I do?
            – zar
            Nov 2 '16 at 17:31


















          • This won't compile at my place as of today. The fix is explained here : add RequirePackage{luatex85} as the very first line, a temporary workaround until standalone is updated.
            – marsupilam
            Oct 25 '16 at 16:29












          • Hi @mark-wibrow, I would like to use your code with a little change: I would like to be able to change the background color of some hexagons, inserting some conditional code. I don't know where to insert it, though. A simple line like "ifthenelse{n=2}{fill=blue!30,}{}" won't work. How could I do?
            – zar
            Nov 2 '16 at 17:31
















          This won't compile at my place as of today. The fix is explained here : add RequirePackage{luatex85} as the very first line, a temporary workaround until standalone is updated.
          – marsupilam
          Oct 25 '16 at 16:29






          This won't compile at my place as of today. The fix is explained here : add RequirePackage{luatex85} as the very first line, a temporary workaround until standalone is updated.
          – marsupilam
          Oct 25 '16 at 16:29














          Hi @mark-wibrow, I would like to use your code with a little change: I would like to be able to change the background color of some hexagons, inserting some conditional code. I don't know where to insert it, though. A simple line like "ifthenelse{n=2}{fill=blue!30,}{}" won't work. How could I do?
          – zar
          Nov 2 '16 at 17:31




          Hi @mark-wibrow, I would like to use your code with a little change: I would like to be able to change the background color of some hexagons, inserting some conditional code. I don't know where to insert it, though. A simple line like "ifthenelse{n=2}{fill=blue!30,}{}" won't work. How could I do?
          – zar
          Nov 2 '16 at 17:31


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f198887%2fhow-can-i-draw-pascals-triangle-with-some-its-properties%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          サソリ

          広島県道265号伴広島線

          Accessing regular linux commands in Huawei's Dopra Linux