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"?

crateane
  • 2,217
  • 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 '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} – crateane Aug 19 '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}. –  Aug 19 '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. – crateane Aug 19 '19 at 12:17
  • 2
    Take a look here too: https://tex.stackexchange.com/a/392188/120578 – koleygr Aug 19 '19 at 12:26
  • Thank you all, I didn't even notice that scriptsize does not take an argument. Now it is working perfectly. – SampleTime Aug 19 '19 at 13:07
  • @SampleTime Even if \scriptsize has no argument, it doesn't change anything because you put the 8 in a group delimited by brackets. This group allows you to circle two-digit numbers such as 18 or 20... – AndréC Aug 19 '19 at 16:06
  • @AndréC I guess you misunderstand the question. The original approach does work in a sense that the font size is changed (also inside the tikz-environment and the circle). But it is not changed back, or as the question says, it leaks. This is not really related to two-digit numbers or the circle size. – crateane Aug 19 '19 at 19:01
  • @Faekynn Yes, you're right. Once again, I did not understand well. :-( – AndréC Aug 19 '19 at 19:15

2 Answers2

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.

crateane
  • 2,217
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}
Black Mild
  • 17,569
  • 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?) – crateane Aug 20 '19 at 13:51