11

While it's easy to typeset a check-box (checked or not) in LaTeX (e.g., using wasysym), I did not find any way to typeset a radio button. I could of course use TikZ, but is there a more "lightweight" way (i.e., using some font or combining existing characters)? This is close:

\documentclass{article}

\usepackage{wasysym}

\begin{document}

\begin{itemize}
\item[$\ocircle$] foo
\item[$\odot$] bar
\item[$\ocircle$] baz
\end{itemize}
\end{document}

but the dot inside \odot might be a bit too light.

Any suggestions?

Note: I am not interested at all in PDF forms; I want a printable document with a clear indication that one element of the list is selectable (i.e., a single-choice test).

mbork
  • 13,385

3 Answers3

15

The selected and unselected radio buttons can be drawn via TikZ:

\documentclass{article}

\usepackage{tikz}

\makeatletter
\newcommand*{\radiobutton}{%
  \@ifstar{\@radiobutton0}{\@radiobutton1}%
}
\newcommand*{\@radiobutton}[1]{%
  \begin{tikzpicture}
    \pgfmathsetlengthmacro\radius{height("X")/2}
    \draw[radius=\radius] circle;
    \ifcase#1 \fill[radius=.6*\radius] circle;\fi
  \end{tikzpicture}%
}
\makeatother

\begin{document}

\begin{itemize}
\item[\radiobutton] foo
\item[\radiobutton*] bar
\item[\radiobutton] baz
\end{itemize}
\end{document}

Result

Some variation with shadow and ball:

\documentclass{article}

\usepackage{tikz}

\makeatletter
\newcommand*{\radiobutton}{%
  \@ifstar{\@radiobutton0}{\@radiobutton1}%
}
\newcommand*{\@radiobutton}[1]{%
  \begin{tikzpicture}
    \pgfmathsetlengthmacro\radius{height("X")/2}
    \draw[radius=\radius,
      preaction={
        draw=gray,
        transform canvas={
          xshift=.7\pgflinewidth,
          yshift=-.7\pgflinewidth,
        },
      },  
      preaction={fill=white},
    ] circle;
    \ifcase#1
      \fill[
        radius=.6*\radius,
        shade,
        shading=ball,
        ball color=black,
      ] circle;
    \fi
  \end{tikzpicture}%
}
\makeatother

\begin{document}

\begin{itemize}
\item[\radiobutton] foo
\item[\radiobutton*] bar
\item[\radiobutton] baz
\end{itemize}
\end{document}

Result with shadow and ball

Heiko Oberdiek
  • 271,626
10

May be this:

\documentclass{article}

\usepackage{wasysym}
\newcommand{\radio}{\ooalign{\hidewidth$\bullet$\hidewidth\cr$\ocircle$}}


\begin{document}

\begin{itemize}
\item[$\ocircle$] foo
\item[$\odot$] bar
\item[$\ocircle$] baz
\item[\radio] baz
\end{itemize}
\end{document}

You can use \scalebox and play with the size of \bullet if you want.

enter image description here

9

Here I use a \stackinset to place a \bullet inside of a scaled \circ.

\documentclass[12pt]{article}
\usepackage[usestackEOL]{stackengine}
\usepackage{graphicx}
\makeatletter
\newcommand*{\radiobutton}{\@ifstar{\radiobuttonON}{\radiobuttonOFF}}
\makeatother
\def\radiobuttonON{\raisebox{-1.5pt}{\stackinset{c}{}{c}{.35pt}{$\bullet$}{\scalebox{2}{$\circ$}}}}
\def\radiobuttonOFF{\raisebox{-1.5pt}{\scalebox{2}{$\circ$}}}
\begin{document}
\begin{itemize}
\item[\radiobutton] foo
\item[\radiobutton*] bar
\item[\radiobutton] baz
\end{itemize}
\end{document}

enter image description here