2

I'm using TikZ to create some circles with numbers as some sort of marker. But I want to use them as superscript.

So to generate a circle I'm using this command (suggested here: Good way to make \textcircled numbers?):

\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
            \node[shape=circle,fill=blue!20,draw,inner sep=0.5pt] (char) {#1};}}

To use it within the text (as superscript) I'm using:

text^{\circled{1}}

However I get the following error:

> Description   Resource    Path    Location    Type Missing $ inserted. ... & 24 &
> 8 & 32^{\circleds{3}} & (followed by: 0      & 24    & 8
> \\)   doc.tex /doc line 287   Texlipse Build Error

Any suggestions of why is that?

Here is an small code example.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
            \node[shape=circle,fill=blue!20,draw,inner sep=0.5pt] (char) {#1};}}

\begin{document} 
This works: \circled{3}. But this^{\circled{1}} is no good.
\end{document}
  • Welcome to TeX - LaTeX! – SAM Jun 30 '16 at 18:00
  • 3
    The superscript character ^ is a command to be used in math mode. If you provided a minimal version of the code that fails, we could answer more definitively, but text^{anything} will fail irrespective of tikz, if it is not already in math mode. Maybe try text\textsuperscript{\circled{1}} – Steven B. Segletes Jun 30 '16 at 18:01
  • ^ works only in math mode, so you may try $text^{\circled{1}}$ – SAM Jun 30 '16 at 18:02
  • Just tried. It seems to ignore the \circled{1} and just place the number 1. – rph Jun 30 '16 at 18:03
  • @SAM That would but the "text" part in math mode too, – Steven B. Segletes Jun 30 '16 at 18:03
5

As discussed in numerous comments, the underlying problem was that ^ was invoked in text, not math mode. Here are two possibilities, depending on how you want it to behave.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
            \node[shape=circle,fill=blue!20,draw,inner sep=0.5pt] (char) {#1};}}

\begin{document} 
This works: \circled{3}. But this\textsuperscript{\circled{1}} is no good.

This works: \circled{3}. But this$^{\circled{1}}$ is no good.
\end{document}

enter image description here

  • Great!! You guys are ninja!! That works. – rph Jun 30 '16 at 18:12

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.