TikZ fill color: How to decrease spatial size of fill behind text?












1















Assumed we have some simple code to display a text node with a colored fill behind the text.





Minimum working example (MWE):



documentclass[tikz,border=5mm]{standalone}

begin{document}
begin{tikzpicture}
draw [fill=red] (0,0) -- (1,0) -- (1,1) -- (0,1) --cycle node [above right, xshift=0.25mm,yshift=2.5mm, fill=white] {Text};
end{tikzpicture}
end{document}




Screenshot of the result:



Screenshot of the result





Description of the issue:



As you can see, there is a lot of white fill space on each side of the text. In some situations this white space is too big in its spatial extent.



How can I decrease the extension of the white fill without loosing text alignment centered? I've tried with text width=XXXX and align=center already, but this does only change the white space on the right side while the text won't be aligned as centered anymore.



How is it possible to decrease the extent of the fill on the left and right side, and maybe even at the top and bottom side?










share|improve this question


















  • 4





    Hey! I think the white space correspond to the node inner sep! If you set it to 0pt (with the option inner sep=0pt) the node edge (here the white rectangle borders) will be touching the text (in every direction: left, right, top and bottom). By default, this value is not zero and correspond here to the extent of the fill you are talking about! So you might only need to change this value to change the gap between the white rectangle and your text! I hope this will help you! :)

    – Vinzza
    Feb 6 at 13:01


















1















Assumed we have some simple code to display a text node with a colored fill behind the text.





Minimum working example (MWE):



documentclass[tikz,border=5mm]{standalone}

begin{document}
begin{tikzpicture}
draw [fill=red] (0,0) -- (1,0) -- (1,1) -- (0,1) --cycle node [above right, xshift=0.25mm,yshift=2.5mm, fill=white] {Text};
end{tikzpicture}
end{document}




Screenshot of the result:



Screenshot of the result





Description of the issue:



As you can see, there is a lot of white fill space on each side of the text. In some situations this white space is too big in its spatial extent.



How can I decrease the extension of the white fill without loosing text alignment centered? I've tried with text width=XXXX and align=center already, but this does only change the white space on the right side while the text won't be aligned as centered anymore.



How is it possible to decrease the extent of the fill on the left and right side, and maybe even at the top and bottom side?










share|improve this question


















  • 4





    Hey! I think the white space correspond to the node inner sep! If you set it to 0pt (with the option inner sep=0pt) the node edge (here the white rectangle borders) will be touching the text (in every direction: left, right, top and bottom). By default, this value is not zero and correspond here to the extent of the fill you are talking about! So you might only need to change this value to change the gap between the white rectangle and your text! I hope this will help you! :)

    – Vinzza
    Feb 6 at 13:01
















1












1








1








Assumed we have some simple code to display a text node with a colored fill behind the text.





Minimum working example (MWE):



documentclass[tikz,border=5mm]{standalone}

begin{document}
begin{tikzpicture}
draw [fill=red] (0,0) -- (1,0) -- (1,1) -- (0,1) --cycle node [above right, xshift=0.25mm,yshift=2.5mm, fill=white] {Text};
end{tikzpicture}
end{document}




Screenshot of the result:



Screenshot of the result





Description of the issue:



As you can see, there is a lot of white fill space on each side of the text. In some situations this white space is too big in its spatial extent.



How can I decrease the extension of the white fill without loosing text alignment centered? I've tried with text width=XXXX and align=center already, but this does only change the white space on the right side while the text won't be aligned as centered anymore.



How is it possible to decrease the extent of the fill on the left and right side, and maybe even at the top and bottom side?










share|improve this question














Assumed we have some simple code to display a text node with a colored fill behind the text.





Minimum working example (MWE):



documentclass[tikz,border=5mm]{standalone}

begin{document}
begin{tikzpicture}
draw [fill=red] (0,0) -- (1,0) -- (1,1) -- (0,1) --cycle node [above right, xshift=0.25mm,yshift=2.5mm, fill=white] {Text};
end{tikzpicture}
end{document}




Screenshot of the result:



Screenshot of the result





Description of the issue:



As you can see, there is a lot of white fill space on each side of the text. In some situations this white space is too big in its spatial extent.



