3

I want to use circled numbers in a figure caption. I found a nice and short implementation using tikz here. The command itself is working (after using \DeclareRobustCommand instead), and the resulting symbols are correctly displayed.

However, the spacing around them is way too large for my liking (see the example below). I checked with \fbox that the actual tikz picture does not have any surrounding whitespace, so I assume it must be a kerning or skip issue. It sometimes seemed to me like the space around the numbers was inconsistent, indicating it isn't a kern, but I'm not sure how to test that more comprehensively.

Here's a minimal example (inside a figure caption because that's the only place I need it to work):

\documentclass{article}
\usepackage{graphicx}

\usepackage{tikz}
\DeclareRobustCommand\circled[1]{
    \tikz[baseline=(char.base)]{
        \node[shape=circle,draw,inner sep=1pt] (char) {\scriptsize \textbf{#1}};
    }
}

\begin{document}
\begin{figure}[t]
    \centering
    \caption{
        This is a figure caption.
        \circled{1} I want to refer to parts of the figure using circled numbers.
        \circled{2} But the spacing around the numbers is completely off.
        \circled{3} I would've expected the numbers to behave like single letters, maybe like just writing (4) or something similar.
    }
\end{figure}
\end{document}

And this is the output: Example with excessive spacing around encircled digits

Any advice how to control this spacing (and ideally make at least the space after the number fixed and non-breaking) is greatly appreciated!

1
  • 2
    There are four "extra" spaces in your definition -- an end-of-line is treated as a space, and there are four of them in your definition. Put a % at the end of those lines (immediately after { or }), and at least that cause will be removed. Aug 18, 2023 at 19:49

2 Answers 2

3

Shameless plug:

\documentclass{article}
\usepackage{graphicx}
\usepackage{circledsteps}

\begin{document}
\begin{figure}[t]
    \centering
    \caption{
        This is a figure caption.
        \Circled{1} I want to refer to parts of the figure using circled numbers.
        \Circled{2} But the spacing around the numbers is completely off.
        \Circled{3} I would've expected the numbers to behave like single letters, maybe like just writing (4) or something similar.
    }
\end{figure}
\end{document}

enter image description here

The advantage of using the package is that

  1. the Circled command will work even inside a tikzpicture;
  2. you can easily reference the number;
  3. it behaves for numbers bigger than 10...

enter image description here

And in addition, it's picture-mode 😉

About the question, which I have not addressed (you are right!), the problem is that you have a lot of spurious spaces in your macro... try:

\DeclareRobustCommand\circled[1]{% <<< remove one space here
    \tikz[baseline=(char.base)]{% <<< this is not really needed (nor the group, really)
        \node[shape=circle,draw,inner sep=1pt] (char) {\scriptsize \textbf{#1}};% <<< remove a space here
    }% << remove another space here 
}

If you change your macro as:

\DeclareRobustCommand\circled[1]{%
    \tikz[baseline=(char.base)]
        \node[shape=circle,draw,inner sep=1pt] (char)
        {\scriptsize \textbf{#1}};%
    }%

You have

enter image description here

2
  • 1
    I appreciate the plug, and will probably just end up using this package for my problem. I'll still leave this question open though as this package does not address how to solve the problem in my setup, and I am really curious to learn how such spacing should be handled (atm it makes no sense to me why my approach doesn't work).
    – Texfy
    Aug 18, 2023 at 18:45
  • Wow, thanks, I was not aware these trailing spaces could lead to issues! Thanks for the explanation!
    – Texfy
    Aug 20, 2023 at 9:53
0

While it does not directly solve your spacing problem, you can use the pifont package to insert circled numbers in you figure caption.

You can see how to use the pifont symbols below. If you need/prefer other symbols, you can have a look at The Comprehensive LaTeX Symbol List. The circled numbers of pifont are on page 141.

Code:

\documentclass{article}

\usepackage{pifont}

\begin{document}
    \ding{172} \ding{173} \ding{174} \ding{175} \ding{176} \ding{177} \ding{178} \ding{179} \ding{180} \ding{181}
    
    Some text with circled numbers \ding{172} and nice spacing. 
\end{document}

Result: Code output

1
  • Thanks for sharing this. I was aware of this approach since it was also suggested in the original question I got the \circled code snippet from. This is a good workaround, but I'll leave the question open since I'm interested in an explanation on how to approach spacing issues like this (and why they arise in the first place).
    – Texfy
    Aug 18, 2023 at 18:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .