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?

20

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 :)

|improve this answer|||||
  • 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}}). – Qrrbrbirlbel Jul 26 '13 at 16:06

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.