How can I decrease the extension of the white fill without loosing text alignment centered? I've tried with text width=XXXX and align=center already, but this does only change the white space on the right side while the text won't be aligned as centered anymore.



How is it possible to decrease the extent of the fill on the left and right side, and maybe even at the top and bottom side?







tikz-pgf nodes width text fill






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Feb 6 at 12:46









DaveDave

830617




830617








  • 4





    Hey! I think the white space correspond to the node inner sep! If you set it to 0pt (with the option inner sep=0pt) the node edge (here the white rectangle borders) will be touching the text (in every direction: left, right, top and bottom). By default, this value is not zero and correspond here to the extent of the fill you are talking about! So you might only need to change this value to change the gap between the white rectangle and your text! I hope this will help you! :)

    – Vinzza
    Feb 6 at 13:01
















  • 4





    Hey! I think the white space correspond to the node inner sep! If you set it to 0pt (with the option inner sep=0pt) the node edge (here the white rectangle borders) will be touching the text (in every direction: left, right, top and bottom). By default, this value is not zero and correspond here to the extent of the fill you are talking about! So you might only need to change this value to change the gap between the white rectangle and your text! I hope this will help you! :)

    – Vinzza
    Feb 6 at 13:01










4




4





Hey! I think the white space correspond to the node inner sep! If you set it to 0pt (with the option inner sep=0pt) the node edge (here the white rectangle borders) will be touching the text (in every direction: left, right, top and bottom). By default, this value is not zero and correspond here to the extent of the fill you are talking about! So you might only need to change this value to change the gap between the white rectangle and your text! I hope this will help you! :)

– Vinzza
Feb 6 at 13:01







Hey! I think the white space correspond to the node inner sep! If you set it to 0pt (with the option inner sep=0pt) the node edge (here the white rectangle borders) will be touching the text (in every direction: left, right, top and bottom). By default, this value is not zero and correspond here to the extent of the fill you are talking about! So you might only need to change this value to change the gap between the white rectangle and your text! I hope this will help you! :)

– Vinzza
Feb 6 at 13:01












2 Answers
2






active

oldest

votes


















2














A more easier approach:



documentclass[tikz,border=5mm]{standalone}

begin{document}
begin{tikzpicture}
node at (0,0) (a) {};
draw [fill = red] (-0.5,-0.5) rectangle (0.5,0.5);
node[draw = none,fill=white, inner sep = 0pt] at (a.center){Text};
end{tikzpicture}
end{document}


this would give you:



enter image description here



As you draw more complicated diagrams, these type of predefined nodal definitions comes handy.



PS: Thank you @Vinzza for the nice hint!



As @Vinzza already mentioned you can play with inner sep = <size> to adapt the spacing.






share|improve this answer
























  • You're welcome! :D

    – Vinzza
    Feb 6 at 15:18



















1














In case you want a filled node but with text over a white background you can use a node with a centered label instead of a filled path with an independent centered node:



documentclass[tikz,border=2mm]{standalone} 

