How to replace space with '+' symbol in a triangular array?How to draw a circle with a triangle in TikZ?Visualize array changes with arrows(not)implies sign as edges in tikz graphHow to make the number line?drawing patterns based on prime factorizationHow can I make a diagram with lots of colored circles?Generating ukulele chord diagramscolored boxes diagram with textStandard align space with CD environment from amscd packageHow to draw a triangular prism in latex?

Promotion comes with unexpected 24/7/365 on-call

He is the first man to arrive here

Have there been any examples of re-usable rockets in the past?

What are the effects of eating many berries from the Goodberry spell per day?

I recently started my machine learning PhD and I have absolutely no idea what I'm doing

Why would company (decision makers) wait for someone to retire, rather than lay them off, when their role is no longer needed?

How can I make dummy text (like lipsum) grey?

Solenoid fastest possible release - for how long should reversed polarity be applied?

How do Ctrl+C and Ctrl+V work?

Why is Drogon so much better in battle than Rhaegal and Viserion?

Would life always name the light from their sun "white"

Usage of the relative pronoun "dont"

Is there an academic word that means "to split hairs over"?

Why does string strummed with finger sound different from the one strummed with pick?

FIFO data structure in pure C

Why does the U.S military use mercenaries?

Why are there five extra turns in tournament Magic?

Is it standard to have the first week's pay indefinitely withheld?

What would a Dragon have to exhale to cause rain?

What technology would Dwarves need to forge titanium?

Capital gains on stocks sold to take initial investment off the table

"Counterexample" for the Inverse function theorem

How can I safely determine the output voltage and current of a transformer?

How to generate a triangular grid from a list of points



How to replace space with '+' symbol in a triangular array?


How to draw a circle with a triangle in TikZ?Visualize array changes with arrows(not)implies sign as edges in tikz graphHow to make the number line?drawing patterns based on prime factorizationHow can I make a diagram with lots of colored circles?Generating ukulele chord diagramscolored boxes diagram with textStandard align space with CD environment from amscd packageHow to draw a triangular prism in latex?













14















How can I make number pattern like this



enter image description here



But, all spaces are replaced with plus signs ?










share|improve this question



















  • 1





    Welcome to TeX.SE!

    – Kurt
    May 5 at 4:03






  • 3





    In the final row of your screenshot, should there be a space between 10 and 11?

    – Mico
    May 5 at 4:12















14















How can I make number pattern like this



enter image description here



But, all spaces are replaced with plus signs ?










share|improve this question



















  • 1





    Welcome to TeX.SE!

    – Kurt
    May 5 at 4:03






  • 3





    In the final row of your screenshot, should there be a space between 10 and 11?

    – Mico
    May 5 at 4:12













14












14








14


4






How can I make number pattern like this



enter image description here



But, all spaces are replaced with plus signs ?










share|improve this question
















How can I make number pattern like this



enter image description here



But, all spaces are replaced with plus signs ?







diagrams






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 5 at 11:39









Mico

291k32399788




291k32399788










asked May 5 at 3:14









LimoPandaLimoPanda

744




744







  • 1





    Welcome to TeX.SE!

    – Kurt
    May 5 at 4:03






  • 3





    In the final row of your screenshot, should there be a space between 10 and 11?

    – Mico
    May 5 at 4:12












  • 1





    Welcome to TeX.SE!

    – Kurt
    May 5 at 4:03






  • 3





    In the final row of your screenshot, should there be a space between 10 and 11?

    – Mico
    May 5 at 4:12







1




1





Welcome to TeX.SE!

– Kurt
May 5 at 4:03





Welcome to TeX.SE!

– Kurt
May 5 at 4:03




3




3





In the final row of your screenshot, should there be a space between 10 and 11?

– Mico
May 5 at 4:12





In the final row of your screenshot, should there be a space between 10 and 11?

– Mico
May 5 at 4:12










5 Answers
5






active

oldest

votes


















21














Just for fun: without packages.



documentclassarticle
newcounterpft
newcounterpfft
begindocument
setcounterpft0loop%
stepcounterpft%
setcounterpfft0noindent$loop%
stepcounterpfftnumbervaluepfft%
ifnumnumbervaluepfft<numbervaluepft+repeat$par%
ifnumnumbervaluepft<11repeat%
enddocument


enter image description here



Or with pgffor, which contains the foreach command that is used in JouleV's nice answer, and which is loaded by TikZ.



documentclassarticle
usepackagepgffor
begindocument
foreach X in 1,...,11%
noindent$foreach Y in 1,...,X%
ifnumY>1%
+%
fi%
Y
$par
enddocument


Since everyone has a bonus...



documentclassarticle
newcounterpft
newcounterpfft
newcountersum
begindocument
beginflushright
setcounterpft0loop%
stepcounterpft%
setcounterpfft0setcountersum0noindent$loop%
stepcounterpfftnumbervaluepfftaddtocountersumvaluepfft%
ifnumnumbervaluepfft<numbervaluepft+repeat=numbervaluesum%
ifnumvaluesum<10relaxphantom1fi$par%
ifnumnumbervaluepft<11repeat%
endflushright
enddocument


enter image description here






