1

I want to have circled numbers in my text and use the TikZ solution posted here. However, I want to make the circles and text a bit smaller so I tried this:

\documentclass{article}
\usepackage{tikz}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
            \node[shape=circle,draw,inner sep=2pt] (char) {#1};}}
\begin{document}
Numbers aligned with the text:  \scriptsize{\circled{1}} end.
\end{document}

Unfortunatly, the \scriptsize seems to "leak" because all text after this command is small (in the text the "end" is also in scriptsize) although the curly parentesis are closed correctly.

How can I make this work without having the \scriptsize command "leak"?

  • 1
    The space between the number and the circle is given by the inner sep option. Just decrease it with for example inner sep=.5pt – AndréC Aug 19 at 11:56
  • 3
    \scriptsize does not take an argument. Try to enclose the text with changed font size in braces instead: {\scriptsize some text}. In this case, I would suggest \circled{\scriptsize 1} – Faekynn Aug 19 at 11:57
  • 2
    Or allow for a parameter \newcommand*\circled[2][]{\tikz[baseline=(char.base)]{ \node[shape=circle,draw,inner sep=2pt,#1] (char) {#2};}} and then do e.g. \circled[scale=0.6]{1} or \circled[font=\scriptsize]{1}. – Schrödinger's cat Aug 19 at 12:15
  • 1
    @Schrödinger'scat that is of course better. It allows also to change other optiones (such as inner sep) if desired. – Faekynn Aug 19 at 12:17
  • 2
    Take a look here too: tex.stackexchange.com/a/392188/120578 – koleygr Aug 19 at 12:26
2

The solution is to correctly change the font size. \scriptsize does not take an argument and changes the font size for all text afterwards. If it is enclosed in braces (e.g., insinde the argument of \circled{·}), the font size change is only local.

Changed code:

\documentclass{article}
\usepackage{tikz}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
            \node[shape=circle,draw,inner sep=2pt] (char) {#1};}}
\begin{document}
Numbers aligned with the text:  \circled{\scriptsize1}  \circled{1} end.
\end{document}

And the output looks like this:

enter image description here

If you like to change the circle size, you can change value of the inner sep option as mentioned in the comment of AndréC.

2

We can insert many things (texts, formulae, tables, images, etc) of LaTeX inside TikZ's node with plenty of options. One of the best option is scale that much flexible than LaTeX ones: \tiny, \scriptsize, \footnotesize, \small, \normalsize, \large, \Large, \LARGE, \huge, \Huge(maybe Stefan Kottwitz mentioned in his answer).

In summary, let us scale of node for this situation.

enter image description here

\documentclass{article}
\usepackage{tikz}
\newcommand*\circled[2]{\tikz[baseline=(char.base)]{
\node[circle,draw,scale=#2,inner sep=2pt] (char) {#1};}}
\begin{document}
Numbers aligned with the text:  \circled{1}{1}  \circled{\color{blue} 1}{1.5} end.
\end{document}
  • I think changing the font size influences the stroke width of the text in a different way than just scaling the text with TikZ. (different sized letters are not just scaled versions of each other?) – Faekynn Aug 20 at 13:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.