begin{document}
begin{tikzpicture}
node[minimum size=2cm, fill=red, label={[fill=white, inner sep=0pt]center:Text}] {};
end{tikzpicture}
end{document}


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%2f473617%2ftikz-fill-color-how-to-decrease-spatial-size-of-fill-behind-text%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









    2














    A more easier approach:



    documentclass[tikz,border=5mm]{standalone}

    begin{document}
    begin{tikzpicture}
    node at (0,0) (a) {};
    draw [fill = red] (-0.5,-0.5) rectangle (0.5,0.5);
    node[draw = none,fill=white, inner sep = 0pt] at (a.center){Text};
    end{tikzpicture}
    end{document}


    this would give you:



    enter image description here



    As you draw more complicated diagrams, these type of predefined nodal definitions comes handy.



    PS: Thank you @Vinzza for the nice hint!



    As @Vinzza already mentioned you can play with inner sep = <size> to adapt the spacing.






    share|improve this answer
























    • You're welcome! :D

      – Vinzza
      Feb 6 at 15:18
















    2














    A more easier approach:



    documentclass[tikz,border=5mm]{standalone}

    begin{document}
    begin{tikzpicture}
    node at (0,0) (a) {};
    draw [fill = red] (-0.5,-0.5) rectangle (0.5,0.5);
    node[draw = none,fill=white, inner sep = 0pt] at (a.center){Text};
    end{tikzpicture}
    end{document}


    this would give you:



    enter image description here



    As you draw more complicated diagrams, these type of predefined nodal definitions comes handy.



    PS: Thank you @Vinzza for the nice hint!



    As @Vinzza already mentioned you can play with inner sep = <size> to adapt the spacing.






    share|improve this answer
























    • You're welcome! :D

      – Vinzza
      Feb 6 at 15:18














    2












    2








    2







    A more easier approach:



    documentclass[tikz,border=5mm]{standalone}

    begin{document}
    begin{tikzpicture}
    node at (0,0) (a) {};
    draw [fill = red] (-0.5,-0.5) rectangle (0.5,0.5);
    node[draw = none,fill=white, inner sep = 0pt] at (a.center){Text};
    end{tikzpicture}
    end{document}


    this would give you:



    enter image description here



    As you draw more complicated diagrams, these type of predefined nodal definitions comes handy.



    PS: Thank you @Vinzza for the nice hint!



    As @Vinzza already mentioned you can play with inner sep = <size> to adapt the spacing.






    share|improve this answer













    A more easier approach:



    documentclass[tikz,border=5mm]{standalone}

    begin{document}
    begin{tikzpicture}
    node at (0,0) (a) {};
    draw [fill = red] (-0.5,-0.5) rectangle (0.5,0.5);
    node[draw = none,fill=white, inner sep = 0pt] at (a.center){Text};
    end{tikzpicture}
    end{document}


    this would give you:



    enter image description here



    As you draw more complicated diagrams, these type of predefined nodal definitions comes handy.



    PS: Thank you @Vinzza for the nice hint!



    As @Vinzza already mentioned you can play with inner sep = <size> to adapt the spacing.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Feb 6 at 13:22









    RaajaRaaja

    3,75521037




    3,75521037













    • You're welcome! :D

      – Vinzza
      Feb 6 at 15:18



















    • You're welcome! :D

      – Vinzza
      Feb 6 at 15:18

















    You're welcome! :D

    – Vinzza
    Feb 6 at 15:18





    You're welcome! :D

    – Vinzza
    Feb 6 at 15:18











    1














    In case you want a filled node but with text over a white background you can use a node with a centered label instead of a filled path with an independent centered node:



    documentclass[tikz,border=2mm]{standalone} 

    begin{document}
    begin{tikzpicture}
    node[minimum size=2cm, fill=red, label={[fill=white, inner sep=0pt]center:Text}] {};
    end{tikzpicture}
    end{document}


    enter image description here






    share|improve this answer




























      1














      In case you want a filled node but with text over a white background you can use a node with a centered label instead of a filled path with an independent centered node:



      documentclass[tikz,border=2mm]{standalone} 

      begin{document}
      begin{tikzpicture}
      node[minimum size=2cm, fill=red, label={[fill=white, inner sep=0pt]center:Text}] {};
      end{tikzpicture}
      end{document}


      enter image description here






      share|improve this answer


























        1












        1








        1







        In case you want a filled node but with text over a white background you can use a node with a centered label instead of a filled path with an independent centered node:



        documentclass[tikz,border=2mm]{standalone} 

        begin{document}
        begin{tikzpicture}
        node[minimum size=2cm, fill=red, label={[fill=white, inner sep=0pt]center:Text}] {};
        end{tikzpicture}
        end{document}


        enter image description here






        share|improve this answer













        In case you want a filled node but with text over a white background you can use a node with a centered label instead of a filled path with an independent centered node:



        documentclass[tikz,border=2mm]{standalone} 

        begin{document}
        begin{tikzpicture}
        node[minimum size=2cm, fill=red, label={[fill=white, inner sep=0pt]center:Text}] {};
        end{tikzpicture}
        end{document}


        enter image description here







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Feb 6 at 23:04









        IgnasiIgnasi

        93.3k4167310




        93.3k4167310






























            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%2f473617%2ftikz-fill-color-how-to-decrease-spatial-size-of-fill-behind-text%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

            How to change which sound is reproduced for terminal bell?

            Can I use Tabulator js library in my java Spring + Thymeleaf project?

            Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents