TikZ matrix, style for combination or rows and columnsIs there any efficient way to add cell identifier to each cell in TikZ?How to have a specific style for empty cells in a tikz matrixIs it possible to add node labels to some matrix column or row when building it?TikZ Colorize a matrixThe simplest way to fill a matrix of nodes?Scaled TikZ matrix of nodesHow to overalap textbox in tikz?Why does a definition of macro containing multi raster column n/.style fail in tcbset of tcolorboxHow to annotate and shade a matrixIntersection of paths with constructed namesHow do I encircle a partial table in tikz?tikz matrix align/decorate cellpicturesNumerical conditional within tikz keys?how can I create keys such as “column … to …” for a TikZ matrixWhy do I get an extra white page before my TikZ picture?Table-like lines in tikz matrixStriking out matrix lines and columns: is Tikz the only way?How to draw a square and its diagonals with arrows?Limiting the scope of styles in TikZ matrix of nodes

How to deal with taxi scam when on vacation?

Are ETF trackers fundamentally better than individual stocks?

The difference between「N分で」and「後N分で」

Why doesn't using two cd commands in bash script execute the second command?

My adviser wants to be the first author

Brexit - No Deal Rejection

Professor being mistaken for a grad student

How do I hide Chekhov's Gun?

Use of undefined constant bloginfo

Have researchers managed to "reverse time"? If so, what does that mean for physics?

Life insurance that covers only simultaneous/dual deaths

Logical notation

My Graph Theory Students

Happy pi day, everyone!

What is this large pipe coming out of my roof?

Look at your watch and tell me what time is it. vs Look at your watch and tell me what time it is

Most cost effective thermostat setting: consistent temperature vs. lowest temperature possible

Is a party consisting of only a bard, a cleric, and a warlock functional long-term?

AG Cluster db upgrade by vendor

Python if-else code style for reduced code

How to change two letters closest to a string and one letter immediately after a string using notepad++

What are substitutions for coconut in curry?

What options are left, if Britain cannot decide?

What is the rarity of this homebrew magic staff?



TikZ matrix, style for combination or rows and columns


Is there any efficient way to add cell identifier to each cell in TikZ?How to have a specific style for empty cells in a tikz matrixIs it possible to add node labels to some matrix column or row when building it?TikZ Colorize a matrixThe simplest way to fill a matrix of nodes?Scaled TikZ matrix of nodesHow to overalap textbox in tikz?Why does a definition of macro containing multi raster column n/.style fail in tcbset of tcolorboxHow to annotate and shade a matrixIntersection of paths with constructed namesHow do I encircle a partial table in tikz?tikz matrix align/decorate cellpicturesNumerical conditional within tikz keys?how can I create keys such as “column … to …” for a TikZ matrixWhy do I get an extra white page before my TikZ picture?Table-like lines in tikz matrixStriking out matrix lines and columns: is Tikz the only way?How to draw a square and its diagonals with arrows?Limiting the scope of styles in TikZ matrix of nodes













11















In the TikZ manual we have the example below that shows how to apply an style to an entry of the matrix. It is also easy to apply it for an entire row and an entire column. My question is how can we achieve the same for several entries? Is there a simple way to specify a style, say for example, rows 1 & 3 and columns 1 & 2?



documentclassbeamer
usepackagetikz
usetikzlibrarymatrix
begindocument
begintikzpicture[row 2 column 3/.style=red]
matrix [matrix of nodes]

8 & 1 & 6 \
3 & 5 & 7 \
4 & 9 & 2 \
;
endtikzpicture
enddocument









share|improve this question



















  • 1





    How simple? [row 1/.style=red, row 3/.style=red]

    – John Kormylo
    May 6 '14 at 13:32











  • @JohnKormylo: Thanks but say the style is very long to type, is there a way to make it even simpler? Something like: row 1,3 /.style=... ?

    – Sergio Parreiras
    May 6 '14 at 15:57












  • You could create a new command, but it might get ugly.

    – John Kormylo
    May 6 '14 at 23:34















11















In the TikZ manual we have the example below that shows how to apply an style to an entry of the matrix. It is also easy to apply it for an entire row and an entire column. My question is how can we achieve the same for several entries? Is there a simple way to specify a style, say for example, rows 1 & 3 and columns 1 & 2?



documentclassbeamer
usepackagetikz
usetikzlibrarymatrix
begindocument
begintikzpicture[row 2 column 3/.style=red]
matrix [matrix of nodes]

8 & 1 & 6 \
3 & 5 & 7 \
4 & 9 & 2 \
;
endtikzpicture
enddocument









share|improve this question



















  • 1





    How simple? [row 1/.style=red, row 3/.style=red]

    – John Kormylo
    May 6 '14 at 13:32











  • @JohnKormylo: Thanks but say the style is very long to type, is there a way to make it even simpler? Something like: row 1,3 /.style=... ?

    – Sergio Parreiras
    May 6 '14 at 15:57












  • You could create a new command, but it might get ugly.

    – John Kormylo
    May 6 '14 at 23:34













11












11








11


4






In the TikZ manual we have the example below that shows how to apply an style to an entry of the matrix. It is also easy to apply it for an entire row and an entire column. My question is how can we achieve the same for several entries? Is there a simple way to specify a style, say for example, rows 1 & 3 and columns 1 & 2?



documentclassbeamer
usepackagetikz
usetikzlibrarymatrix
begindocument
begintikzpicture[row 2 column 3/.style=red]
matrix [matrix of nodes]

8 & 1 & 6 \
3 & 5 & 7 \
4 & 9 & 2 \
;
endtikzpicture
enddocument









share|improve this question
















In the TikZ manual we have the example below that shows how to apply an style to an entry of the matrix. It is also easy to apply it for an entire row and an entire column. My question is how can we achieve the same for several entries? Is there a simple way to specify a style, say for example, rows 1 & 3 and columns 1 & 2?



documentclassbeamer
usepackagetikz
usetikzlibrarymatrix
begindocument
begintikzpicture[row 2 column 3/.style=red]
matrix [matrix of nodes]

8 & 1 & 6 \
3 & 5 & 7 \
4 & 9 & 2 \
;
endtikzpicture
enddocument






tikz-pgf tikz-matrix






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 7 '14 at 8:14







Sergio Parreiras

















asked May 6 '14 at 12:31









Sergio ParreirasSergio Parreiras

6681825




6681825







  • 1





    How simple? [row 1/.style=red, row 3/.style=red]

    – John Kormylo
    May 6 '14 at 13:32











  • @JohnKormylo: Thanks but say the style is very long to type, is there a way to make it even simpler? Something like: row 1,3 /.style=... ?

    – Sergio Parreiras
    May 6 '14 at 15:57












  • You could create a new command, but it might get ugly.

    – John Kormylo
    May 6 '14 at 23:34












  • 1





    How simple? [row 1/.style=red, row 3/.style=red]

    – John Kormylo
    May 6 '14 at 13:32











  • @JohnKormylo: Thanks but say the style is very long to type, is there a way to make it even simpler? Something like: row 1,3 /.style=... ?

    – Sergio Parreiras
    May 6 '14 at 15:57












  • You could create a new command, but it might get ugly.

    – John Kormylo
    May 6 '14 at 23:34







1




1





How simple? [row 1/.style=red, row 3/.style=red]

– John Kormylo
May 6 '14 at 13:32





How simple? [row 1/.style=red, row 3/.style=red]

– John Kormylo
May 6 '14 at 13:32













@JohnKormylo: Thanks but say the style is very long to type, is there a way to make it even simpler? Something like: row 1,3 /.style=... ?

– Sergio Parreiras
May 6 '14 at 15:57






@JohnKormylo: Thanks but say the style is very long to type, is there a way to make it even simpler? Something like: row 1,3 /.style=... ?

– Sergio Parreiras
May 6 '14 at 15:57














You could create a new command, but it might get ugly.

– John Kormylo
May 6 '14 at 23:34





You could create a new command, but it might get ugly.

– John Kormylo
May 6 '14 at 23:34










5 Answers
5






active

oldest

votes


















14














You can use the /.list feature John Kormylo mentioned in his answer to repeat a style for different inputs.



documentclassarticle
usepackagetikz
usetikzlibrarymatrix
begindocument
tikzsetmyset/.style=row 2 column #1/.style=nodes=text=red
begintikzpicture[myset/.list=1,3,5]
matrix [matrix of nodes]

