Customize circled numbers












4















Below is one solution (by @Stefan) for circled numbers with the help of tikz. What can I do to make it such that I can in-place customize its draw color, fill color, text color, etc.?



documentclass[tikz,border=7pt]{standalone}
newcommand*circled[1]{tikz[baseline=(char.base)]{
node[shape=circle,draw,inner sep=2pt] (char) {#1};}}

begin{document}
circled{1}
end{document}


enter image description here










share|improve this question























  • Not tikz, but here's an answer using the picture environment for the same question: tex.stackexchange.com/a/460946/87678

    – David Purton
    yesterday
















4















Below is one solution (by @Stefan) for circled numbers with the help of tikz. What can I do to make it such that I can in-place customize its draw color, fill color, text color, etc.?



documentclass[tikz,border=7pt]{standalone}
newcommand*circled[1]{tikz[baseline=(char.base)]{
node[shape=circle,draw,inner sep=2pt] (char) {#1};}}

begin{document}
circled{1}
end{document}


enter image description here










share|improve this question























  • Not tikz, but here's an answer using the picture environment for the same question: tex.stackexchange.com/a/460946/87678

    – David Purton
    yesterday














4












4








4








Below is one solution (by @Stefan) for circled numbers with the help of tikz. What can I do to make it such that I can in-place customize its draw color, fill color, text color, etc.?



documentclass[tikz,border=7pt]{standalone}
newcommand*circled[1]{tikz[baseline=(char.base)]{
node[shape=circle,draw,inner sep=2pt] (char) {#1};}}

begin{document}
circled{1}
end{document}


enter image description here










share|improve this question














Below is one solution (by @Stefan) for circled numbers with the help of tikz. What can I do to make it such that I can in-place customize its draw color, fill color, text color, etc.?



documentclass[tikz,border=7pt]{standalone}
newcommand*circled[1]{tikz[baseline=(char.base)]{
node[shape=circle,draw,inner sep=2pt] (char) {#1};}}

begin{document}
circled{1}
end{document}


enter image description here







tikz-pgf






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked yesterday









blackenedblackened

1,670714




1,670714













  • Not tikz, but here's an answer using the picture environment for the same question: tex.stackexchange.com/a/460946/87678

    – David Purton
    yesterday



















  • Not tikz, but here's an answer using the picture environment for the same question: tex.stackexchange.com/a/460946/87678

    – David Purton
    yesterday

















Not tikz, but here's an answer using the picture environment for the same question: tex.stackexchange.com/a/460946/87678

– David Purton
yesterday





Not tikz, but here's an answer using the picture environment for the same question: tex.stackexchange.com/a/460946/87678

– David Purton
yesterday










5 Answers
5






active

oldest

votes


















7














Edit after @marmot's (kind :P) comment (thanks):



This answer REALLY takes some care about a somehow constant size for all letters but not when line width is increased/decreased, because I had to set this parameter as extra or make some hacks in the way that it will be provided to my macro and I am not really sure if the OP need to change the line width (I just gave it initally as an idea about improving the appearance.)



documentclass{article}
usepackage{tikz}
usetikzlibrary{calc}
makeatletter
newlength{mylength}
xdefCircleFactor{1.1}
setlengthmylength{dimexprf@size pt}
newsavebox{mybox}

newcommand*circled[2][draw=blue]{saveboxmybox{vbox{vphantom{WL1/}#1}}setlengthmylength{dimexprCircleFactordimexprhtmybox+dpmyboxrelaxrelax}tikzset{mystyle/.style={circle,#1,minimum height={mylength}}}
tikz[baseline=(char.base)]
node[mystyle] (char) {#2};}
makeatother
begin{document}
This answer takes care of the current font size in a way that circled{i} and circled{W} will appear the same size here and in the next paragpaph with a verb|tiny| (or whatever font).

noindent Demonstration:\
circled{i}circled{i}circled{W}circled{W}\
circled{W}circled{W}circled{i}circled{i}

tiny This answer takes care of the current font size in a way that circled{i} and circled{W} will appear the same size here and in the this with a verb|tiny| (or whatever font).

noindent Demonstration:\
noindentcircled{i}circled{i}circled{W}circled{W}\
circled{W}circled{W}circled{i}circled{i}

normalsize Also you can give a parameter inside an optional argument of the command and have different appearance:

circled[text=blue,fill=red,draw=black]{W}circled[fill=yellow,draw=red,text=blue]{W}

end{document}


enter image description here



This is the old answer that DOESN'T REALY take care for the size according to my answer here.



You will select the style and could add your preferred style inside the optional argument of the definition of the command (I just placed the draw=blue option)



documentclass{article}
usepackage{tikz}
usetikzlibrary{calc}
makeatletter
defmfontsize{f@size}
newcommand*circled[2][draw=blue]{tikzset{mystyle/.style={circle,#1,minimum height={mfontsize*1.4}}}tikz[baseline=(char.base)]
{
node[mystyle] (char) {vphantom{WAH1g}#2};}}
makeatother

begin{document}
This is circled{a} circled[text=blue,fill=orange,draw=red, line width=0.3mm]{1} balloon.

end{document}


enter image description here






share|improve this answer


























  • Takes care of the size. Really? Try begin{document} noindentcircled{i} noindentcircled{w} end{document}

    – marmot
    yesterday











  • @marmot: Possibly it was a lie... :P. If it was for "real" your example would not fail. (Thanks... kidding because this "Really?" heard funny to me. Edited).

    – koleygr
    yesterday





















6














You can add more parameters to the command.



MWE:



documentclass[tikz,border=7pt]{standalone}
newcommand*circled[4]{tikz[baseline=(char.base)]{
node[shape=circle, fill=#2, draw=#3, text=#4, inner sep=2pt] (char) {#1};}}

begin{document}
circled{1}{red}{green}{blue}
end{document}


Result:



enter image description here



You can also specify default values for the colors using NewDocumentCommand from the xparse package:



documentclass[tikz,border=7pt]{standalone}
usepackage{xparse}
NewDocumentCommand{circleddefaults}{
O{black}
O{yellow}
O{orange}
m
}{
tikz[baseline=(char.base)]{
node[shape=circle, fill=#1, draw=#2, text=#3, inner sep=2pt] (char) {#4};}}

newcommand*circled[4]{tikz[baseline=(char.base)]{
node[shape=circle, fill=#2, draw=#3, text=#4, inner sep=2pt] (char) {#1};}}

begin{document}
circled{1}{red}{green}{blue}

circleddefaults[blue,brown]{2} % two colors specified, third default

circleddefaults{3} % all defaults
end{document}


enter image description here






share|improve this answer

































    6














    Here is a "double" customization that defines :




    • an optional parameter of circled that can be any style applied to the node,

    • an optional every number style that, if defined, is applied to all circled numbers.


    documentclass[border=7pt]{standalone}
    usepackage{tikz}
    newcommand*circled[2]{tikz[baseline=(char.base)]{
    node[shape=circle,draw,inner sep=2pt,#1,every number/.try] (char) {#2};}}
    tikzstyle{every number}=[draw=red] % I like to use tikzstyle ;)
    begin{document}
    circled{1}circled[fill=yellow]{2}
    end{document}


    enter image description here






    share|improve this answer































      4














      I would recommend using tikzmark here because this amazing library detects which mode (text vs. math mode, if math mode, which) you are in, so you won't have to care about this. And I would like to argue that one should specify the line width in relative units such that it scales with the font size. Of course, you have all the possibilities to color stuff and so on. (The best part is that you can connect the nodes in paths and so on.)



      documentclass{article}
      usepackage{tikz}
      usetikzlibrary{tikzmark}
      tikzset{mycircled/.style={circle,draw,inner sep=0.1em,line width=0.04em}}
      begin{document}
      abc tikzmarknode[mycircled,draw=red]{t1}{d}
      {Huge tikzmarknode[mycircled,draw=blue,text=purple]{t1}{D}}
      [
      intlimits_{tikzmarknode[mycircled,red]{a1}{a}}^{tikzmarknode[mycircled,blue]{b1}{b}}
      f(x),mathrm{d}x=F(tikzmarknode[mycircled,red]{a2}{a})-
      F(tikzmarknode[mycircled,blue]{b2}{b})
      ]
      begin{tikzpicture}[overlay,remember picture]
      draw[latex-latex,red] (a1) to[bend right] (a2);
      draw[latex-latex,blue] (b1) to[bend left] (b2);
      end{tikzpicture}
      end{document}


      enter image description here






      share|improve this answer


























      • The TikZ Wizard at work!

        – samcarter
        yesterday











      • @marmot Why can't I compile your code?

        – blackened
        yesterday






      • 2





        @blackened Probably because you have not the most recent version of tikzmark. tikzmarknode was added last June or so. You may have to update your TeX installation.

        – marmot
        yesterday



















      3














      Here there is a minimal proposal hoping to have understood your request.



      enter image description here



      documentclass[tikz,border=7pt]{standalone}
      newcommand*circled[1]{tikz[baseline=(char.base)]{
      node[shape=circle, fill= red, draw=yellow, inner sep=2pt] (char) {#1};}}

      begin{document}
      circled{1}
      end{document}





      share|improve this answer





















      • 1





        I need to be able to change the style when I use it.

        – blackened
        yesterday











      • In my humble opinion, it is necessary to change the excellent macro according to your needs with a new command. It depends on what you need. Have you looked at TikZ's manual?

        – Sebastiano
        yesterday











      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%2f481168%2fcustomize-circled-numbers%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









      7














      Edit after @marmot's (kind :P) comment (thanks):



      This answer REALLY takes some care about a somehow constant size for all letters but not when line width is increased/decreased, because I had to set this parameter as extra or make some hacks in the way that it will be provided to my macro and I am not really sure if the OP need to change the line width (I just gave it initally as an idea about improving the appearance.)



      documentclass{article}
      usepackage{tikz}
      usetikzlibrary{calc}
      makeatletter
      newlength{mylength}
      xdefCircleFactor{1.1}
      setlengthmylength{dimexprf@size pt}
      newsavebox{mybox}

      newcommand*circled[2][draw=blue]{saveboxmybox{vbox{vphantom{WL1/}#1}}setlengthmylength{dimexprCircleFactordimexprhtmybox+dpmyboxrelaxrelax}tikzset{mystyle/.style={circle,#1,minimum height={mylength}}}
      tikz[baseline=(char.base)]
      node[mystyle] (char) {#2};}
      makeatother
      begin{document}
      This answer takes care of the current font size in a way that circled{i} and circled{W} will appear the same size here and in the next paragpaph with a verb|tiny| (or whatever font).

      noindent Demonstration:\
      circled{i}circled{i}circled{W}circled{W}\
      circled{W}circled{W}circled{i}circled{i}

      tiny This answer takes care of the current font size in a way that circled{i} and circled{W} will appear the same size here and in the this with a verb|tiny| (or whatever font).

      noindent Demonstration:\
      noindentcircled{i}circled{i}circled{W}circled{W}\
      circled{W}circled{W}circled{i}circled{i}

      normalsize Also you can give a parameter inside an optional argument of the command and have different appearance:

      circled[text=blue,fill=red,draw=black]{W}circled[fill=yellow,draw=red,text=blue]{W}

      end{document}


      enter image description here



      This is the old answer that DOESN'T REALY take care for the size according to my answer here.



      You will select the style and could add your preferred style inside the optional argument of the definition of the command (I just placed the draw=blue option)



      documentclass{article}
      usepackage{tikz}
      usetikzlibrary{calc}
      makeatletter
      defmfontsize{f@size}
      newcommand*circled[2][draw=blue]{tikzset{mystyle/.style={circle,#1,minimum height={mfontsize*1.4}}}tikz[baseline=(char.base)]
      {
      node[mystyle] (char) {vphantom{WAH1g}#2};}}
      makeatother

      begin{document}
      This is circled{a} circled[text=blue,fill=orange,draw=red, line width=0.3mm]{1} balloon.

      end{document}


      enter image description here






      share|improve this answer


























      • Takes care of the size. Really? Try begin{document} noindentcircled{i} noindentcircled{w} end{document}

        – marmot
        yesterday











      • @marmot: Possibly it was a lie... :P. If it was for "real" your example would not fail. (Thanks... kidding because this "Really?" heard funny to me. Edited).

        – koleygr
        yesterday


















      7














      Edit after @marmot's (kind :P) comment (thanks):



      This answer REALLY takes some care about a somehow constant size for all letters but not when line width is increased/decreased, because I had to set this parameter as extra or make some hacks in the way that it will be provided to my macro and I am not really sure if the OP need to change the line width (I just gave it initally as an idea about improving the appearance.)



      documentclass{article}
      usepackage{tikz}
      usetikzlibrary{calc}
      makeatletter
      newlength{mylength}
      xdefCircleFactor{1.1}
      setlengthmylength{dimexprf@size pt}
      newsavebox{mybox}

      newcommand*circled[2][draw=blue]{saveboxmybox{vbox{vphantom{WL1/}#1}}setlengthmylength{dimexprCircleFactordimexprhtmybox+dpmyboxrelaxrelax}tikzset{mystyle/.style={circle,#1,minimum height={mylength}}}
      tikz[baseline=(char.base)]
      node[mystyle] (char) {#2};}
      makeatother
      begin{document}
      This answer takes care of the current font size in a way that circled{i} and circled{W} will appear the same size here and in the next paragpaph with a verb|tiny| (or whatever font).

      noindent Demonstration:\
      circled{i}circled{i}circled{W}circled{W}\
      circled{W}circled{W}circled{i}circled{i}

      tiny This answer takes care of the current font size in a way that circled{i} and circled{W} will appear the same size here and in the this with a verb|tiny| (or whatever font).

      noindent Demonstration:\
      noindentcircled{i}circled{i}circled{W}circled{W}\
      circled{W}circled{W}circled{i}circled{i}

      normalsize Also you can give a parameter inside an optional argument of the command and have different appearance:

      circled[text=blue,fill=red,draw=black]{W}circled[fill=yellow,draw=red,text=blue]{W}

      end{document}


      enter image description here



      This is the old answer that DOESN'T REALY take care for the size according to my answer here.



      You will select the style and could add your preferred style inside the optional argument of the definition of the command (I just placed the draw=blue option)



      documentclass{article}
      usepackage{tikz}
      usetikzlibrary{calc}
      makeatletter
      defmfontsize{f@size}
      newcommand*circled[2][draw=blue]{tikzset{mystyle/.style={circle,#1,minimum height={mfontsize*1.4}}}tikz[baseline=(char.base)]
      {
      node[mystyle] (char) {vphantom{WAH1g}#2};}}
      makeatother

      begin{document}
      This is circled{a} circled[text=blue,fill=orange,draw=red, line width=0.3mm]{1} balloon.

      end{document}


      enter image description here






      share|improve this answer


























      • Takes care of the size. Really? Try begin{document} noindentcircled{i} noindentcircled{w} end{document}

        – marmot
        yesterday











      • @marmot: Possibly it was a lie... :P. If it was for "real" your example would not fail. (Thanks... kidding because this "Really?" heard funny to me. Edited).

        – koleygr
        yesterday
















      7












      7








      7







      Edit after @marmot's (kind :P) comment (thanks):



      This answer REALLY takes some care about a somehow constant size for all letters but not when line width is increased/decreased, because I had to set this parameter as extra or make some hacks in the way that it will be provided to my macro and I am not really sure if the OP need to change the line width (I just gave it initally as an idea about improving the appearance.)



      documentclass{article}
      usepackage{tikz}
      usetikzlibrary{calc}
      makeatletter
      newlength{mylength}
      xdefCircleFactor{1.1}
      setlengthmylength{dimexprf@size pt}
      newsavebox{mybox}

      newcommand*circled[2][draw=blue]{saveboxmybox{vbox{vphantom{WL1/}#1}}setlengthmylength{dimexprCircleFactordimexprhtmybox+dpmyboxrelaxrelax}tikzset{mystyle/.style={circle,#1,minimum height={mylength}}}
      tikz[baseline=(char.base)]
      node[mystyle] (char) {#2};}
      makeatother
      begin{document}
      This answer takes care of the current font size in a way that circled{i} and circled{W} will appear the same size here and in the next paragpaph with a verb|tiny| (or whatever font).

      noindent Demonstration:\
      circled{i}circled{i}circled{W}circled{W}\
      circled{W}circled{W}circled{i}circled{i}

      tiny This answer takes care of the current font size in a way that circled{i} and circled{W} will appear the same size here and in the this with a verb|tiny| (or whatever font).

      noindent Demonstration:\
      noindentcircled{i}circled{i}circled{W}circled{W}\
      circled{W}circled{W}circled{i}circled{i}

      normalsize Also you can give a parameter inside an optional argument of the command and have different appearance:

      circled[text=blue,fill=red,draw=black]{W}circled[fill=yellow,draw=red,text=blue]{W}

      end{document}


      enter image description here



      This is the old answer that DOESN'T REALY take care for the size according to my answer here.



      You will select the style and could add your preferred style inside the optional argument of the definition of the command (I just placed the draw=blue option)



      documentclass{article}
      usepackage{tikz}
      usetikzlibrary{calc}
      makeatletter
      defmfontsize{f@size}
      newcommand*circled[2][draw=blue]{tikzset{mystyle/.style={circle,#1,minimum height={mfontsize*1.4}}}tikz[baseline=(char.base)]
      {
      node[mystyle] (char) {vphantom{WAH1g}#2};}}
      makeatother

      begin{document}
      This is circled{a} circled[text=blue,fill=orange,draw=red, line width=0.3mm]{1} balloon.

      end{document}


      enter image description here






      share|improve this answer















      Edit after @marmot's (kind :P) comment (thanks):



      This answer REALLY takes some care about a somehow constant size for all letters but not when line width is increased/decreased, because I had to set this parameter as extra or make some hacks in the way that it will be provided to my macro and I am not really sure if the OP need to change the line width (I just gave it initally as an idea about improving the appearance.)



      documentclass{article}
      usepackage{tikz}
      usetikzlibrary{calc}
      makeatletter
      newlength{mylength}
      xdefCircleFactor{1.1}
      setlengthmylength{dimexprf@size pt}
      newsavebox{mybox}

      newcommand*circled[2][draw=blue]{saveboxmybox{vbox{vphantom{WL1/}#1}}setlengthmylength{dimexprCircleFactordimexprhtmybox+dpmyboxrelaxrelax}tikzset{mystyle/.style={circle,#1,minimum height={mylength}}}
      tikz[baseline=(char.base)]
      node[mystyle] (char) {#2};}
      makeatother
      begin{document}
      This answer takes care of the current font size in a way that circled{i} and circled{W} will appear the same size here and in the next paragpaph with a verb|tiny| (or whatever font).

      noindent Demonstration:\
      circled{i}circled{i}circled{W}circled{W}\
      circled{W}circled{W}circled{i}circled{i}

      tiny This answer takes care of the current font size in a way that circled{i} and circled{W} will appear the same size here and in the this with a verb|tiny| (or whatever font).

      noindent Demonstration:\
      noindentcircled{i}circled{i}circled{W}circled{W}\
      circled{W}circled{W}circled{i}circled{i}

      normalsize Also you can give a parameter inside an optional argument of the command and have different appearance:

      circled[text=blue,fill=red,draw=black]{W}circled[fill=yellow,draw=red,text=blue]{W}

      end{document}


      enter image description here



      This is the old answer that DOESN'T REALY take care for the size according to my answer here.



      You will select the style and could add your preferred style inside the optional argument of the definition of the command (I just placed the draw=blue option)



      documentclass{article}
      usepackage{tikz}
      usetikzlibrary{calc}
      makeatletter
      defmfontsize{f@size}
      newcommand*circled[2][draw=blue]{tikzset{mystyle/.style={circle,#1,minimum height={mfontsize*1.4}}}tikz[baseline=(char.base)]
      {
      node[mystyle] (char) {vphantom{WAH1g}#2};}}
      makeatother

      begin{document}
      This is circled{a} circled[text=blue,fill=orange,draw=red, line width=0.3mm]{1} balloon.

      end{document}


      enter image description here







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited yesterday

























      answered yesterday









      koleygrkoleygr

      13.2k11038




      13.2k11038













      • Takes care of the size. Really? Try begin{document} noindentcircled{i} noindentcircled{w} end{document}

        – marmot
        yesterday











      • @marmot: Possibly it was a lie... :P. If it was for "real" your example would not fail. (Thanks... kidding because this "Really?" heard funny to me. Edited).

        – koleygr
        yesterday





















      • Takes care of the size. Really? Try begin{document} noindentcircled{i} noindentcircled{w} end{document}

        – marmot
        yesterday











      • @marmot: Possibly it was a lie... :P. If it was for "real" your example would not fail. (Thanks... kidding because this "Really?" heard funny to me. Edited).

        – koleygr
        yesterday



















      Takes care of the size. Really? Try begin{document} noindentcircled{i} noindentcircled{w} end{document}

      – marmot
      yesterday





      Takes care of the size. Really? Try begin{document} noindentcircled{i} noindentcircled{w} end{document}

      – marmot
      yesterday













      @marmot: Possibly it was a lie... :P. If it was for "real" your example would not fail. (Thanks... kidding because this "Really?" heard funny to me. Edited).

      – koleygr
      yesterday







      @marmot: Possibly it was a lie... :P. If it was for "real" your example would not fail. (Thanks... kidding because this "Really?" heard funny to me. Edited).

      – koleygr
      yesterday













      6














      You can add more parameters to the command.



      MWE:



      documentclass[tikz,border=7pt]{standalone}
      newcommand*circled[4]{tikz[baseline=(char.base)]{
      node[shape=circle, fill=#2, draw=#3, text=#4, inner sep=2pt] (char) {#1};}}

      begin{document}
      circled{1}{red}{green}{blue}
      end{document}


      Result:



      enter image description here



      You can also specify default values for the colors using NewDocumentCommand from the xparse package:



      documentclass[tikz,border=7pt]{standalone}
      usepackage{xparse}
      NewDocumentCommand{circleddefaults}{
      O{black}
      O{yellow}
      O{orange}
      m
      }{
      tikz[baseline=(char.base)]{
      node[shape=circle, fill=#1, draw=#2, text=#3, inner sep=2pt] (char) {#4};}}

      newcommand*circled[4]{tikz[baseline=(char.base)]{
      node[shape=circle, fill=#2, draw=#3, text=#4, inner sep=2pt] (char) {#1};}}

      begin{document}
      circled{1}{red}{green}{blue}

      circleddefaults[blue,brown]{2} % two colors specified, third default

      circleddefaults{3} % all defaults
      end{document}


      enter image description here






      share|improve this answer






























        6














        You can add more parameters to the command.



        MWE:



        documentclass[tikz,border=7pt]{standalone}
        newcommand*circled[4]{tikz[baseline=(char.base)]{
        node[shape=circle, fill=#2, draw=#3, text=#4, inner sep=2pt] (char) {#1};}}

        begin{document}
        circled{1}{red}{green}{blue}
        end{document}


        Result:



        enter image description here



        You can also specify default values for the colors using NewDocumentCommand from the xparse package:



        documentclass[tikz,border=7pt]{standalone}
        usepackage{xparse}
        NewDocumentCommand{circleddefaults}{
        O{black}
        O{yellow}
        O{orange}
        m
        }{
        tikz[baseline=(char.base)]{
        node[shape=circle, fill=#1, draw=#2, text=#3, inner sep=2pt] (char) {#4};}}

        newcommand*circled[4]{tikz[baseline=(char.base)]{
        node[shape=circle, fill=#2, draw=#3, text=#4, inner sep=2pt] (char) {#1};}}

        begin{document}
        circled{1}{red}{green}{blue}

        circleddefaults[blue,brown]{2} % two colors specified, third default

        circleddefaults{3} % all defaults
        end{document}


        enter image description here






        share|improve this answer




























          6












          6








          6







          You can add more parameters to the command.



          MWE:



          documentclass[tikz,border=7pt]{standalone}
          newcommand*circled[4]{tikz[baseline=(char.base)]{
          node[shape=circle, fill=#2, draw=#3, text=#4, inner sep=2pt] (char) {#1};}}

          begin{document}
          circled{1}{red}{green}{blue}
          end{document}


          Result:



          enter image description here



          You can also specify default values for the colors using NewDocumentCommand from the xparse package:



          documentclass[tikz,border=7pt]{standalone}
          usepackage{xparse}
          NewDocumentCommand{circleddefaults}{
          O{black}
          O{yellow}
          O{orange}
          m
          }{
          tikz[baseline=(char.base)]{
          node[shape=circle, fill=#1, draw=#2, text=#3, inner sep=2pt] (char) {#4};}}

          newcommand*circled[4]{tikz[baseline=(char.base)]{
          node[shape=circle, fill=#2, draw=#3, text=#4, inner sep=2pt] (char) {#1};}}

          begin{document}
          circled{1}{red}{green}{blue}

          circleddefaults[blue,brown]{2} % two colors specified, third default

          circleddefaults{3} % all defaults
          end{document}


          enter image description here






          share|improve this answer















          You can add more parameters to the command.



          MWE:



          documentclass[tikz,border=7pt]{standalone}
          newcommand*circled[4]{tikz[baseline=(char.base)]{
          node[shape=circle, fill=#2, draw=#3, text=#4, inner sep=2pt] (char) {#1};}}

          begin{document}
          circled{1}{red}{green}{blue}
          end{document}


          Result:



          enter image description here



          You can also specify default values for the colors using NewDocumentCommand from the xparse package:



          documentclass[tikz,border=7pt]{standalone}
          usepackage{xparse}
          NewDocumentCommand{circleddefaults}{
          O{black}
          O{yellow}
          O{orange}
          m
          }{
          tikz[baseline=(char.base)]{
          node[shape=circle, fill=#1, draw=#2, text=#3, inner sep=2pt] (char) {#4};}}

          newcommand*circled[4]{tikz[baseline=(char.base)]{
          node[shape=circle, fill=#2, draw=#3, text=#4, inner sep=2pt] (char) {#1};}}

          begin{document}
          circled{1}{red}{green}{blue}

          circleddefaults[blue,brown]{2} % two colors specified, third default

          circleddefaults{3} % all defaults
          end{document}


          enter image description here







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited yesterday

























          answered yesterday









          MarijnMarijn

          8,219636




          8,219636























              6














              Here is a "double" customization that defines :




              • an optional parameter of circled that can be any style applied to the node,

              • an optional every number style that, if defined, is applied to all circled numbers.


              documentclass[border=7pt]{standalone}
              usepackage{tikz}
              newcommand*circled[2]{tikz[baseline=(char.base)]{
              node[shape=circle,draw,inner sep=2pt,#1,every number/.try] (char) {#2};}}
              tikzstyle{every number}=[draw=red] % I like to use tikzstyle ;)
              begin{document}
              circled{1}circled[fill=yellow]{2}
              end{document}


              enter image description here






              share|improve this answer




























                6














                Here is a "double" customization that defines :




                • an optional parameter of circled that can be any style applied to the node,

                • an optional every number style that, if defined, is applied to all circled numbers.


                documentclass[border=7pt]{standalone}
                usepackage{tikz}
                newcommand*circled[2]{tikz[baseline=(char.base)]{
                node[shape=circle,draw,inner sep=2pt,#1,every number/.try] (char) {#2};}}
                tikzstyle{every number}=[draw=red] % I like to use tikzstyle ;)
                begin{document}
                circled{1}circled[fill=yellow]{2}
                end{document}


                enter image description here






                share|improve this answer


























                  6












                  6








                  6







                  Here is a "double" customization that defines :




                  • an optional parameter of circled that can be any style applied to the node,

                  • an optional every number style that, if defined, is applied to all circled numbers.


                  documentclass[border=7pt]{standalone}
                  usepackage{tikz}
                  newcommand*circled[2]{tikz[baseline=(char.base)]{
                  node[shape=circle,draw,inner sep=2pt,#1,every number/.try] (char) {#2};}}
                  tikzstyle{every number}=[draw=red] % I like to use tikzstyle ;)
                  begin{document}
                  circled{1}circled[fill=yellow]{2}
                  end{document}


                  enter image description here






                  share|improve this answer













                  Here is a "double" customization that defines :




                  • an optional parameter of circled that can be any style applied to the node,

                  • an optional every number style that, if defined, is applied to all circled numbers.


                  documentclass[border=7pt]{standalone}
                  usepackage{tikz}
                  newcommand*circled[2]{tikz[baseline=(char.base)]{
                  node[shape=circle,draw,inner sep=2pt,#1,every number/.try] (char) {#2};}}
                  tikzstyle{every number}=[draw=red] % I like to use tikzstyle ;)
                  begin{document}
                  circled{1}circled[fill=yellow]{2}
                  end{document}


                  enter image description here







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered yesterday









                  KpymKpym

                  17k24090




                  17k24090























                      4














                      I would recommend using tikzmark here because this amazing library detects which mode (text vs. math mode, if math mode, which) you are in, so you won't have to care about this. And I would like to argue that one should specify the line width in relative units such that it scales with the font size. Of course, you have all the possibilities to color stuff and so on. (The best part is that you can connect the nodes in paths and so on.)



                      documentclass{article}
                      usepackage{tikz}
                      usetikzlibrary{tikzmark}
                      tikzset{mycircled/.style={circle,draw,inner sep=0.1em,line width=0.04em}}
                      begin{document}
                      abc tikzmarknode[mycircled,draw=red]{t1}{d}
                      {Huge tikzmarknode[mycircled,draw=blue,text=purple]{t1}{D}}
                      [
                      intlimits_{tikzmarknode[mycircled,red]{a1}{a}}^{tikzmarknode[mycircled,blue]{b1}{b}}
                      f(x),mathrm{d}x=F(tikzmarknode[mycircled,red]{a2}{a})-
                      F(tikzmarknode[mycircled,blue]{b2}{b})
                      ]
                      begin{tikzpicture}[overlay,remember picture]
                      draw[latex-latex,red] (a1) to[bend right] (a2);
                      draw[latex-latex,blue] (b1) to[bend left] (b2);
                      end{tikzpicture}
                      end{document}


                      enter image description here






                      share|improve this answer


























                      • The TikZ Wizard at work!

                        – samcarter
                        yesterday











                      • @marmot Why can't I compile your code?

                        – blackened
                        yesterday






                      • 2





                        @blackened Probably because you have not the most recent version of tikzmark. tikzmarknode was added last June or so. You may have to update your TeX installation.

                        – marmot
                        yesterday
















                      4














                      I would recommend using tikzmark here because this amazing library detects which mode (text vs. math mode, if math mode, which) you are in, so you won't have to care about this. And I would like to argue that one should specify the line width in relative units such that it scales with the font size. Of course, you have all the possibilities to color stuff and so on. (The best part is that you can connect the nodes in paths and so on.)



                      documentclass{article}
                      usepackage{tikz}
                      usetikzlibrary{tikzmark}
                      tikzset{mycircled/.style={circle,draw,inner sep=0.1em,line width=0.04em}}
                      begin{document}
                      abc tikzmarknode[mycircled,draw=red]{t1}{d}
                      {Huge tikzmarknode[mycircled,draw=blue,text=purple]{t1}{D}}
                      [
                      intlimits_{tikzmarknode[mycircled,red]{a1}{a}}^{tikzmarknode[mycircled,blue]{b1}{b}}
                      f(x),mathrm{d}x=F(tikzmarknode[mycircled,red]{a2}{a})-
                      F(tikzmarknode[mycircled,blue]{b2}{b})
                      ]
                      begin{tikzpicture}[overlay,remember picture]
                      draw[latex-latex,red] (a1) to[bend right] (a2);
                      draw[latex-latex,blue] (b1) to[bend left] (b2);
                      end{tikzpicture}
                      end{document}


                      enter image description here






                      share|improve this answer


























                      • The TikZ Wizard at work!

                        – samcarter
                        yesterday











                      • @marmot Why can't I compile your code?

                        – blackened
                        yesterday






                      • 2





                        @blackened Probably because you have not the most recent version of tikzmark. tikzmarknode was added last June or so. You may have to update your TeX installation.

                        – marmot
                        yesterday














                      4












                      4








                      4







                      I would recommend using tikzmark here because this amazing library detects which mode (text vs. math mode, if math mode, which) you are in, so you won't have to care about this. And I would like to argue that one should specify the line width in relative units such that it scales with the font size. Of course, you have all the possibilities to color stuff and so on. (The best part is that you can connect the nodes in paths and so on.)



                      documentclass{article}
                      usepackage{tikz}
                      usetikzlibrary{tikzmark}
                      tikzset{mycircled/.style={circle,draw,inner sep=0.1em,line width=0.04em}}
                      begin{document}
                      abc tikzmarknode[mycircled,draw=red]{t1}{d}
                      {Huge tikzmarknode[mycircled,draw=blue,text=purple]{t1}{D}}
                      [
                      intlimits_{tikzmarknode[mycircled,red]{a1}{a}}^{tikzmarknode[mycircled,blue]{b1}{b}}
                      f(x),mathrm{d}x=F(tikzmarknode[mycircled,red]{a2}{a})-
                      F(tikzmarknode[mycircled,blue]{b2}{b})
                      ]
                      begin{tikzpicture}[overlay,remember picture]
                      draw[latex-latex,red] (a1) to[bend right] (a2);
                      draw[latex-latex,blue] (b1) to[bend left] (b2);
                      end{tikzpicture}
                      end{document}


                      enter image description here






                      share|improve this answer















                      I would recommend using tikzmark here because this amazing library detects which mode (text vs. math mode, if math mode, which) you are in, so you won't have to care about this. And I would like to argue that one should specify the line width in relative units such that it scales with the font size. Of course, you have all the possibilities to color stuff and so on. (The best part is that you can connect the nodes in paths and so on.)



                      documentclass{article}
                      usepackage{tikz}
                      usetikzlibrary{tikzmark}
                      tikzset{mycircled/.style={circle,draw,inner sep=0.1em,line width=0.04em}}
                      begin{document}
                      abc tikzmarknode[mycircled,draw=red]{t1}{d}
                      {Huge tikzmarknode[mycircled,draw=blue,text=purple]{t1}{D}}
                      [
                      intlimits_{tikzmarknode[mycircled,red]{a1}{a}}^{tikzmarknode[mycircled,blue]{b1}{b}}
                      f(x),mathrm{d}x=F(tikzmarknode[mycircled,red]{a2}{a})-
                      F(tikzmarknode[mycircled,blue]{b2}{b})
                      ]
                      begin{tikzpicture}[overlay,remember picture]
                      draw[latex-latex,red] (a1) to[bend right] (a2);
                      draw[latex-latex,blue] (b1) to[bend left] (b2);
                      end{tikzpicture}
                      end{document}


                      enter image description here







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited yesterday

























                      answered yesterday









                      marmotmarmot

                      112k5140264




                      112k5140264













                      • The TikZ Wizard at work!

                        – samcarter
                        yesterday











                      • @marmot Why can't I compile your code?

                        – blackened
                        yesterday






                      • 2





                        @blackened Probably because you have not the most recent version of tikzmark. tikzmarknode was added last June or so. You may have to update your TeX installation.

                        – marmot
                        yesterday



















                      • The TikZ Wizard at work!

                        – samcarter
                        yesterday











                      • @marmot Why can't I compile your code?

                        – blackened
                        yesterday






                      • 2





                        @blackened Probably because you have not the most recent version of tikzmark. tikzmarknode was added last June or so. You may have to update your TeX installation.

                        – marmot
                        yesterday

















                      The TikZ Wizard at work!

                      – samcarter
                      yesterday





                      The TikZ Wizard at work!

                      – samcarter
                      yesterday













                      @marmot Why can't I compile your code?

                      – blackened
                      yesterday





                      @marmot Why can't I compile your code?

                      – blackened
                      yesterday




                      2




                      2





                      @blackened Probably because you have not the most recent version of tikzmark. tikzmarknode was added last June or so. You may have to update your TeX installation.

                      – marmot
                      yesterday





                      @blackened Probably because you have not the most recent version of tikzmark. tikzmarknode was added last June or so. You may have to update your TeX installation.

                      – marmot
                      yesterday











                      3














                      Here there is a minimal proposal hoping to have understood your request.



                      enter image description here



                      documentclass[tikz,border=7pt]{standalone}
                      newcommand*circled[1]{tikz[baseline=(char.base)]{
                      node[shape=circle, fill= red, draw=yellow, inner sep=2pt] (char) {#1};}}

                      begin{document}
                      circled{1}
                      end{document}





                      share|improve this answer





















                      • 1





                        I need to be able to change the style when I use it.

                        – blackened
                        yesterday











                      • In my humble opinion, it is necessary to change the excellent macro according to your needs with a new command. It depends on what you need. Have you looked at TikZ's manual?

                        – Sebastiano
                        yesterday
















                      3














                      Here there is a minimal proposal hoping to have understood your request.



                      enter image description here



                      documentclass[tikz,border=7pt]{standalone}
                      newcommand*circled[1]{tikz[baseline=(char.base)]{
                      node[shape=circle, fill= red, draw=yellow, inner sep=2pt] (char) {#1};}}

                      begin{document}
                      circled{1}
                      end{document}





                      share|improve this answer





















                      • 1





                        I need to be able to change the style when I use it.

                        – blackened
                        yesterday











                      • In my humble opinion, it is necessary to change the excellent macro according to your needs with a new command. It depends on what you need. Have you looked at TikZ's manual?

                        – Sebastiano
                        yesterday














                      3












                      3








                      3







                      Here there is a minimal proposal hoping to have understood your request.



                      enter image description here



                      documentclass[tikz,border=7pt]{standalone}
                      newcommand*circled[1]{tikz[baseline=(char.base)]{
                      node[shape=circle, fill= red, draw=yellow, inner sep=2pt] (char) {#1};}}

                      begin{document}
                      circled{1}
                      end{document}





                      share|improve this answer















                      Here there is a minimal proposal hoping to have understood your request.



                      enter image description here



                      documentclass[tikz,border=7pt]{standalone}
                      newcommand*circled[1]{tikz[baseline=(char.base)]{
                      node[shape=circle, fill= red, draw=yellow, inner sep=2pt] (char) {#1};}}

                      begin{document}
                      circled{1}
                      end{document}






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited yesterday

























                      answered yesterday









                      SebastianoSebastiano

                      11.1k42164




                      11.1k42164








                      • 1





                        I need to be able to change the style when I use it.

                        – blackened
                        yesterday











                      • In my humble opinion, it is necessary to change the excellent macro according to your needs with a new command. It depends on what you need. Have you looked at TikZ's manual?

                        – Sebastiano
                        yesterday














                      • 1





                        I need to be able to change the style when I use it.

                        – blackened
                        yesterday











                      • In my humble opinion, it is necessary to change the excellent macro according to your needs with a new command. It depends on what you need. Have you looked at TikZ's manual?

                        – Sebastiano
                        yesterday








                      1




                      1





                      I need to be able to change the style when I use it.

                      – blackened
                      yesterday





                      I need to be able to change the style when I use it.

                      – blackened
                      yesterday













                      In my humble opinion, it is necessary to change the excellent macro according to your needs with a new command. It depends on what you need. Have you looked at TikZ's manual?

                      – Sebastiano
                      yesterday





                      In my humble opinion, it is necessary to change the excellent macro according to your needs with a new command. It depends on what you need. Have you looked at TikZ's manual?

                      – Sebastiano
                      yesterday


















                      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%2f481168%2fcustomize-circled-numbers%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

                      數位音樂下載

                      格利澤436b

                      When can things happen in Etherscan, such as the picture below?