13

I'm trying to define a new counter which does the following:

\documentclass[10pt]{article} 
\usepackage{amsmath} 
\usepackage{amssymb} 
\usepackage{array}
\usepackage{tikz}
\usepackage{longtable}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
        \node[shape=circle,draw,inner sep=2pt] (char) {#1};}}

\begin{document} 
\begin{longtable}{lll} 
\circled{x} \quad  $3x^4-x^4-x^3(x+2)$ & 
\circled{x} \quad  $-12a^2+3a(a+1)$ &
\circled{x} \quad  $ax^n+4x^n$ 
\end{longtable} 
\end{document}

In the circles there should be 1., 2. and so on.

Is it possible to define a counter which counts automaticly?

1 Answer 1

21

The following works:

\documentclass[10pt]{article} 
\usepackage{amsmath} 
\usepackage{amssymb} 
\usepackage{array}
\usepackage{tikz}
\usepackage{longtable}
\newcounter{circled}
\newcommand*\circled{\tikz[baseline=(char.base)]{
  \stepcounter{circled}
  \node[shape=circle,draw,inner sep=2pt] (char) {\arabic{circled}};}}

\begin{document} 
\begin{longtable}{lll} 
  \circled \quad  $3x^4-x^4-x^3(x+2)$ & 
  \circled \quad  $-12a^2+3a(a+1)$ &
  \circled \quad  $ax^n+4x^n$ 
\end{longtable} 
\end{document}

Output

A new counter, circled, is declared with \newcounter. It gets incremented by \stepcounter (which increments it automatically by 1; if you want other increments, use \addtocounter). Finally, its numerical value is printed with \arabic (you could use \roman or \Roman for Roman numerals instead).

Finally, note that the code you provided isn't minimal (as in Minimal Working Example (MWE)). It doesn't really matter here, but in general providing a minimal code will help you spot errors and make it easier for people here to help you :)

1
  • 4
    The macro \thecircled which is defined with \newcounter gives a consistent way to use the counter and can be redefined to \roman or \Roman (\renewcommand*{\thecircled}{\Roman{circled}}). Jul 26, 2013 at 16:06

You must log in to answer this question.

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