8 & 1 & 6 & 8 & 1 & 6 \
3 & 5 & 7 & 3 & 5 & 7 \
4 & 9 & 2 & 4 & 9 & 2 \
;
endtikzpicture
enddocument


enter image description here






share|improve this answer























  • list will be very useful for other projects, thanks! By any chance, besides the manual do you have any suggestions on references for TikZ programming?

    – Sergio Parreiras
    May 7 '14 at 8:32






  • 1





    @SergioParreiras Manual is very very good. I would say answer questions here :P It gives you a lot of practice and gives a chance to see others do their black magic.

    – percusse
    May 7 '14 at 8:33


















8














More a long comment than a real answer... Based on percusse's answer, this style allows to specify both row and column.



documentclassstandalone
usepackagetikz
usetikzlibrarymatrix
begindocument
tikzsetmyset/.style args = (#1,#2)%
row #1 column #2/.style=nodes=text=red
begintikzpicture[myset/.list=(2,1),(3,3),(1,5)]
matrix [matrix of nodes]

8 & 1 & 6 & 8 & 1 & 6 \
3 & 5 & 7 & 3 & 5 & 7 \
4 & 9 & 2 & 4 & 9 & 2 \
;
endtikzpicture
enddocument


enter image description here






share|improve this answer
































    7














    This can be done via foreach indeed, but since the keys set with pgfkeys are not global, their assignment are lost when the loop is exited. Unless you mess with globaldef, as in the following example:



    documentclassarticle
    usepackagetikz
    usetikzlibrarymatrix
    begindocument

    newcommandrows[2]% #1 = rows, #2 = style
    foreach r in #1 %
    globaldefs=1relax
    tikzsetrow r/.style=#2
    %


    newcommandcols[2]% #1 = columns, #2 = style
    foreach r in #1 %
    globaldefs=1relax
    tikzsetcolumn r/.style=#2
    %


    begintikzpicture
    cols1,3blue
    rows1,3red
    matrix [matrix of nodes]

    8 & 1 & 6 \
    3 & 5 & 7 \
    4 & 9 & 2 \
    ;
    endtikzpicture
    enddocument


    Result






    share|improve this answer























    • Consider me considerably less fuzzy now.

      – John Kormylo
      May 7 '14 at 14:06


















    2














    Interestingly, you cannot do this using foreach. I understand this is because foreach is actually implemented using pgfkeys using the /.list=... feature, but I'm a bit fuzzy on the details.



    documentclassstandalone
    usepackagetikz
    usetikzlibrarymatrix

    newcommandrow[2]% #1 = row, #2 = style
    tikzsetrow #1/.style=#2

    newcommandcol[2]% #1 = column, #2 = style
    tikzsetcolumn #1/.style=#2

    begindocument
    begintikzpicture
    row1red
    row3red
    col1blue
    col3blue
    matrix [matrix of nodes]

    8 & 1 & 6 \
    3 & 5 & 7 \
    4 & 9 & 2 \
    ;
    endtikzpicture
    enddocument





    share|improve this answer






























      0














      I reopen this old questions because, from percusse's and cjorssen's answers, I managed to assign style to a block of cells only specifying its (top,left to bottom,right) coordinates. I share here my solution, hoping it will help someone else.



      documentclassstandalone
      usepackagetikz
      usetikzlibrarymatrix
      begindocument
      tikzsetmyblocks/.style args = (#1,#2 to #3,#4)
      blockrows/.style=
      block/.style=
      row ##1 column ####1/.style=nodes=text=red
      ,
      block/.list=#2,...,#4
      ,
      blockrows/.list=#1,...,#3


      begintikzpicture[myblocks/.list=(1,1 to 2,2),(1,4 to 3,5)]
      matrix [matrix of nodes]

      8 & 1 & 6 & 8 & 1 & 6 \
      3 & 5 & 7 & 3 & 5 & 7 \
      4 & 9 & 2 & 4 & 9 & 2 \
      ;
      endtikzpicture
      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%2f175616%2ftikz-matrix-style-for-combination-or-rows-and-columns%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









        14














        You can use the /.list feature John Kormylo mentioned in his answer to repeat a style for different inputs.



        documentclassarticle
        usepackagetikz
        usetikzlibrarymatrix
        begindocument
        tikzsetmyset/.style=row 2 column #1/.style=nodes=text=red
        begintikzpicture[myset/.list=1,3,5]
        matrix [matrix of nodes]

        8 & 1 & 6 & 8 & 1 & 6 \
        3 & 5 & 7 & 3 & 5 & 7 \
        4 & 9 & 2 & 4 & 9 & 2 \
        ;
        endtikzpicture
        enddocument


        enter image description here






        share|improve this answer























        • list will be very useful for other projects, thanks! By any chance, besides the manual do you have any suggestions on references for TikZ programming?

          – Sergio Parreiras
          May 7 '14 at 8:32






        • 1





          @SergioParreiras Manual is very very good. I would say answer questions here :P It gives you a lot of practice and gives a chance to see others do their black magic.

          – percusse
          May 7 '14 at 8:33















        14














        You can use the /.list feature John Kormylo mentioned in his answer to repeat a style for different inputs.



        documentclassarticle
        usepackagetikz
        usetikzlibrarymatrix
        begindocument
        tikzsetmyset/.style=row 2 column #1/.style=nodes=text=red
        begintikzpicture[myset/.list=1,3,5]
        matrix [matrix of nodes]

        8 & 1 & 6 & 8 & 1 & 6 \
        3 & 5 & 7 & 3 & 5 & 7 \
        4 & 9 & 2 & 4 & 9 & 2 \
        ;
        endtikzpicture
        enddocument


        enter image description here






        share|improve this answer























        • list will be very useful for other projects, thanks! By any chance, besides the manual do you have any suggestions on references for TikZ programming?

          – Sergio Parreiras
          May 7 '14 at 8:32






        • 1





          @SergioParreiras Manual is very very good. I would say answer questions here :P It gives you a lot of practice and gives a chance to see others do their black magic.

          – percusse
          May 7 '14 at 8:33













        14












        14








        14







        You can use the /.list feature John Kormylo mentioned in his answer to repeat a style for different inputs.



        documentclassarticle
        usepackagetikz
        usetikzlibrarymatrix
        begindocument
        tikzsetmyset/.style=row 2 column #1/.style=nodes=text=red
        begintikzpicture[myset/.list=1,3,5]
        matrix [matrix of nodes]

        8 & 1 & 6 & 8 & 1 & 6 \
        3 & 5 & 7 & 3 & 5 & 7 \
        4 & 9 & 2 & 4 & 9 & 2 \
        ;
        endtikzpicture
        enddocument


        enter image description here






        share|improve this answer













        You can use the /.list feature John Kormylo mentioned in his answer to repeat a style for different inputs.



        documentclassarticle
        usepackagetikz
        usetikzlibrarymatrix
        begindocument
        tikzsetmyset/.style=row 2 column #1/.style=nodes=text=red
        begintikzpicture[myset/.list=1,3,5]
        matrix [matrix of nodes]

        8 & 1 & 6 & 8 & 1 & 6 \
        3 & 5 & 7 & 3 & 5 & 7 \
        4 & 9 & 2 & 4 & 9 & 2 \
        ;
        endtikzpicture
        enddocument


        enter image description here







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered May 7 '14 at 8:23









        percussepercusse

        138k14258496




        138k14258496












        • list will be very useful for other projects, thanks! By any chance, besides the manual do you have any suggestions on references for TikZ programming?

          – Sergio Parreiras
          May 7 '14 at 8:32






        • 1





          @SergioParreiras Manual is very very good. I would say answer questions here :P It gives you a lot of practice and gives a chance to see others do their black magic.

          – percusse
          May 7 '14 at 8:33

















        • list will be very useful for other projects, thanks! By any chance, besides the manual do you have any suggestions on references for TikZ programming?

          – Sergio Parreiras
          May 7 '14 at 8:32






        • 1





          @SergioParreiras Manual is very very good. I would say answer questions here :P It gives you a lot of practice and gives a chance to see others do their black magic.

          – percusse
          May 7 '14 at 8:33
















        list will be very useful for other projects, thanks! By any chance, besides the manual do you have any suggestions on references for TikZ programming?

        – Sergio Parreiras
        May 7 '14 at 8:32





        list will be very useful for other projects, thanks! By any chance, besides the manual do you have any suggestions on references for TikZ programming?

        – Sergio Parreiras
        May 7 '14 at 8:32




        1




        1





        @SergioParreiras Manual is very very good. I would say answer questions here :P It gives you a lot of practice and gives a chance to see others do their black magic.

        – percusse
        May 7 '14 at 8:33





        @SergioParreiras Manual is very very good. I would say answer questions here :P It gives you a lot of practice and gives a chance to see others do their black magic.

        – percusse
        May 7 '14 at 8:33











        8














        More a long comment than a real answer... Based on percusse's answer, this style allows to specify both row and column.



        documentclassstandalone
        usepackagetikz
        usetikzlibrarymatrix
        begindocument
        tikzsetmyset/.style args = (#1,#2)%
        row #1 column #2/.style=nodes=text=red
        begintikzpicture[myset/.list=(2,1),(3,3),(1,5)]
        matrix [matrix of nodes]

        8 & 1 & 6 & 8 & 1 & 6 \
        3 & 5 & 7 & 3 & 5 & 7 \
        4 & 9 & 2 & 4 & 9 & 2 \
        ;
        endtikzpicture
        enddocument


        enter image description here






        share|improve this answer





























          8














          More a long comment than a real answer... Based on percusse's answer, this style allows to specify both row and column.



          documentclassstandalone
          usepackagetikz
          usetikzlibrarymatrix
          begindocument
          tikzsetmyset/.style args = (#1,#2)%
          row #1 column #2/.style=nodes=text=red
          begintikzpicture[myset/.list=(2,1),(3,3),(1,5)]
          matrix [matrix of nodes]

          8 & 1 & 6 & 8 & 1 & 6 \
          3 & 5 & 7 & 3 & 5 & 7 \
          4 & 9 & 2 & 4 & 9 & 2 \
          ;
          endtikzpicture
          enddocument


          enter image description here






          share|improve this answer



























            8












            8








            8







            More a long comment than a real answer... Based on percusse's answer, this style allows to specify both row and column.



            documentclassstandalone
            usepackagetikz
            usetikzlibrarymatrix
            begindocument
            tikzsetmyset/.style args = (#1,#2)%
            row #1 column #2/.style=nodes=text=red
            begintikzpicture[myset/.list=(2,1),(3,3),(1,5)]
            matrix [matrix of nodes]

            8 & 1 & 6 & 8 & 1 & 6 \
            3 & 5 & 7 & 3 & 5 & 7 \
            4 & 9 & 2 & 4 & 9 & 2 \
            ;
            endtikzpicture
            enddocument


            enter image description here






            share|improve this answer















            More a long comment than a real answer... Based on percusse's answer, this style allows to specify both row and column.



            documentclassstandalone
            usepackagetikz
            usetikzlibrarymatrix
            begindocument
            tikzsetmyset/.style args = (#1,#2)%
            row #1 column #2/.style=nodes=text=red
            begintikzpicture[myset/.list=(2,1),(3,3),(1,5)]
            matrix [matrix of nodes]

            8 & 1 & 6 & 8 & 1 & 6 \
            3 & 5 & 7 & 3 & 5 & 7 \
            4 & 9 & 2 & 4 & 9 & 2 \
            ;
            endtikzpicture
            enddocument


            enter image description here







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Apr 13 '17 at 12:35









            Community

            1




            1










            answered May 7 '14 at 9:09









            cjorssencjorssen

            5,646225104




            5,646225104





















                7














                This can be done via foreach indeed, but since the keys set with pgfkeys are not global, their assignment are lost when the loop is exited. Unless you mess with globaldef, as in the following example:



                documentclassarticle
                usepackagetikz
                usetikzlibrarymatrix
                begindocument

                newcommandrows[2]% #1 = rows, #2 = style
                foreach r in #1 %
                globaldefs=1relax
                tikzsetrow r/.style=#2
                %


                newcommandcols[2]% #1 = columns, #2 = style
                foreach r in #1 %
                globaldefs=1relax
                tikzsetcolumn r/.style=#2
                %


                begintikzpicture
                cols1,3blue
                rows1,3red
                matrix [matrix of nodes]

                8 & 1 & 6 \
                3 & 5 & 7 \
                4 & 9 & 2 \
                ;
                endtikzpicture
                enddocument


                Result






                share|improve this answer























                • Consider me considerably less fuzzy now.

                  – John Kormylo
                  May 7 '14 at 14:06















                7














                This can be done via foreach indeed, but since the keys set with pgfkeys are not global, their assignment are lost when the loop is exited. Unless you mess with globaldef, as in the following example:



                documentclassarticle
                usepackagetikz
                usetikzlibrarymatrix
                begindocument

                newcommandrows[2]% #1 = rows, #2 = style
                foreach r in #1 %
                globaldefs=1relax
                tikzsetrow r/.style=#2
                %


                newcommandcols[2]% #1 = columns, #2 = style
                foreach r in #1 %
                globaldefs=1relax
                tikzsetcolumn r/.style=#2
                %


                begintikzpicture
                cols1,3blue
                rows1,3red
                matrix [matrix of nodes]

                8 & 1 & 6 \
                3 & 5 & 7 \
                4 & 9 & 2 \
                ;
                endtikzpicture
                enddocument


                Result






                share|improve this answer























                • Consider me considerably less fuzzy now.

                  – John Kormylo
                  May 7 '14 at 14:06













                7












                7








                7







                This can be done via foreach indeed, but since the keys set with pgfkeys are not global, their assignment are lost when the loop is exited. Unless you mess with globaldef, as in the following example:



                documentclassarticle
                usepackagetikz
                usetikzlibrarymatrix
                begindocument

                newcommandrows[2]% #1 = rows, #2 = style
                foreach r in #1 %
                globaldefs=1relax
                tikzsetrow r/.style=#2
                %


                newcommandcols[2]% #1 = columns, #2 = style
                foreach r in #1 %
                globaldefs=1relax
                tikzsetcolumn r/.style=#2
                %


                begintikzpicture
                cols1,3blue
                rows1,3red
                matrix [matrix of nodes]

                8 & 1 & 6 \
                3 & 5 & 7 \
                4 & 9 & 2 \
                ;
                endtikzpicture
                enddocument


                Result






                share|improve this answer













                This can be done via foreach indeed, but since the keys set with pgfkeys are not global, their assignment are lost when the loop is exited. Unless you mess with globaldef, as in the following example:



                documentclassarticle
                usepackagetikz
                usetikzlibrarymatrix
                begindocument

                newcommandrows[2]% #1 = rows, #2 = style
                foreach r in #1 %
                globaldefs=1relax
                tikzsetrow r/.style=#2
                %


                newcommandcols[2]% #1 = columns, #2 = style
                foreach r in #1 %
                globaldefs=1relax
                tikzsetcolumn r/.style=#2
                %


                begintikzpicture
                cols1,3blue
                rows1,3red
                matrix [matrix of nodes]

                8 & 1 & 6 \
                3 & 5 & 7 \
                4 & 9 & 2 \
                ;
                endtikzpicture
                enddocument


                Result







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered May 7 '14 at 8:36









                JLDiazJLDiaz

                50.1k4123186




                50.1k4123186












                • Consider me considerably less fuzzy now.

                  – John Kormylo
                  May 7 '14 at 14:06

















                • Consider me considerably less fuzzy now.

                  – John Kormylo
                  May 7 '14 at 14:06
















                Consider me considerably less fuzzy now.

                – John Kormylo
                May 7 '14 at 14:06





                Consider me considerably less fuzzy now.

                – John Kormylo
                May 7 '14 at 14:06











                2














                Interestingly, you cannot do this using foreach. I understand this is because foreach is actually implemented using pgfkeys using the /.list=... feature, but I'm a bit fuzzy on the details.



                documentclassstandalone
                usepackagetikz
                usetikzlibrarymatrix

                newcommandrow[2]% #1 = row, #2 = style
                tikzsetrow #1/.style=#2

                newcommandcol[2]% #1 = column, #2 = style
                tikzsetcolumn #1/.style=#2

                begindocument
                begintikzpicture
                row1red
                row3red
                col1blue
                col3blue
                matrix [matrix of nodes]

                8 & 1 & 6 \
                3 & 5 & 7 \
                4 & 9 & 2 \
                ;
                endtikzpicture
                enddocument





                share|improve this answer



























                  2














                  Interestingly, you cannot do this using foreach. I understand this is because foreach is actually implemented using pgfkeys using the /.list=... feature, but I'm a bit fuzzy on the details.



                  documentclassstandalone
                  usepackagetikz
                  usetikzlibrarymatrix

                  newcommandrow[2]% #1 = row, #2 = style
                  tikzsetrow #1/.style=#2

                  newcommandcol[2]% #1 = column, #2 = style
                  tikzsetcolumn #1/.style=#2

                  begindocument
                  begintikzpicture
                  row1red
                  row3red
                  col1blue
                  col3blue
                  matrix [matrix of nodes]

                  8 & 1 & 6 \
                  3 & 5 & 7 \
                  4 & 9 & 2 \
                  ;
                  endtikzpicture
                  enddocument





                  share|improve this answer

























                    2












                    2








                    2







                    Interestingly, you cannot do this using foreach. I understand this is because foreach is actually implemented using pgfkeys using the /.list=... feature, but I'm a bit fuzzy on the details.



                    documentclassstandalone
                    usepackagetikz
                    usetikzlibrarymatrix

                    newcommandrow[2]% #1 = row, #2 = style
                    tikzsetrow #1/.style=#2

                    newcommandcol[2]% #1 = column, #2 = style
                    tikzsetcolumn #1/.style=#2

                    begindocument
                    begintikzpicture
                    row1red
                    row3red
                    col1blue
                    col3blue
                    matrix [matrix of nodes]

                    8 & 1 & 6 \
                    3 & 5 & 7 \
                    4 & 9 & 2 \
                    ;
                    endtikzpicture
                    enddocument





                    share|improve this answer













                    Interestingly, you cannot do this using foreach. I understand this is because foreach is actually implemented using pgfkeys using the /.list=... feature, but I'm a bit fuzzy on the details.



                    documentclassstandalone
                    usepackagetikz
                    usetikzlibrarymatrix

                    newcommandrow[2]% #1 = row, #2 = style
                    tikzsetrow #1/.style=#2

                    newcommandcol[2]% #1 = column, #2 = style
                    tikzsetcolumn #1/.style=#2

                    begindocument
                    begintikzpicture
                    row1red
                    row3red
                    col1blue
                    col3blue
                    matrix [matrix of nodes]

                    8 & 1 & 6 \
                    3 & 5 & 7 \
                    4 & 9 & 2 \
                    ;
                    endtikzpicture
                    enddocument






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered May 7 '14 at 3:34









                    John KormyloJohn Kormylo

                    45.2k12570




                    45.2k12570





















                        0














                        I reopen this old questions because, from percusse's and cjorssen's answers, I managed to assign style to a block of cells only specifying its (top,left to bottom,right) coordinates. I share here my solution, hoping it will help someone else.



                        documentclassstandalone
                        usepackagetikz
                        usetikzlibrarymatrix
                        begindocument
                        tikzsetmyblocks/.style args = (#1,#2 to #3,#4)
                        blockrows/.style=
                        block/.style=
                        row ##1 column ####1/.style=nodes=text=red
                        ,
                        block/.list=#2,...,#4
                        ,
                        blockrows/.list=#1,...,#3


                        begintikzpicture[myblocks/.list=(1,1 to 2,2),(1,4 to 3,5)]
                        matrix [matrix of nodes]

                        8 & 1 & 6 & 8 & 1 & 6 \
                        3 & 5 & 7 & 3 & 5 & 7 \
                        4 & 9 & 2 & 4 & 9 & 2 \
                        ;
                        endtikzpicture
                        enddocument


                        enter image description here






                        share|improve this answer





























                          0














                          I reopen this old questions because, from percusse's and cjorssen's answers, I managed to assign style to a block of cells only specifying its (top,left to bottom,right) coordinates. I share here my solution, hoping it will help someone else.



                          documentclassstandalone
                          usepackagetikz
                          usetikzlibrarymatrix
                          begindocument
                          tikzsetmyblocks/.style args = (#1,#2 to #3,#4)
                          blockrows/.style=
                          block/.style=
                          row ##1 column ####1/.style=nodes=text=red
                          ,
                          block/.list=#2,...,#4
                          ,
                          blockrows/.list=#1,...,#3


                          begintikzpicture[myblocks/.list=(1,1 to 2,2),(1,4 to 3,5)]
                          matrix [matrix of nodes]

                          8 & 1 & 6 & 8 & 1 & 6 \
                          3 & 5 & 7 & 3 & 5 & 7 \
                          4 & 9 & 2 & 4 & 9 & 2 \
                          ;
                          endtikzpicture
                          enddocument


                          enter image description here






                          share|improve this answer



























                            0












                            0








                            0







                            I reopen this old questions because, from percusse's and cjorssen's answers, I managed to assign style to a block of cells only specifying its (top,left to bottom,right) coordinates. I share here my solution, hoping it will help someone else.



                            documentclassstandalone
                            usepackagetikz
                            usetikzlibrarymatrix
                            begindocument
                            tikzsetmyblocks/.style args = (#1,#2 to #3,#4)
                            blockrows/.style=
                            block/.style=
                            row ##1 column ####1/.style=nodes=text=red
                            ,
                            block/.list=#2,...,#4
                            ,
                            blockrows/.list=#1,...,#3


                            begintikzpicture[myblocks/.list=(1,1 to 2,2),(1,4 to 3,5)]
                            matrix [matrix of nodes]

                            8 & 1 & 6 & 8 & 1 & 6 \
                            3 & 5 & 7 & 3 & 5 & 7 \
                            4 & 9 & 2 & 4 & 9 & 2 \
                            ;
                            endtikzpicture
                            enddocument


                            enter image description here






                            share|improve this answer















                            I reopen this old questions because, from percusse's and cjorssen's answers, I managed to assign style to a block of cells only specifying its (top,left to bottom,right) coordinates. I share here my solution, hoping it will help someone else.



                            documentclassstandalone
                            usepackagetikz
                            usetikzlibrarymatrix
                            begindocument
                            tikzsetmyblocks/.style args = (#1,#2 to #3,#4)
                            blockrows/.style=
                            block/.style=
                            row ##1 column ####1/.style=nodes=text=red
                            ,
                            block/.list=#2,...,#4
                            ,
                            blockrows/.list=#1,...,#3


                            begintikzpicture[myblocks/.list=(1,1 to 2,2),(1,4 to 3,5)]
                            matrix [matrix of nodes]

                            8 & 1 & 6 & 8 & 1 & 6 \
                            3 & 5 & 7 & 3 & 5 & 7 \
                            4 & 9 & 2 & 4 & 9 & 2 \
                            ;
                            endtikzpicture
                            enddocument


                            enter image description here







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited 8 mins ago

























                            answered 14 mins ago









                            JPGJPG

                            1,392413




                            1,392413



























                                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%2f175616%2ftikz-matrix-style-for-combination-or-rows-and-columns%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

                                Isabella Eugénie Boyer Biographie | Références | Menu de navigationmodifiermodifier le codeComparator to Compute the Relative Value of a U.S. Dollar Amount – 1774 to Present.

                                Join wedge with single bond in chemfigHow to make only one part of double bond bold with chemfig?Crossing bonds in chemfigjoining atoms in chemfig. Two adjacent molculesHow do I selectively change bond length in chemfig?Ugly bond joints in chemfigchemfig: reaction above arrowUsing the mhchem and chemfig packages in conjunctionBonding to specific element letter using chemfigResonance hybrids in chemfigScale chemfig molecule in beamer with tikzWhy does this chemfig bond with a hook start in the middle of the atom?

                                Are small insurances worth itIs insurance worth it if you can afford to replace the item? If not, when is it?Is accident insurance worth it for my kids who play sportsIs insuring property for more than it is worth allowed?At what point does it become worth it to file an insurance claim?Are wage loss insurance programs worth the cost compared to having an emergency fund?When is an event worth insuring against?Is insurance worth it if you can afford to replace the item? If not, when is it?FHA loan just commenced : Any way to get any of the up-front mortgage insurance back?Which types of insurances do I need to buy?Should I carry less renter's insurance if I can self-insure?Mortgage Adviser Signed Me Up For Multiple Home and Life Insurances (UK)Why many travel insurances don't cover country of nationality?