Bug or feature: tikz interprets color specification differently for rectangles












8














When drawing a rectangle, Tikz interprets color in two different ways, depending on in which order it is specified among the options.



In the example below: When color is specified first, as in the first two example, it is used to color the frame of the rectangle---as I'd expect. But in the third rectangle, the red color specification actually fills the rectangle with red. Is this expected?



documentclass{article}

usepackage{tikz}

begin{document}
begin{tikzpicture}
draw[color=red,very thick] (0,0) rectangle (1,1);
draw[color=red,very thick,fill=blue] (2,0) rectangle (3,1);
draw[very thick,fill=blue,color=red] (4,0) rectangle (5,1);
end{tikzpicture}
end{document}


3 squares










share|improve this question



























    8














    When drawing a rectangle, Tikz interprets color in two different ways, depending on in which order it is specified among the options.



    In the example below: When color is specified first, as in the first two example, it is used to color the frame of the rectangle---as I'd expect. But in the third rectangle, the red color specification actually fills the rectangle with red. Is this expected?



    documentclass{article}

    usepackage{tikz}

    begin{document}
    begin{tikzpicture}
    draw[color=red,very thick] (0,0) rectangle (1,1);
    draw[color=red,very thick,fill=blue] (2,0) rectangle (3,1);
    draw[very thick,fill=blue,color=red] (4,0) rectangle (5,1);
    end{tikzpicture}
    end{document}


    3 squares










    share|improve this question

























      8












      8








      8


      0





      When drawing a rectangle, Tikz interprets color in two different ways, depending on in which order it is specified among the options.



      In the example below: When color is specified first, as in the first two example, it is used to color the frame of the rectangle---as I'd expect. But in the third rectangle, the red color specification actually fills the rectangle with red. Is this expected?



      documentclass{article}

      usepackage{tikz}

      begin{document}
      begin{tikzpicture}
      draw[color=red,very thick] (0,0) rectangle (1,1);
      draw[color=red,very thick,fill=blue] (2,0) rectangle (3,1);
      draw[very thick,fill=blue,color=red] (4,0) rectangle (5,1);
      end{tikzpicture}
      end{document}


      3 squares










      share|improve this question













      When drawing a rectangle, Tikz interprets color in two different ways, depending on in which order it is specified among the options.



      In the example below: When color is specified first, as in the first two example, it is used to color the frame of the rectangle---as I'd expect. But in the third rectangle, the red color specification actually fills the rectangle with red. Is this expected?



      documentclass{article}

      usepackage{tikz}

      begin{document}
      begin{tikzpicture}
      draw[color=red,very thick] (0,0) rectangle (1,1);
      draw[color=red,very thick,fill=blue] (2,0) rectangle (3,1);
      draw[very thick,fill=blue,color=red] (4,0) rectangle (5,1);
      end{tikzpicture}
      end{document}


      3 squares







      tikz-pgf color






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 21 hours ago









      Máté Wierdl

      46928




      46928






















          2 Answers
          2






          active

          oldest

          votes


















          10














          You are using the wrong key. color sets fill, draw and text. That said, it will only set the color and does not apply it/the operation.





          • draw[color=red] will draw a red frame (equals draw[draw=red])


          • draw[color=red,fill] will draw a red frame filled with red (equals draw[fill=red] or filldraw[red])


          • draw[color=red,draw=none] will draw a red fill but no frame (equals fill[red])


          • draw[color=red] node {Test}; will draw a node with red text (equals draw[text=red] node {Test};


          TLDR: Use draw to change the frame.



          documentclass{article}

          usepackage{tikz}

          begin{document}
          begin{tikzpicture}
          draw[color=red,very thick] (0,0) rectangle (1,1);
          draw[color=red,very thick,fill=blue] (2,0) rectangle (3,1);
          draw[very thick,fill=blue,draw=red] (4,0) rectangle (5,1);
          end{tikzpicture}
          end{document}





          share|improve this answer



















          • 1




            The assertion it will not add a fill color if you do not specify fill is not exact. Actually, as @AndréC says, color=red set all the three default colors for draw, fill and text. But if there is no an actual command like draw of fill you simply can't see it. For example in draw[color=red,very thick,fill] ... it will fill in red because the default fill color is set to red.
            – Kpym
            20 hours ago






          • 1




            @Kpym I am not sure I agree. (Actually I like and upvoted your answer and am wondering why you removed it.) I guess the cleanest answer may be to just copy the tikzoption{color}{....} code and discuss what it means. This also clarifies the "hierarchy" and "inheritances" between the different keys. And, as you know very well, it is actually nontrivial to figure out what the current color is. And there are much more advanced discussions IMHO such as this one and the links there...
            – marmot
            18 hours ago










          • @marmot I deleted my answer because it is wrong. It is not true that in a draw command the color=red is equivalent to draw=red,text=red. The proof is that if you add fill after the color=red it will not fill in the default fill color (usually black), but in red.
            – Kpym
            17 hours ago










          • @Kpym I see. (Whenever I am confused I really just look through tikzoption{color}{....} to understand what's going on. Maybe TeXnician wants to add this information to their nice answer, in which case I could remove these comments... ;-)
            – marmot
            17 hours ago












          • @marmot I've tried to extend my post. Is it better now?
            – TeXnician
            6 hours ago



















          6














          Yes because this option rewrites the colors on the draw, fill operations, i quote the 3.0.1a manual on page 165:




          /tikz/color=<color name> (no default) This option sets the color that
          is used for fill, drawing, and text inside the current scope.







          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%2f468439%2fbug-or-feature-tikz-interprets-color-specification-differently-for-rectangles%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            10














            You are using the wrong key. color sets fill, draw and text. That said, it will only set the color and does not apply it/the operation.





            • draw[color=red] will draw a red frame (equals draw[draw=red])


            • draw[color=red,fill] will draw a red frame filled with red (equals draw[fill=red] or filldraw[red])


            • draw[color=red,draw=none] will draw a red fill but no frame (equals fill[red])


            • draw[color=red] node {Test}; will draw a node with red text (equals draw[text=red] node {Test};


            TLDR: Use draw to change the frame.



            documentclass{article}

            usepackage{tikz}

            begin{document}
            begin{tikzpicture}
            draw[color=red,very thick] (0,0) rectangle (1,1);
            draw[color=red,very thick,fill=blue] (2,0) rectangle (3,1);
            draw[very thick,fill=blue,draw=red] (4,0) rectangle (5,1);
            end{tikzpicture}
            end{document}





            share|improve this answer



















            • 1




              The assertion it will not add a fill color if you do not specify fill is not exact. Actually, as @AndréC says, color=red set all the three default colors for draw, fill and text. But if there is no an actual command like draw of fill you simply can't see it. For example in draw[color=red,very thick,fill] ... it will fill in red because the default fill color is set to red.
              – Kpym
              20 hours ago






            • 1




              @Kpym I am not sure I agree. (Actually I like and upvoted your answer and am wondering why you removed it.) I guess the cleanest answer may be to just copy the tikzoption{color}{....} code and discuss what it means. This also clarifies the "hierarchy" and "inheritances" between the different keys. And, as you know very well, it is actually nontrivial to figure out what the current color is. And there are much more advanced discussions IMHO such as this one and the links there...
              – marmot
              18 hours ago










            • @marmot I deleted my answer because it is wrong. It is not true that in a draw command the color=red is equivalent to draw=red,text=red. The proof is that if you add fill after the color=red it will not fill in the default fill color (usually black), but in red.
              – Kpym
              17 hours ago










            • @Kpym I see. (Whenever I am confused I really just look through tikzoption{color}{....} to understand what's going on. Maybe TeXnician wants to add this information to their nice answer, in which case I could remove these comments... ;-)
              – marmot
              17 hours ago












            • @marmot I've tried to extend my post. Is it better now?
              – TeXnician
              6 hours ago
















            10














            You are using the wrong key. color sets fill, draw and text. That said, it will only set the color and does not apply it/the operation.





            • draw[color=red] will draw a red frame (equals draw[draw=red])


            • draw[color=red,fill] will draw a red frame filled with red (equals draw[fill=red] or filldraw[red])


            • draw[color=red,draw=none] will draw a red fill but no frame (equals fill[red])


            • draw[color=red] node {Test}; will draw a node with red text (equals draw[text=red] node {Test};


            TLDR: Use draw to change the frame.



            documentclass{article}

            usepackage{tikz}

            begin{document}
            begin{tikzpicture}
            draw[color=red,very thick] (0,0) rectangle (1,1);
            draw[color=red,very thick,fill=blue] (2,0) rectangle (3,1);
            draw[very thick,fill=blue,draw=red] (4,0) rectangle (5,1);
            end{tikzpicture}
            end{document}





            share|improve this answer



















            • 1




              The assertion it will not add a fill color if you do not specify fill is not exact. Actually, as @AndréC says, color=red set all the three default colors for draw, fill and text. But if there is no an actual command like draw of fill you simply can't see it. For example in draw[color=red,very thick,fill] ... it will fill in red because the default fill color is set to red.
              – Kpym
              20 hours ago






            • 1




              @Kpym I am not sure I agree. (Actually I like and upvoted your answer and am wondering why you removed it.) I guess the cleanest answer may be to just copy the tikzoption{color}{....} code and discuss what it means. This also clarifies the "hierarchy" and "inheritances" between the different keys. And, as you know very well, it is actually nontrivial to figure out what the current color is. And there are much more advanced discussions IMHO such as this one and the links there...
              – marmot
              18 hours ago










            • @marmot I deleted my answer because it is wrong. It is not true that in a draw command the color=red is equivalent to draw=red,text=red. The proof is that if you add fill after the color=red it will not fill in the default fill color (usually black), but in red.
              – Kpym
              17 hours ago










            • @Kpym I see. (Whenever I am confused I really just look through tikzoption{color}{....} to understand what's going on. Maybe TeXnician wants to add this information to their nice answer, in which case I could remove these comments... ;-)
              – marmot
              17 hours ago












            • @marmot I've tried to extend my post. Is it better now?
              – TeXnician
              6 hours ago














            10












            10








            10






            You are using the wrong key. color sets fill, draw and text. That said, it will only set the color and does not apply it/the operation.





            • draw[color=red] will draw a red frame (equals draw[draw=red])


            • draw[color=red,fill] will draw a red frame filled with red (equals draw[fill=red] or filldraw[red])


            • draw[color=red,draw=none] will draw a red fill but no frame (equals fill[red])


            • draw[color=red] node {Test}; will draw a node with red text (equals draw[text=red] node {Test};


            TLDR: Use draw to change the frame.



            documentclass{article}

            usepackage{tikz}

            begin{document}
            begin{tikzpicture}
            draw[color=red,very thick] (0,0) rectangle (1,1);
            draw[color=red,very thick,fill=blue] (2,0) rectangle (3,1);
            draw[very thick,fill=blue,draw=red] (4,0) rectangle (5,1);
            end{tikzpicture}
            end{document}





            share|improve this answer














            You are using the wrong key. color sets fill, draw and text. That said, it will only set the color and does not apply it/the operation.





            • draw[color=red] will draw a red frame (equals draw[draw=red])


            • draw[color=red,fill] will draw a red frame filled with red (equals draw[fill=red] or filldraw[red])


            • draw[color=red,draw=none] will draw a red fill but no frame (equals fill[red])


            • draw[color=red] node {Test}; will draw a node with red text (equals draw[text=red] node {Test};


            TLDR: Use draw to change the frame.



            documentclass{article}

            usepackage{tikz}

            begin{document}
            begin{tikzpicture}
            draw[color=red,very thick] (0,0) rectangle (1,1);
            draw[color=red,very thick,fill=blue] (2,0) rectangle (3,1);
            draw[very thick,fill=blue,draw=red] (4,0) rectangle (5,1);
            end{tikzpicture}
            end{document}






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 6 hours ago

























            answered 21 hours ago









            TeXnician

            24.6k63087




            24.6k63087








            • 1




              The assertion it will not add a fill color if you do not specify fill is not exact. Actually, as @AndréC says, color=red set all the three default colors for draw, fill and text. But if there is no an actual command like draw of fill you simply can't see it. For example in draw[color=red,very thick,fill] ... it will fill in red because the default fill color is set to red.
              – Kpym
              20 hours ago






            • 1




              @Kpym I am not sure I agree. (Actually I like and upvoted your answer and am wondering why you removed it.) I guess the cleanest answer may be to just copy the tikzoption{color}{....} code and discuss what it means. This also clarifies the "hierarchy" and "inheritances" between the different keys. And, as you know very well, it is actually nontrivial to figure out what the current color is. And there are much more advanced discussions IMHO such as this one and the links there...
              – marmot
              18 hours ago










            • @marmot I deleted my answer because it is wrong. It is not true that in a draw command the color=red is equivalent to draw=red,text=red. The proof is that if you add fill after the color=red it will not fill in the default fill color (usually black), but in red.
              – Kpym
              17 hours ago










            • @Kpym I see. (Whenever I am confused I really just look through tikzoption{color}{....} to understand what's going on. Maybe TeXnician wants to add this information to their nice answer, in which case I could remove these comments... ;-)
              – marmot
              17 hours ago












            • @marmot I've tried to extend my post. Is it better now?
              – TeXnician
              6 hours ago














            • 1




              The assertion it will not add a fill color if you do not specify fill is not exact. Actually, as @AndréC says, color=red set all the three default colors for draw, fill and text. But if there is no an actual command like draw of fill you simply can't see it. For example in draw[color=red,very thick,fill] ... it will fill in red because the default fill color is set to red.
              – Kpym
              20 hours ago






            • 1




              @Kpym I am not sure I agree. (Actually I like and upvoted your answer and am wondering why you removed it.) I guess the cleanest answer may be to just copy the tikzoption{color}{....} code and discuss what it means. This also clarifies the "hierarchy" and "inheritances" between the different keys. And, as you know very well, it is actually nontrivial to figure out what the current color is. And there are much more advanced discussions IMHO such as this one and the links there...
              – marmot
              18 hours ago










            • @marmot I deleted my answer because it is wrong. It is not true that in a draw command the color=red is equivalent to draw=red,text=red. The proof is that if you add fill after the color=red it will not fill in the default fill color (usually black), but in red.
              – Kpym
              17 hours ago










            • @Kpym I see. (Whenever I am confused I really just look through tikzoption{color}{....} to understand what's going on. Maybe TeXnician wants to add this information to their nice answer, in which case I could remove these comments... ;-)
              – marmot
              17 hours ago












            • @marmot I've tried to extend my post. Is it better now?
              – TeXnician
              6 hours ago








            1




            1




            The assertion it will not add a fill color if you do not specify fill is not exact. Actually, as @AndréC says, color=red set all the three default colors for draw, fill and text. But if there is no an actual command like draw of fill you simply can't see it. For example in draw[color=red,very thick,fill] ... it will fill in red because the default fill color is set to red.
            – Kpym
            20 hours ago




            The assertion it will not add a fill color if you do not specify fill is not exact. Actually, as @AndréC says, color=red set all the three default colors for draw, fill and text. But if there is no an actual command like draw of fill you simply can't see it. For example in draw[color=red,very thick,fill] ... it will fill in red because the default fill color is set to red.
            – Kpym
            20 hours ago




            1




            1




            @Kpym I am not sure I agree. (Actually I like and upvoted your answer and am wondering why you removed it.) I guess the cleanest answer may be to just copy the tikzoption{color}{....} code and discuss what it means. This also clarifies the "hierarchy" and "inheritances" between the different keys. And, as you know very well, it is actually nontrivial to figure out what the current color is. And there are much more advanced discussions IMHO such as this one and the links there...
            – marmot
            18 hours ago




            @Kpym I am not sure I agree. (Actually I like and upvoted your answer and am wondering why you removed it.) I guess the cleanest answer may be to just copy the tikzoption{color}{....} code and discuss what it means. This also clarifies the "hierarchy" and "inheritances" between the different keys. And, as you know very well, it is actually nontrivial to figure out what the current color is. And there are much more advanced discussions IMHO such as this one and the links there...
            – marmot
            18 hours ago












            @marmot I deleted my answer because it is wrong. It is not true that in a draw command the color=red is equivalent to draw=red,text=red. The proof is that if you add fill after the color=red it will not fill in the default fill color (usually black), but in red.
            – Kpym
            17 hours ago




            @marmot I deleted my answer because it is wrong. It is not true that in a draw command the color=red is equivalent to draw=red,text=red. The proof is that if you add fill after the color=red it will not fill in the default fill color (usually black), but in red.
            – Kpym
            17 hours ago












            @Kpym I see. (Whenever I am confused I really just look through tikzoption{color}{....} to understand what's going on. Maybe TeXnician wants to add this information to their nice answer, in which case I could remove these comments... ;-)
            – marmot
            17 hours ago






            @Kpym I see. (Whenever I am confused I really just look through tikzoption{color}{....} to understand what's going on. Maybe TeXnician wants to add this information to their nice answer, in which case I could remove these comments... ;-)
            – marmot
            17 hours ago














            @marmot I've tried to extend my post. Is it better now?
            – TeXnician
            6 hours ago




            @marmot I've tried to extend my post. Is it better now?
            – TeXnician
            6 hours ago











            6














            Yes because this option rewrites the colors on the draw, fill operations, i quote the 3.0.1a manual on page 165:




            /tikz/color=<color name> (no default) This option sets the color that
            is used for fill, drawing, and text inside the current scope.







            share|improve this answer


























              6














              Yes because this option rewrites the colors on the draw, fill operations, i quote the 3.0.1a manual on page 165:




              /tikz/color=<color name> (no default) This option sets the color that
              is used for fill, drawing, and text inside the current scope.







              share|improve this answer
























                6












                6








                6






                Yes because this option rewrites the colors on the draw, fill operations, i quote the 3.0.1a manual on page 165:




                /tikz/color=<color name> (no default) This option sets the color that
                is used for fill, drawing, and text inside the current scope.







                share|improve this answer












                Yes because this option rewrites the colors on the draw, fill operations, i quote the 3.0.1a manual on page 165:




                /tikz/color=<color name> (no default) This option sets the color that
                is used for fill, drawing, and text inside the current scope.








                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 21 hours ago









                AndréC

                7,98511443




                7,98511443






























                    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.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • 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%2f468439%2fbug-or-feature-tikz-interprets-color-specification-differently-for-rectangles%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

                    Mario Kart Wii

                    What does “Dominus providebit” mean?

                    Antonio Litta Visconti Arese