share|improve this answer
































    15














    Let's employ TikZ and some simple algorithms for such things.



    documentclass[tikz]standalone
    begindocument
    begintikzpicture[x=5ex,y=5ex]
    defmaxnum11 % Change the size here
    foreach i in 1,...,maxnum
    % Draw the numbers
    pgfmathsetmacroauxnummaxnum-i+1
    foreach j in 1,...,auxnum
    node (i-j) at (i,j) i;
    % Draw the plus signs
    ifnumi=maxnumrelaxelse
    pgfmathsetmacroauxnummaxnum-i
    foreach j in 1,...,auxnum
    node[anchor=base] at ([shift=(.5,0)]i-j.base) +;
    fi

    endtikzpicture
    enddocument


    enter image description here



    A little bonus:



    documentclass[tikz]standalone
    begindocument
    begintikzpicture[x=5ex,y=5ex]
    defmaxnum11
    foreach i in 1,...,maxnum
    % Draw the numbers
    pgfmathsetmacroauxnummaxnum-i+1
    foreach j in 1,...,auxnum
    node (i-j) at (i,j) i;
    % Draw the plus signs
    ifnumi=maxnumrelaxelse
    pgfmathsetmacroauxnummaxnum-i
    foreach j in 1,...,auxnum
    node[anchor=base] at ([shift=(.5,0)]i-j.base) +;
    fi
    % The rest :)
    pgfmathsetmacrosumoutputint((maxnum-i+1)*(maxnum-i+2)/2)
    node (output-i) at (maxnum+1,i) sumoutput;
    node[anchor=base] at ([shift=(-.5,0)]output-i.base) =;

    endtikzpicture
    enddocument


    enter image description here




    Not sure what do you really want to get by "to the right", but maybe this?



    documentclass[tikz]standalone
    begindocument
    begintikzpicture[x=5ex,y=5ex]
    defmaxnum11
    foreach i in 1,...,maxnum
    % numbers - simpler than the above code
    foreach j [count=k] in i,...,1
    node (i-j) at (i,j) k;
    % plus signs - a bit simpler
    ifnumi=maxnumrelaxelse
    foreach j in i,...,1
    node[anchor=base] at ([shift=(.5,0)]i-j.base) +;
    fi
    % I keep the "bonus" part - it needs no improvements
    pgfmathsetmacrosumoutputint((maxnum-i+1)*(maxnum-i+2)/2)
    node (output-i) at (maxnum+1,i) sumoutput;
    node[anchor=base] at ([shift=(-.5,0)]output-i.base) =;

    endtikzpicture
    enddocument


    enter image description here




    Comparison with other answers



    Other answers are very good, but it seems that this answer is totally different from all other answers (which are somehow a little similar to each other). This is the pros and cons of this answer compared to the others. Read it to consider what to use.



    Pros



    The numbers and signs are aligned in a perfect square. So you can have something like this



    documentclass[tikz]standalone
    usetikzlibrarybackgrounds,fit,calc
    begindocument
    begintikzpicture[x=5ex,y=5ex]
    defmaxnum11 % Change the size here
    foreach i in 1,...,maxnum
    % numbers - simpler than the above code
    foreach j [count=k] in i,...,1
    node[minimum size=.55cm] (i-j) at (i,j) k;
    % plus signs - a bit simpler
    ifnumi=maxnumrelaxelse
    foreach j in i,...,1
    node[anchor=base] at ([shift=(.5,0)]i-j.base) +;
    fi
    % I keep the "bonus" part - it needs no improvements
    pgfmathsetmacrosumoutputint((maxnum-i+1)*(maxnum-i+2)/2)
    node (output-i) at (maxnum+1,i) sumoutput;
    node[anchor=base] at ([shift=(-.5,0)]output-i.base) =;

    beginscope[on background layer]
    path[fill=red!10,draw=red,thick]
    ([shift=( .1,-.1)]1-1.north west) --
    ([shift=( .1,-.1)]11-11.north west)
    arc (135:-45:.55/sqrt(2)) --
    ([shift=(-.1, .1)]1-1.south east)
    arc (315:135:.55/sqrt(2)); % Well, possibly this is not the best
    % way to draw this, but this is only
    % for illustration purpose.
    draw[red,thick,<-]
    ($([shift=( .1,-.1)]1-1.north west)!.45!([shift=( .1,-.1)]11-11.north west)$)
    -- + (-2,1) node[pos=1.3] Looks! All are number 1!;
    endscope
    endtikzpicture
    enddocument


    enter image description here



    In other answers, the numbers, say 1, are not perfectly aligned if maxnum is greater than 9, so it is harder to draw such a path.



    Cons



    It is very clear: the spacing between the numbers and the plus signs are inconsistent. But when I follow this approach (insert the plus signs separately), I have to accept this kind of spacing.



    Btw, the numbers after the equal signs are not right-aligned. This is fixable, but a fix will make the code much more complicated (if I want to automatically determine the width of the node of the "sum"). I don't think this is a major problem though.






    share|improve this answer

























    • What if you want to make it align to the right ? What is this TikZ thing ? (I'm a very-beginner)

      – LimoPanda
      May 5 at 4:05







    • 2





      Hello @LimoPanda, if you want to know what TikZ is good for, please have a look at p. 18 of this manual. ;-)

      – marmot
      May 5 at 4:10











    • @LimoPanda Sorry for the late reply. What do you want to align to the right?

      – JouleV
      May 5 at 4:34






    • 1





      @marmot I thought it should be pages 18 and 11-12 of that manual

      – JouleV
      May 5 at 4:39







    • 1





      @Mico Sure. I edited my answer.

      – JouleV
      May 5 at 14:06


















    12














    Here's a LuaLaTeX-based solution. The number of rows can be set as the argument of the LaTeX macro makearray; this macro calls the Lua function make_array, which does most of the work.



    enter image description here



    To make the triangular array right-aligned instead of left-aligned, change beginarray@l@ to beginarray@r@. If you wish to have a bit more space around the + symbols, change tex.sprint ( "+" ) to tex.sprint ( "+" ).



    % !TEX TS-program = lualatex
    documentclassarticle
    usepackageluacode % for 'luacode' environment

    %% Lua-side code: Define the Lua function 'make_array'
    beginluacode


    function make_array ( n )
    for i=1,n do
    for j=1,i do
    tex.sprint ( j )
    if j<i then
    tex.sprint ( "+" )
    else
    tex.sprint ( "\\" )
    end
    end
    end
    end


    endluacode

    %% LaTeX-side code: Define the macro 'makearray'
    newcommandmakearray[1]%
    $beginarray@l@
    directluamake_array(#1)
    endarray$


    begindocument
    makearray11
    enddocument



    Addendum: Here's a solution which typesets each row's sum along the right-hand edge of the (now rectangular) array. Compared with the solution shown above, it also allows for a bit more space around the + symbols. Observe the use of toprule and bottomrule: These instruction are optional and may be left off.



    enter image description here



    % !TEX TS-program = lualatex
    documentclassarticle
    usepackageluacode % for 'luaexec' macro
    usepackagebooktabs % for 'toprule' and 'bottomrule' macros

    %% Lua-side code: Define the function 'make_array_with_rowsum'
    luaexec%


    function make_array_with_rowsum ( n )
    for i=1,n do
    for j=1,i do
    tex.sprint ( j )
    if j<i then
    tex.sprint ( "+" )
    else
    tex.sprint ( "&=&" .. i*(i+1)//2 .. "\\" )
    end
    end
    end
    end




    %% LaTeX-side code: Define the macro 'makearray'
    newcommandmakearray[1]%
    parnoindent
    begingroup
    centering
    setlengtharraycolsep0pt
    $beginarraylcr
    toprule
    luadirectmake_array_with_rowsum(#1)
    bottomrule
    endarray$par
    endgroup

    begindocument
    makearray16
    enddocument





    share|improve this answer
































      11














      documentclassarticle
      usepackagemultido
      begindocument
      noindent$1$
      multidoiA=2+110\$%
      multidoiB=1+1numexpriA-1iB+iA$

      bigskipnoindent$1=1$
      multidoiA=2+110\$xdefSum0%
      multidoiB=1+1numexpriA-1%
      iB+xdefSumthenumexprSum+iBiA=thenumexprSum+iA$

      enddocument


      enter image description here






      share|improve this answer






























        8














        The mandatory double expl3 loop:



        documentclassarticle
        usepackagexparse,array

        ExplSyntaxOn
        NewDocumentCommandtriangletabsm
        % #1 = * for totals, #2 = end point
        IfBooleanTF #1

        begintabular@ l @ c @ r @
        int_step_inline:nn #2 panda_row_total:n ##1 \
        endtabular


        begintabular@ l @
        int_step_inline:nn #2 panda_row:n ##1 \
        endtabular


        cs_new_protected:Nn panda_row:n

        $1 int_step_inline:nnn 2 #1 + ##1 $

        cs_new_protected:Nn panda_row_total:n

        panda_row:n #1 & $=$ & $int_eval:n (#1)*(#1+1)/2 $

        ExplSyntaxOff

        begindocument

        [
        triangletab1 qquad triangletab3 qquad triangletab11
        ]

        [
        triangletab*1 qquad triangletab*3 qquad triangletab*11
        ]

        enddocument


        enter image description here






        share|improve this answer























          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',
          autoActivateHeartbeat: false,
          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%2f489242%2fhow-to-replace-space-with-symbol-in-a-triangular-array%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          5 Answers
          5






          active

          oldest

          votes








          5 Answers
          5






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          21














          Just for fun: without packages.



          documentclassarticle
          newcounterpft
          newcounterpfft
          begindocument
          setcounterpft0loop%
          stepcounterpft%
          setcounterpfft0noindent$loop%
          stepcounterpfftnumbervaluepfft%
          ifnumnumbervaluepfft<numbervaluepft+repeat$par%
          ifnumnumbervaluepft<11repeat%
          enddocument


          enter image description here



          Or with pgffor, which contains the foreach command that is used in JouleV's nice answer, and which is loaded by TikZ.



          documentclassarticle
          usepackagepgffor
          begindocument
          foreach X in 1,...,11%
          noindent$foreach Y in 1,...,X%
          ifnumY>1%
          +%
          fi%
          Y
          $par
          enddocument


          Since everyone has a bonus...



          documentclassarticle
          newcounterpft
          newcounterpfft
          newcountersum
          begindocument
          beginflushright
          setcounterpft0loop%
          stepcounterpft%
          setcounterpfft0setcountersum0noindent$loop%
          stepcounterpfftnumbervaluepfftaddtocountersumvaluepfft%
          ifnumnumbervaluepfft<numbervaluepft+repeat=numbervaluesum%
          ifnumvaluesum<10relaxphantom1fi$par%
          ifnumnumbervaluepft<11repeat%
          endflushright
          enddocument


          enter image description here






          share|improve this answer





























            21














            Just for fun: without packages.



            documentclassarticle
            newcounterpft
            newcounterpfft
            begindocument
            setcounterpft0loop%
            stepcounterpft%
            setcounterpfft0noindent$loop%
            stepcounterpfftnumbervaluepfft%
            ifnumnumbervaluepfft<numbervaluepft+repeat$par%
            ifnumnumbervaluepft<11repeat%
            enddocument


            enter image description here



            Or with pgffor, which contains the foreach command that is used in JouleV's nice answer, and which is loaded by TikZ.



            documentclassarticle
            usepackagepgffor
            begindocument
            foreach X in 1,...,11%
            noindent$foreach Y in 1,...,X%
            ifnumY>1%
            +%
            fi%
            Y
            $par
            enddocument


            Since everyone has a bonus...



            documentclassarticle
            newcounterpft
            newcounterpfft
            newcountersum
            begindocument
            beginflushright
            setcounterpft0loop%
            stepcounterpft%
            setcounterpfft0setcountersum0noindent$loop%
            stepcounterpfftnumbervaluepfftaddtocountersumvaluepfft%
            ifnumnumbervaluepfft<numbervaluepft+repeat=numbervaluesum%
            ifnumvaluesum<10relaxphantom1fi$par%
            ifnumnumbervaluepft<11repeat%
            endflushright
            enddocument


            enter image description here






            share|improve this answer



























              21












              21








              21







              Just for fun: without packages.



              documentclassarticle
              newcounterpft
              newcounterpfft
              begindocument
              setcounterpft0loop%
              stepcounterpft%
              setcounterpfft0noindent$loop%
              stepcounterpfftnumbervaluepfft%
              ifnumnumbervaluepfft<numbervaluepft+repeat$par%
              ifnumnumbervaluepft<11repeat%
              enddocument


              enter image description here



              Or with pgffor, which contains the foreach command that is used in JouleV's nice answer, and which is loaded by TikZ.



              documentclassarticle
              usepackagepgffor
              begindocument
              foreach X in 1,...,11%
              noindent$foreach Y in 1,...,X%
              ifnumY>1%
              +%
              fi%
              Y
              $par
              enddocument


              Since everyone has a bonus...



              documentclassarticle
              newcounterpft
              newcounterpfft
              newcountersum
              begindocument
              beginflushright
              setcounterpft0loop%
              stepcounterpft%
              setcounterpfft0setcountersum0noindent$loop%
              stepcounterpfftnumbervaluepfftaddtocountersumvaluepfft%
              ifnumnumbervaluepfft<numbervaluepft+repeat=numbervaluesum%
              ifnumvaluesum<10relaxphantom1fi$par%
              ifnumnumbervaluepft<11repeat%
              endflushright
              enddocument


              enter image description here






              share|improve this answer















              Just for fun: without packages.



              documentclassarticle
              newcounterpft
              newcounterpfft
              begindocument
              setcounterpft0loop%
              stepcounterpft%
              setcounterpfft0noindent$loop%
              stepcounterpfftnumbervaluepfft%
              ifnumnumbervaluepfft<numbervaluepft+repeat$par%
              ifnumnumbervaluepft<11repeat%
              enddocument


              enter image description here



              Or with pgffor, which contains the foreach command that is used in JouleV's nice answer, and which is loaded by TikZ.



              documentclassarticle
              usepackagepgffor
              begindocument
              foreach X in 1,...,11%
              noindent$foreach Y in 1,...,X%
              ifnumY>1%
              +%
              fi%
              Y
              $par
              enddocument


              Since everyone has a bonus...



              documentclassarticle
              newcounterpft
              newcounterpfft
              newcountersum
              begindocument
              beginflushright
              setcounterpft0loop%
              stepcounterpft%
              setcounterpfft0setcountersum0noindent$loop%
              stepcounterpfftnumbervaluepfftaddtocountersumvaluepfft%
              ifnumnumbervaluepfft<numbervaluepft+repeat=numbervaluesum%
              ifnumvaluesum<10relaxphantom1fi$par%
              ifnumnumbervaluepft<11repeat%
              endflushright
              enddocument


              enter image description here







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited May 8 at 21:20

























              answered May 5 at 3:58









              marmotmarmot

              127k6162308




              127k6162308





















                  15














                  Let's employ TikZ and some simple algorithms for such things.



                  documentclass[tikz]standalone
                  begindocument
                  begintikzpicture[x=5ex,y=5ex]
                  defmaxnum11 % Change the size here
                  foreach i in 1,...,maxnum
                  % Draw the numbers
                  pgfmathsetmacroauxnummaxnum-i+1
                  foreach j in 1,...,auxnum
                  node (i-j) at (i,j) i;
                  % Draw the plus signs
                  ifnumi=maxnumrelaxelse
                  pgfmathsetmacroauxnummaxnum-i
                  foreach j in 1,...,auxnum
                  node[anchor=base] at ([shift=(.5,0)]i-j.base) +;
                  fi

                  endtikzpicture
                  enddocument


                  enter image description here



                  A little bonus:



                  documentclass[tikz]standalone
                  begindocument
                  begintikzpicture[x=5ex,y=5ex]
                  defmaxnum11
                  foreach i in 1,...,maxnum
                  % Draw the numbers
                  pgfmathsetmacroauxnummaxnum-i+1
                  foreach j in 1,...,auxnum
                  node (i-j) at (i,j) i;
                  % Draw the plus signs
                  ifnumi=maxnumrelaxelse
                  pgfmathsetmacroauxnummaxnum-i
                  foreach j in 1,...,auxnum
                  node[anchor=base] at ([shift=(.5,0)]i-j.base) +;
                  fi
                  % The rest :)
                  pgfmathsetmacrosumoutputint((maxnum-i+1)*(maxnum-i+2)/2)
                  node (output-i) at (maxnum+1,i) sumoutput;
                  node[anchor=base] at ([shift=(-.5,0)]output-i.base) =;

                  endtikzpicture
                  enddocument


                  enter image description here




                  Not sure what do you really want to get by "to the right", but maybe this?



                  documentclass[tikz]standalone
                  begindocument
                  begintikzpicture[x=5ex,y=5ex]
                  defmaxnum11
                  foreach i in 1,...,maxnum
                  % numbers - simpler than the above code
                  foreach j [count=k] in i,...,1
                  node (i-j) at (i,j) k;
                  % plus signs - a bit simpler
                  ifnumi=maxnumrelaxelse
                  foreach j in i,...,1
                  node[anchor=base] at ([shift=(.5,0)]i-j.base) +;
                  fi
                  % I keep the "bonus" part - it needs no improvements
                  pgfmathsetmacrosumoutputint((maxnum-i+1)*(maxnum-i+2)/2)
                  node (output-i) at (maxnum+1,i) sumoutput;
                  node[anchor=base] at ([shift=(-.5,0)]output-i.base) =;

                  endtikzpicture
                  enddocument


                  enter image description here




                  Comparison with other answers



                  Other answers are very good, but it seems that this answer is totally different from all other answers (which are somehow a little similar to each other). This is the pros and cons of this answer compared to the others. Read it to consider what to use.



                  Pros



                  The numbers and signs are aligned in a perfect square. So you can have something like this



                  documentclass[tikz]standalone
                  usetikzlibrarybackgrounds,fit,calc
                  begindocument
                  begintikzpicture[x=5ex,y=5ex]
                  defmaxnum11 % Change the size here
                  foreach i in 1,...,maxnum
                  % numbers - simpler than the above code
                  foreach j [count=k] in i,...,1
                  node[minimum size=.55cm] (i-j) at (i,j) k;
                  % plus signs - a bit simpler
                  ifnumi=maxnumrelaxelse
                  foreach j in i,...,1
                  node[anchor=base] at ([shift=(.5,0)]i-j.base) +;
                  fi
                  % I keep the "bonus" part - it needs no improvements
                  pgfmathsetmacrosumoutputint((maxnum-i+1)*(maxnum-i+2)/2)
                  node (output-i) at (maxnum+1,i) sumoutput;
                  node[anchor=base] at ([shift=(-.5,0)]output-i.base) =;

                  beginscope[on background layer]
                  path[fill=red!10,draw=red,thick]
                  ([shift=( .1,-.1)]1-1.north west) --
                  ([shift=( .1,-.1)]11-11.north west)
                  arc (135:-45:.55/sqrt(2)) --
                  ([shift=(-.1, .1)]1-1.south east)
                  arc (315:135:.55/sqrt(2)); % Well, possibly this is not the best
                  % way to draw this, but this is only
                  % for illustration purpose.
                  draw[red,thick,<-]
                  ($([shift=( .1,-.1)]1-1.north west)!.45!([shift=( .1,-.1)]11-11.north west)$)
                  -- + (-2,1) node[pos=1.3] Looks! All are number 1!;
                  endscope
                  endtikzpicture
                  enddocument


                  enter image description here



                  In other answers, the numbers, say 1, are not perfectly aligned if maxnum is greater than 9, so it is harder to draw such a path.



                  Cons



                  It is very clear: the spacing between the numbers and the plus signs are inconsistent. But when I follow this approach (insert the plus signs separately), I have to accept this kind of spacing.



                  Btw, the numbers after the equal signs are not right-aligned. This is fixable, but a fix will make the code much more complicated (if I want to automatically determine the width of the node of the "sum"). I don't think this is a major problem though.






                  share|improve this answer

























                  • What if you want to make it align to the right ? What is this TikZ thing ? (I'm a very-beginner)

                    – LimoPanda
                    May 5 at 4:05







                  • 2





                    Hello @LimoPanda, if you want to know what TikZ is good for, please have a look at p. 18 of this manual. ;-)

                    – marmot
                    May 5 at 4:10











                  • @LimoPanda Sorry for the late reply. What do you want to align to the right?

                    – JouleV
                    May 5 at 4:34






                  • 1





                    @marmot I thought it should be pages 18 and 11-12 of that manual

                    – JouleV
                    May 5 at 4:39







                  • 1





                    @Mico Sure. I edited my answer.

                    – JouleV
                    May 5 at 14:06















                  15














                  Let's employ TikZ and some simple algorithms for such things.



                  documentclass[tikz]standalone
                  begindocument
                  begintikzpicture[x=5ex,y=5ex]
                  defmaxnum11 % Change the size here
                  foreach i in 1,...,maxnum
                  % Draw the numbers
                  pgfmathsetmacroauxnummaxnum-i+1
                  foreach j in 1,...,auxnum
                  node (i-j) at (i,j) i;
                  % Draw the plus signs
                  ifnumi=maxnumrelaxelse
                  pgfmathsetmacroauxnummaxnum-i
                  foreach j in 1,...,auxnum
                  node[anchor=base] at ([shift=(.5,0)]i-j.base) +;
                  fi

                  endtikzpicture
                  enddocument


                  enter image description here



                  A little bonus:



                  documentclass[tikz]standalone
                  begindocument
                  begintikzpicture[x=5ex,y=5ex]
                  defmaxnum11
                  foreach i in 1,...,maxnum
                  % Draw the numbers
                  pgfmathsetmacroauxnummaxnum-i+1
                  foreach j in 1,...,auxnum
                  node (i-j) at (i,j) i;
                  % Draw the plus signs
                  ifnumi=maxnumrelaxelse
                  pgfmathsetmacroauxnummaxnum-i
                  foreach j in 1,...,auxnum
                  node[anchor=base] at ([shift=(.5,0)]i-j.base) +;
                  fi
                  % The rest :)
                  pgfmathsetmacrosumoutputint((maxnum-i+1)*(maxnum-i+2)/2)
                  node (output-i) at (maxnum+1,i) sumoutput;
                  node[anchor=base] at ([shift=(-.5,0)]output-i.base) =;

                  endtikzpicture
                  enddocument


                  enter image description here




                  Not sure what do you really want to get by "to the right", but maybe this?



                  documentclass[tikz]standalone
                  begindocument
                  begintikzpicture[x=5ex,y=5ex]
                  defmaxnum11
                  foreach i in 1,...,maxnum
                  % numbers - simpler than the above code
                  foreach j [count=k] in i,...,1
                  node (i-j) at (i,j) k;
                  % plus signs - a bit simpler
                  ifnumi=maxnumrelaxelse
                  foreach j in i,...,1
                  node[anchor=base] at ([shift=(.5,0)]i-j.base) +;
                  fi
                  % I keep the "bonus" part - it needs no improvements
                  pgfmathsetmacrosumoutputint((maxnum-i+1)*(maxnum-i+2)/2)
                  node (output-i) at (maxnum+1,i) sumoutput;
                  node[anchor=base] at ([shift=(-.5,0)]output-i.base) =;

                  endtikzpicture
                  enddocument


                  enter image description here




                  Comparison with other answers



                  Other answers are very good, but it seems that this answer is totally different from all other answers (which are somehow a little similar to each other). This is the pros and cons of this answer compared to the others. Read it to consider what to use.



                  Pros



                  The numbers and signs are aligned in a perfect square. So you can have something like this



                  documentclass[tikz]standalone
                  usetikzlibrarybackgrounds,fit,calc
                  begindocument
                  begintikzpicture[x=5ex,y=5ex]
                  defmaxnum11 % Change the size here
                  foreach i in 1,...,maxnum
                  % numbers - simpler than the above code
                  foreach j [count=k] in i,...,1
                  node[minimum size=.55cm] (i-j) at (i,j) k;
                  % plus signs - a bit simpler
                  ifnumi=maxnumrelaxelse
                  foreach j in i,...,1
                  node[anchor=base] at ([shift=(.5,0)]i-j.base) +;
                  fi
                  % I keep the "bonus" part - it needs no improvements
                  pgfmathsetmacrosumoutputint((maxnum-i+1)*(maxnum-i+2)/2)
                  node (output-i) at (maxnum+1,i) sumoutput;
                  node[anchor=base] at ([shift=(-.5,0)]output-i.base) =;

                  beginscope[on background layer]
                  path[fill=red!10,draw=red,thick]
                  ([shift=( .1,-.1)]1-1.north west) --
                  ([shift=( .1,-.1)]11-11.north west)
                  arc (135:-45:.55/sqrt(2)) --
                  ([shift=(-.1, .1)]1-1.south east)
                  arc (315:135:.55/sqrt(2)); % Well, possibly this is not the best
                  % way to draw this, but this is only
                  % for illustration purpose.
                  draw[red,thick,<-]
                  ($([shift=( .1,-.1)]1-1.north west)!.45!([shift=( .1,-.1)]11-11.north west)$)
                  -- + (-2,1) node[pos=1.3] Looks! All are number 1!;
                  endscope
                  endtikzpicture
                  enddocument


                  enter image description here



                  In other answers, the numbers, say 1, are not perfectly aligned if maxnum is greater than 9, so it is harder to draw such a path.



                  Cons



                  It is very clear: the spacing between the numbers and the plus signs are inconsistent. But when I follow this approach (insert the plus signs separately), I have to accept this kind of spacing.



                  Btw, the numbers after the equal signs are not right-aligned. This is fixable, but a fix will make the code much more complicated (if I want to automatically determine the width of the node of the "sum"). I don't think this is a major problem though.






                  share|improve this answer

























                  • What if you want to make it align to the right ? What is this TikZ thing ? (I'm a very-beginner)

                    – LimoPanda
                    May 5 at 4:05







                  • 2





                    Hello @LimoPanda, if you want to know what TikZ is good for, please have a look at p. 18 of this manual. ;-)

                    – marmot
                    May 5 at 4:10











                  • @LimoPanda Sorry for the late reply. What do you want to align to the right?

                    – JouleV
                    May 5 at 4:34






                  • 1





                    @marmot I thought it should be pages 18 and 11-12 of that manual

                    – JouleV
                    May 5 at 4:39







                  • 1





                    @Mico Sure. I edited my answer.

                    – JouleV
                    May 5 at 14:06













                  15












                  15








                  15







                  Let's employ TikZ and some simple algorithms for such things.



                  documentclass[tikz]standalone
                  begindocument
                  begintikzpicture[x=5ex,y=5ex]
                  defmaxnum11 % Change the size here
                  foreach i in 1,...,maxnum
                  % Draw the numbers
                  pgfmathsetmacroauxnummaxnum-i+1
                  foreach j in 1,...,auxnum
                  node (i-j) at (i,j) i;
                  % Draw the plus signs
                  ifnumi=maxnumrelaxelse
                  pgfmathsetmacroauxnummaxnum-i
                  foreach j in 1,...,auxnum
                  node[anchor=base] at ([shift=(.5,0)]i-j.base) +;
                  fi

                  endtikzpicture
                  enddocument


                  enter image description here



                  A little bonus:



                  documentclass[tikz]standalone
                  begindocument
                  begintikzpicture[x=5ex,y=5ex]
                  defmaxnum11
                  foreach i in 1,...,maxnum
                  % Draw the numbers
                  pgfmathsetmacroauxnummaxnum-i+1
                  foreach j in 1,...,auxnum
                  node (i-j) at (i,j) i;
                  % Draw the plus signs
                  ifnumi=maxnumrelaxelse
                  pgfmathsetmacroauxnummaxnum-i
                  foreach j in 1,...,auxnum
                  node[anchor=base] at ([shift=(.5,0)]i-j.base) +;
                  fi
                  % The rest :)
                  pgfmathsetmacrosumoutputint((maxnum-i+1)*(maxnum-i+2)/2)
                  node (output-i) at (maxnum+1,i) sumoutput;
                  node[anchor=base] at ([shift=(-.5,0)]output-i.base) =;

                  endtikzpicture
                  enddocument


                  enter image description here




                  Not sure what do you really want to get by "to the right", but maybe this?



                  documentclass[tikz]standalone
                  begindocument
                  begintikzpicture[x=5ex,y=5ex]
                  defmaxnum11
                  foreach i in 1,...,maxnum
                  % numbers - simpler than the above code
                  foreach j [count=k] in i,...,1
                  node (i-j) at (i,j) k;
                  % plus signs - a bit simpler
                  ifnumi=maxnumrelaxelse
                  foreach j in i,...,1
                  node[anchor=base] at ([shift=(.5,0)]i-j.base) +;
                  fi
                  % I keep the "bonus" part - it needs no improvements
                  pgfmathsetmacrosumoutputint((maxnum-i+1)*(maxnum-i+2)/2)
                  node (output-i) at (maxnum+1,i) sumoutput;
                  node[anchor=base] at ([shift=(-.5,0)]output-i.base) =;

                  endtikzpicture
                  enddocument


                  enter image description here




                  Comparison with other answers



                  Other answers are very good, but it seems that this answer is totally different from all other answers (which are somehow a little similar to each other). This is the pros and cons of this answer compared to the others. Read it to consider what to use.



                  Pros



                  The numbers and signs are aligned in a perfect square. So you can have something like this



                  documentclass[tikz]standalone
                  usetikzlibrarybackgrounds,fit,calc
                  begindocument
                  begintikzpicture[x=5ex,y=5ex]
                  defmaxnum11 % Change the size here
                  foreach i in 1,...,maxnum
                  % numbers - simpler than the above code
                  foreach j [count=k] in i,...,1
                  node[minimum size=.55cm] (i-j) at (i,j) k;
                  % plus signs - a bit simpler
                  ifnumi=maxnumrelaxelse
                  foreach j in i,...,1
                  node[anchor=base] at ([shift=(.5,0)]i-j.base) +;
                  fi
                  % I keep the "bonus" part - it needs no improvements
                  pgfmathsetmacrosumoutputint((maxnum-i+1)*(maxnum-i+2)/2)
                  node (output-i) at (maxnum+1,i) sumoutput;
                  node[anchor=base] at ([shift=(-.5,0)]output-i.base) =;

                  beginscope[on background layer]
                  path[fill=red!10,draw=red,thick]
                  ([shift=( .1,-.1)]1-1.north west) --
                  ([shift=( .1,-.1)]11-11.north west)
                  arc (135:-45:.55/sqrt(2)) --
                  ([shift=(-.1, .1)]1-1.south east)
                  arc (315:135:.55/sqrt(2)); % Well, possibly this is not the best
                  % way to draw this, but this is only
                  % for illustration purpose.
                  draw[red,thick,<-]
                  ($([shift=( .1,-.1)]1-1.north west)!.45!([shift=( .1,-.1)]11-11.north west)$)
                  -- + (-2,1) node[pos=1.3] Looks! All are number 1!;
                  endscope
                  endtikzpicture
                  enddocument


                  enter image description here



                  In other answers, the numbers, say 1, are not perfectly aligned if maxnum is greater than 9, so it is harder to draw such a path.



                  Cons



                  It is very clear: the spacing between the numbers and the plus signs are inconsistent. But when I follow this approach (insert the plus signs separately), I have to accept this kind of spacing.



                  Btw, the numbers after the equal signs are not right-aligned. This is fixable, but a fix will make the code much more complicated (if I want to automatically determine the width of the node of the "sum"). I don't think this is a major problem though.






                  share|improve this answer















                  Let's employ TikZ and some simple algorithms for such things.



                  documentclass[tikz]standalone
                  begindocument
                  begintikzpicture[x=5ex,y=5ex]
                  defmaxnum11 % Change the size here
                  foreach i in 1,...,maxnum
                  % Draw the numbers
                  pgfmathsetmacroauxnummaxnum-i+1
                  foreach j in 1,...,auxnum
                  node (i-j) at (i,j) i;
                  % Draw the plus signs
                  ifnumi=maxnumrelaxelse
                  pgfmathsetmacroauxnummaxnum-i
                  foreach j in 1,...,auxnum
                  node[anchor=base] at ([shift=(.5,0)]i-j.base) +;
                  fi

                  endtikzpicture
                  enddocument


                  enter image description here



                  A little bonus:



                  documentclass[tikz]standalone
                  begindocument
                  begintikzpicture[x=5ex,y=5ex]
                  defmaxnum11
                  foreach i in 1,...,maxnum
                  % Draw the numbers
                  pgfmathsetmacroauxnummaxnum-i+1
                  foreach j in 1,...,auxnum
                  node (i-j) at (i,j) i;
                  % Draw the plus signs
                  ifnumi=maxnumrelaxelse
                  pgfmathsetmacroauxnummaxnum-i
                  foreach j in 1,...,auxnum
                  node[anchor=base] at ([shift=(.5,0)]i-j.base) +;
                  fi
                  % The rest :)
                  pgfmathsetmacrosumoutputint((maxnum-i+1)*(maxnum-i+2)/2)
                  node (output-i) at (maxnum+1,i) sumoutput;
                  node[anchor=base] at ([shift=(-.5,0)]output-i.base) =;

                  endtikzpicture
                  enddocument


                  enter image description here




                  Not sure what do you really want to get by "to the right", but maybe this?



                  documentclass[tikz]standalone
                  begindocument
                  begintikzpicture[x=5ex,y=5ex]
                  defmaxnum11
                  foreach i in 1,...,maxnum
                  % numbers - simpler than the above code
                  foreach j [count=k] in i,...,1
                  node (i-j) at (i,j) k;
                  % plus signs - a bit simpler
                  ifnumi=maxnumrelaxelse
                  foreach j in i,...,1
                  node[anchor=base] at ([shift=(.5,0)]i-j.base) +;
                  fi
                  % I keep the "bonus" part - it needs no improvements
                  pgfmathsetmacrosumoutputint((maxnum-i+1)*(maxnum-i+2)/2)
                  node (output-i) at (maxnum+1,i) sumoutput;
                  node[anchor=base] at ([shift=(-.5,0)]output-i.base) =;

                  endtikzpicture
                  enddocument


                  enter image description here




                  Comparison with other answers



                  Other answers are very good, but it seems that this answer is totally different from all other answers (which are somehow a little similar to each other). This is the pros and cons of this answer compared to the others. Read it to consider what to use.



                  Pros



                  The numbers and signs are aligned in a perfect square. So you can have something like this



                  documentclass[tikz]standalone
                  usetikzlibrarybackgrounds,fit,calc
                  begindocument
                  begintikzpicture[x=5ex,y=5ex]
                  defmaxnum11 % Change the size here
                  foreach i in 1,...,maxnum
                  % numbers - simpler than the above code
                  foreach j [count=k] in i,...,1
                  node[minimum size=.55cm] (i-j) at (i,j) k;
                  % plus signs - a bit simpler
                  ifnumi=maxnumrelaxelse
                  foreach j in i,...,1
                  node[anchor=base] at ([shift=(.5,0)]i-j.base) +;
                  fi
                  % I keep the "bonus" part - it needs no improvements
                  pgfmathsetmacrosumoutputint((maxnum-i+1)*(maxnum-i+2)/2)
                  node (output-i) at (maxnum+1,i) sumoutput;
                  node[anchor=base] at ([shift=(-.5,0)]output-i.base) =;

                  beginscope[on background layer]
                  path[fill=red!10,draw=red,thick]
                  ([shift=( .1,-.1)]1-1.north west) --
                  ([shift=( .1,-.1)]11-11.north west)
                  arc (135:-45:.55/sqrt(2)) --
                  ([shift=(-.1, .1)]1-1.south east)
                  arc (315:135:.55/sqrt(2)); % Well, possibly this is not the best
                  % way to draw this, but this is only
                  % for illustration purpose.
                  draw[red,thick,<-]
                  ($([shift=( .1,-.1)]1-1.north west)!.45!([shift=( .1,-.1)]11-11.north west)$)
                  -- + (-2,1) node[pos=1.3] Looks! All are number 1!;
                  endscope
                  endtikzpicture
                  enddocument


                  enter image description here



                  In other answers, the numbers, say 1, are not perfectly aligned if maxnum is greater than 9, so it is harder to draw such a path.



                  Cons



                  It is very clear: the spacing between the numbers and the plus signs are inconsistent. But when I follow this approach (insert the plus signs separately), I have to accept this kind of spacing.



                  Btw, the numbers after the equal signs are not right-aligned. This is fixable, but a fix will make the code much more complicated (if I want to automatically determine the width of the node of the "sum"). I don't think this is a major problem though.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited May 9 at 4:18

























                  answered May 5 at 3:29









                  JouleVJouleV

                  17.6k22971




                  17.6k22971












                  • What if you want to make it align to the right ? What is this TikZ thing ? (I'm a very-beginner)

                    – LimoPanda
                    May 5 at 4:05







                  • 2





                    Hello @LimoPanda, if you want to know what TikZ is good for, please have a look at p. 18 of this manual. ;-)

                    – marmot
                    May 5 at 4:10











                  • @LimoPanda Sorry for the late reply. What do you want to align to the right?

                    – JouleV
                    May 5 at 4:34






                  • 1





                    @marmot I thought it should be pages 18 and 11-12 of that manual

                    – JouleV
                    May 5 at 4:39







                  • 1





                    @Mico Sure. I edited my answer.

                    – JouleV
                    May 5 at 14:06

















                  • What if you want to make it align to the right ? What is this TikZ thing ? (I'm a very-beginner)

                    – LimoPanda
                    May 5 at 4:05







                  • 2





                    Hello @LimoPanda, if you want to know what TikZ is good for, please have a look at p. 18 of this manual. ;-)

                    – marmot
                    May 5 at 4:10











                  • @LimoPanda Sorry for the late reply. What do you want to align to the right?

                    – JouleV
                    May 5 at 4:34






                  • 1





                    @marmot I thought it should be pages 18 and 11-12 of that manual

                    – JouleV
                    May 5 at 4:39







                  • 1





                    @Mico Sure. I edited my answer.

                    – JouleV
                    May 5 at 14:06
















                  What if you want to make it align to the right ? What is this TikZ thing ? (I'm a very-beginner)

                  – LimoPanda
                  May 5 at 4:05






                  What if you want to make it align to the right ? What is this TikZ thing ? (I'm a very-beginner)

                  – LimoPanda
                  May 5 at 4:05





                  2




                  2





                  Hello @LimoPanda, if you want to know what TikZ is good for, please have a look at p. 18 of this manual. ;-)

                  – marmot
                  May 5 at 4:10





                  Hello @LimoPanda, if you want to know what TikZ is good for, please have a look at p. 18 of this manual. ;-)

                  – marmot
                  May 5 at 4:10













                  @LimoPanda Sorry for the late reply. What do you want to align to the right?

                  – JouleV
                  May 5 at 4:34





                  @LimoPanda Sorry for the late reply. What do you want to align to the right?

                  – JouleV
                  May 5 at 4:34




                  1




                  1





                  @marmot I thought it should be pages 18 and 11-12 of that manual

                  – JouleV
                  May 5 at 4:39






                  @marmot I thought it should be pages 18 and 11-12 of that manual

                  – JouleV
                  May 5 at 4:39





                  1




                  1





                  @Mico Sure. I edited my answer.

                  – JouleV
                  May 5 at 14:06





                  @Mico Sure. I edited my answer.

                  – JouleV
                  May 5 at 14:06











                  12














                  Here's a LuaLaTeX-based solution. The number of rows can be set as the argument of the LaTeX macro makearray; this macro calls the Lua function make_array, which does most of the work.



                  enter image description here



                  To make the triangular array right-aligned instead of left-aligned, change beginarray@l@ to beginarray@r@. If you wish to have a bit more space around the + symbols, change tex.sprint ( "+" ) to tex.sprint ( "+" ).



                  % !TEX TS-program = lualatex
                  documentclassarticle
                  usepackageluacode % for 'luacode' environment

                  %% Lua-side code: Define the Lua function 'make_array'
                  beginluacode


                  function make_array ( n )
                  for i=1,n do
                  for j=1,i do
                  tex.sprint ( j )
                  if j<i then
                  tex.sprint ( "+" )
                  else
                  tex.sprint ( "\\" )
                  end
                  end
                  end
                  end


                  endluacode

                  %% LaTeX-side code: Define the macro 'makearray'
                  newcommandmakearray[1]%
                  $beginarray@l@
                  directluamake_array(#1)
                  endarray$


                  begindocument
                  makearray11
                  enddocument



                  Addendum: Here's a solution which typesets each row's sum along the right-hand edge of the (now rectangular) array. Compared with the solution shown above, it also allows for a bit more space around the + symbols. Observe the use of toprule and bottomrule: These instruction are optional and may be left off.



                  enter image description here



                  % !TEX TS-program = lualatex
                  documentclassarticle
                  usepackageluacode % for 'luaexec' macro
                  usepackagebooktabs % for 'toprule' and 'bottomrule' macros

                  %% Lua-side code: Define the function 'make_array_with_rowsum'
                  luaexec%


                  function make_array_with_rowsum ( n )
                  for i=1,n do
                  for j=1,i do
                  tex.sprint ( j )
                  if j<i then
                  tex.sprint ( "+" )
                  else
                  tex.sprint ( "&=&" .. i*(i+1)//2 .. "\\" )
                  end
                  end
                  end
                  end




                  %% LaTeX-side code: Define the macro 'makearray'
                  newcommandmakearray[1]%
                  parnoindent
                  begingroup
                  centering
                  setlengtharraycolsep0pt
                  $beginarraylcr
                  toprule
                  luadirectmake_array_with_rowsum(#1)
                  bottomrule
                  endarray$par
                  endgroup

                  begindocument
                  makearray16
                  enddocument





                  share|improve this answer





























                    12














                    Here's a LuaLaTeX-based solution. The number of rows can be set as the argument of the LaTeX macro makearray; this macro calls the Lua function make_array, which does most of the work.



                    enter image description here



                    To make the triangular array right-aligned instead of left-aligned, change beginarray@l@ to beginarray@r@. If you wish to have a bit more space around the + symbols, change tex.sprint ( "+" ) to tex.sprint ( "+" ).



                    % !TEX TS-program = lualatex
                    documentclassarticle
                    usepackageluacode % for 'luacode' environment

                    %% Lua-side code: Define the Lua function 'make_array'
                    beginluacode


                    function make_array ( n )
                    for i=1,n do
                    for j=1,i do
                    tex.sprint ( j )
                    if j<i then
                    tex.sprint ( "+" )
                    else
                    tex.sprint ( "\\" )
                    end
                    end
                    end
                    end


                    endluacode

                    %% LaTeX-side code: Define the macro 'makearray'
                    newcommandmakearray[1]%
                    $beginarray@l@
                    directluamake_array(#1)
                    endarray$


                    begindocument
                    makearray11
                    enddocument



                    Addendum: Here's a solution which typesets each row's sum along the right-hand edge of the (now rectangular) array. Compared with the solution shown above, it also allows for a bit more space around the + symbols. Observe the use of toprule and bottomrule: These instruction are optional and may be left off.



                    enter image description here



                    % !TEX TS-program = lualatex
                    documentclassarticle
                    usepackageluacode % for 'luaexec' macro
                    usepackagebooktabs % for 'toprule' and 'bottomrule' macros

                    %% Lua-side code: Define the function 'make_array_with_rowsum'
                    luaexec%


                    function make_array_with_rowsum ( n )
                    for i=1,n do
                    for j=1,i do
                    tex.sprint ( j )
                    if j<i then
                    tex.sprint ( "+" )
                    else
                    tex.sprint ( "&=&" .. i*(i+1)//2 .. "\\" )
                    end
                    end
                    end
                    end




                    %% LaTeX-side code: Define the macro 'makearray'
                    newcommandmakearray[1]%
                    parnoindent
                    begingroup
                    centering
                    setlengtharraycolsep0pt
                    $beginarraylcr
                    toprule
                    luadirectmake_array_with_rowsum(#1)
                    bottomrule
                    endarray$par
                    endgroup

                    begindocument
                    makearray16
                    enddocument





                    share|improve this answer



























                      12












                      12








                      12







                      Here's a LuaLaTeX-based solution. The number of rows can be set as the argument of the LaTeX macro makearray; this macro calls the Lua function make_array, which does most of the work.



                      enter image description here



                      To make the triangular array right-aligned instead of left-aligned, change beginarray@l@ to beginarray@r@. If you wish to have a bit more space around the + symbols, change tex.sprint ( "+" ) to tex.sprint ( "+" ).



                      % !TEX TS-program = lualatex
                      documentclassarticle
                      usepackageluacode % for 'luacode' environment

                      %% Lua-side code: Define the Lua function 'make_array'
                      beginluacode


                      function make_array ( n )
                      for i=1,n do
                      for j=1,i do
                      tex.sprint ( j )
                      if j<i then
                      tex.sprint ( "+" )
                      else
                      tex.sprint ( "\\" )
                      end
                      end
                      end
                      end


                      endluacode

                      %% LaTeX-side code: Define the macro 'makearray'
                      newcommandmakearray[1]%
                      $beginarray@l@
                      directluamake_array(#1)
                      endarray$


                      begindocument
                      makearray11
                      enddocument



                      Addendum: Here's a solution which typesets each row's sum along the right-hand edge of the (now rectangular) array. Compared with the solution shown above, it also allows for a bit more space around the + symbols. Observe the use of toprule and bottomrule: These instruction are optional and may be left off.



                      enter image description here



                      % !TEX TS-program = lualatex
                      documentclassarticle
                      usepackageluacode % for 'luaexec' macro
                      usepackagebooktabs % for 'toprule' and 'bottomrule' macros

                      %% Lua-side code: Define the function 'make_array_with_rowsum'
                      luaexec%


                      function make_array_with_rowsum ( n )
                      for i=1,n do
                      for j=1,i do
                      tex.sprint ( j )
                      if j<i then
                      tex.sprint ( "+" )
                      else
                      tex.sprint ( "&=&" .. i*(i+1)//2 .. "\\" )
                      end
                      end
                      end
                      end




                      %% LaTeX-side code: Define the macro 'makearray'
                      newcommandmakearray[1]%
                      parnoindent
                      begingroup
                      centering
                      setlengtharraycolsep0pt
                      $beginarraylcr
                      toprule
                      luadirectmake_array_with_rowsum(#1)
                      bottomrule
                      endarray$par
                      endgroup

                      begindocument
                      makearray16
                      enddocument





                      share|improve this answer















                      Here's a LuaLaTeX-based solution. The number of rows can be set as the argument of the LaTeX macro makearray; this macro calls the Lua function make_array, which does most of the work.



                      enter image description here



                      To make the triangular array right-aligned instead of left-aligned, change beginarray@l@ to beginarray@r@. If you wish to have a bit more space around the + symbols, change tex.sprint ( "+" ) to tex.sprint ( "+" ).



                      % !TEX TS-program = lualatex
                      documentclassarticle
                      usepackageluacode % for 'luacode' environment

                      %% Lua-side code: Define the Lua function 'make_array'
                      beginluacode


                      function make_array ( n )
                      for i=1,n do
                      for j=1,i do
                      tex.sprint ( j )
                      if j<i then
                      tex.sprint ( "+" )
                      else
                      tex.sprint ( "\\" )
                      end
                      end
                      end
                      end


                      endluacode

                      %% LaTeX-side code: Define the macro 'makearray'
                      newcommandmakearray[1]%
                      $beginarray@l@
                      directluamake_array(#1)
                      endarray$


                      begindocument
                      makearray11
                      enddocument



                      Addendum: Here's a solution which typesets each row's sum along the right-hand edge of the (now rectangular) array. Compared with the solution shown above, it also allows for a bit more space around the + symbols. Observe the use of toprule and bottomrule: These instruction are optional and may be left off.



                      enter image description here



                      % !TEX TS-program = lualatex
                      documentclassarticle
                      usepackageluacode % for 'luaexec' macro
                      usepackagebooktabs % for 'toprule' and 'bottomrule' macros

                      %% Lua-side code: Define the function 'make_array_with_rowsum'
                      luaexec%


                      function make_array_with_rowsum ( n )
                      for i=1,n do
                      for j=1,i do
                      tex.sprint ( j )
                      if j<i then
                      tex.sprint ( "+" )
                      else
                      tex.sprint ( "&=&" .. i*(i+1)//2 .. "\\" )
                      end
                      end
                      end
                      end




                      %% LaTeX-side code: Define the macro 'makearray'
                      newcommandmakearray[1]%
                      parnoindent
                      begingroup
                      centering
                      setlengtharraycolsep0pt
                      $beginarraylcr
                      toprule
                      luadirectmake_array_with_rowsum(#1)
                      bottomrule
                      endarray$par
                      endgroup

                      begindocument
                      makearray16
                      enddocument






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited May 5 at 10:05

























                      answered May 5 at 4:07









                      MicoMico

                      291k32399788




                      291k32399788





















                          11














                          documentclassarticle
                          usepackagemultido
                          begindocument
                          noindent$1$
                          multidoiA=2+110\$%
                          multidoiB=1+1numexpriA-1iB+iA$

                          bigskipnoindent$1=1$
                          multidoiA=2+110\$xdefSum0%
                          multidoiB=1+1numexpriA-1%
                          iB+xdefSumthenumexprSum+iBiA=thenumexprSum+iA$

                          enddocument


                          enter image description here






                          share|improve this answer



























                            11














                            documentclassarticle
                            usepackagemultido
                            begindocument
                            noindent$1$
                            multidoiA=2+110\$%
                            multidoiB=1+1numexpriA-1iB+iA$

                            bigskipnoindent$1=1$
                            multidoiA=2+110\$xdefSum0%
                            multidoiB=1+1numexpriA-1%
                            iB+xdefSumthenumexprSum+iBiA=thenumexprSum+iA$

                            enddocument


                            enter image description here






                            share|improve this answer

























                              11












                              11








                              11







                              documentclassarticle
                              usepackagemultido
                              begindocument
                              noindent$1$
                              multidoiA=2+110\$%
                              multidoiB=1+1numexpriA-1iB+iA$

                              bigskipnoindent$1=1$
                              multidoiA=2+110\$xdefSum0%
                              multidoiB=1+1numexpriA-1%
                              iB+xdefSumthenumexprSum+iBiA=thenumexprSum+iA$

                              enddocument


                              enter image description here






                              share|improve this answer













                              documentclassarticle
                              usepackagemultido
                              begindocument
                              noindent$1$
                              multidoiA=2+110\$%
                              multidoiB=1+1numexpriA-1iB+iA$

                              bigskipnoindent$1=1$
                              multidoiA=2+110\$xdefSum0%
                              multidoiB=1+1numexpriA-1%
                              iB+xdefSumthenumexprSum+iBiA=thenumexprSum+iA$

                              enddocument


                              enter image description here







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered May 5 at 6:15









                              Red-CloudRed-Cloud

                              2,30313




                              2,30313





















                                  8














                                  The mandatory double expl3 loop:



                                  documentclassarticle
                                  usepackagexparse,array

                                  ExplSyntaxOn
                                  NewDocumentCommandtriangletabsm
                                  % #1 = * for totals, #2 = end point
                                  IfBooleanTF #1

                                  begintabular@ l @ c @ r @
                                  int_step_inline:nn #2 panda_row_total:n ##1 \
                                  endtabular


                                  begintabular@ l @
                                  int_step_inline:nn #2 panda_row:n ##1 \
                                  endtabular


                                  cs_new_protected:Nn panda_row:n

                                  $1 int_step_inline:nnn 2 #1 + ##1 $

                                  cs_new_protected:Nn panda_row_total:n

                                  panda_row:n #1 & $=$ & $int_eval:n (#1)*(#1+1)/2 $

                                  ExplSyntaxOff

                                  begindocument

                                  [
                                  triangletab1 qquad triangletab3 qquad triangletab11
                                  ]

                                  [
                                  triangletab*1 qquad triangletab*3 qquad triangletab*11
                                  ]

                                  enddocument


                                  enter image description here






                                  share|improve this answer



























                                    8














                                    The mandatory double expl3 loop:



                                    documentclassarticle
                                    usepackagexparse,array

                                    ExplSyntaxOn
                                    NewDocumentCommandtriangletabsm
                                    % #1 = * for totals, #2 = end point
                                    IfBooleanTF #1

                                    begintabular@ l @ c @ r @
                                    int_step_inline:nn #2 panda_row_total:n ##1 \
                                    endtabular


                                    begintabular@ l @
                                    int_step_inline:nn #2 panda_row:n ##1 \
                                    endtabular


                                    cs_new_protected:Nn panda_row:n

                                    $1 int_step_inline:nnn 2 #1 + ##1 $

                                    cs_new_protected:Nn panda_row_total:n

                                    panda_row:n #1 & $=$ & $int_eval:n (#1)*(#1+1)/2 $

                                    ExplSyntaxOff

                                    begindocument

                                    [
                                    triangletab1 qquad triangletab3 qquad triangletab11
                                    ]

                                    [
                                    triangletab*1 qquad triangletab*3 qquad triangletab*11
                                    ]

                                    enddocument


                                    enter image description here






                                    share|improve this answer

























                                      8












                                      8








                                      8







                                      The mandatory double expl3 loop:



                                      documentclassarticle
                                      usepackagexparse,array

                                      ExplSyntaxOn
                                      NewDocumentCommandtriangletabsm
                                      % #1 = * for totals, #2 = end point
                                      IfBooleanTF #1

                                      begintabular@ l @ c @ r @
                                      int_step_inline:nn #2 panda_row_total:n ##1 \
                                      endtabular


                                      begintabular@ l @
                                      int_step_inline:nn #2 panda_row:n ##1 \
                                      endtabular


                                      cs_new_protected:Nn panda_row:n

                                      $1 int_step_inline:nnn 2 #1 + ##1 $

                                      cs_new_protected:Nn panda_row_total:n

                                      panda_row:n #1 & $=$ & $int_eval:n (#1)*(#1+1)/2 $

                                      ExplSyntaxOff

                                      begindocument

                                      [
                                      triangletab1 qquad triangletab3 qquad triangletab11
                                      ]

                                      [
                                      triangletab*1 qquad triangletab*3 qquad triangletab*11
                                      ]

                                      enddocument


                                      enter image description here






                                      share|improve this answer













                                      The mandatory double expl3 loop:



                                      documentclassarticle
                                      usepackagexparse,array

                                      ExplSyntaxOn
                                      NewDocumentCommandtriangletabsm
                                      % #1 = * for totals, #2 = end point
                                      IfBooleanTF #1

                                      begintabular@ l @ c @ r @
                                      int_step_inline:nn #2 panda_row_total:n ##1 \
                                      endtabular


                                      begintabular@ l @
                                      int_step_inline:nn #2 panda_row:n ##1 \
                                      endtabular


                                      cs_new_protected:Nn panda_row:n

                                      $1 int_step_inline:nnn 2 #1 + ##1 $

                                      cs_new_protected:Nn panda_row_total:n

                                      panda_row:n #1 & $=$ & $int_eval:n (#1)*(#1+1)/2 $

                                      ExplSyntaxOff

                                      begindocument

                                      [
                                      triangletab1 qquad triangletab3 qquad triangletab11
                                      ]

                                      [
                                      triangletab*1 qquad triangletab*3 qquad triangletab*11
                                      ]

                                      enddocument


                                      enter image description here







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered May 5 at 13:23









                                      egregegreg

                                      742k8919423274




                                      742k8919423274



























                                          draft saved

                                          draft discarded
















































                                          Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid


                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.

                                          To learn more, see our tips on writing great answers.




                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function ()
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f489242%2fhow-to-replace-space-with-symbol-in-a-triangular-array%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

                                          Wikipedia:Vital articles Мазмуну Biography - Өмүр баян Philosophy and psychology - Философия жана психология Religion - Дин Social sciences - Коомдук илимдер Language and literature - Тил жана адабият Science - Илим Technology - Технология Arts and recreation - Искусство жана эс алуу History and geography - Тарых жана география Навигация менюсу

                                          Bruxelas-Capital Índice Historia | Composición | Situación lingüística | Clima | Cidades irmandadas | Notas | Véxase tamén | Menú de navegacióneO uso das linguas en Bruxelas e a situación do neerlandés"Rexión de Bruxelas Capital"o orixinalSitio da rexiónPáxina de Bruselas no sitio da Oficina de Promoción Turística de Valonia e BruxelasMapa Interactivo da Rexión de Bruxelas-CapitaleeWorldCat332144929079854441105155190212ID28008674080552-90000 0001 0666 3698n94104302ID540940339365017018237

                                          What should I write in an apology letter, since I have decided not to join a company after accepting an offer letterShould I keep looking after accepting a job offer?What should I do when I've been verbally told I would get an offer letter, but still haven't gotten one after 4 weeks?Do I accept an offer from a company that I am not likely to join?New job hasn't confirmed starting date and I want to give current employer as much notice as possibleHow should I address my manager in my resignation letter?HR delayed background verification, now jobless as resignedNo email communication after accepting a formal written offer. How should I phrase the call?What should I do if after receiving a verbal offer letter I am informed that my written job offer is put on hold due to some internal issues?Should I inform the current employer that I am about to resign within 1-2 weeks since I have signed the offer letter and waiting for visa?What company will do, if I send their offer letter to another company