4

I want to create a counter (and be able to label each time a new item of it appears) that counts problems and name them in order of their appearance, indifferent to which section they appear in. Such as:

Problem 1. Text text text equation....

and then in a totally different section/chapter

Problem 2. Text ... equation text etc

And so on.

1 Answer 1

6

You can simply define a new counter

\newcounter{problem}

and its numbering won't depend on sectioning levels.

But, looking at the result you want to achieve, I suggest you to define a new theorem-like environment

\theoremstyle{definition}
\newtheorem{problem}{Problem}

MWE:

\documentclass{book}
\usepackage{amsthm}
\theoremstyle{definition}
\newtheorem{problem}{Problem}

\begin{document}

\chapter{First}

\begin{problem}\label{prob:first}
  Some text
\end{problem}

\begin{problem}\label{prob:second}
  Some text
\end{problem}

\chapter{Second}

\begin{problem}\label{prob:third}
  Some text
\end{problem}

A reference to problem \ref{prob:second}

\end{document} 

Output:

enter image description here


EDIT (in response to the OP's comment)

You can define a new style and use it instead of definition style:

\newtheoremstyle{problem}%  <name>
  {\topsep}%                <space above>
  {\topsep}%                <space below>
  {}%                       <body font>
  {}%                       <indent amount>
  {\bfseries\large}%        <theorem head font>
  {.}%                      <punctuation after theorem head>
  {.5em}%                   <space after theorem head>
  {}%                       <theorem head spec>
\theoremstyle{problem}

Change \large to whatever you want.

MWE:

\documentclass{book}
\usepackage{amsthm}
\newtheoremstyle{problem}%  <name>
  {\topsep}%                <space above>
  {\topsep}%                <space below>
  {}%                       <body font>
  {}%                       <indent amount>
  {\bfseries\large}%        <theorem head font>
  {.}%                      <punctuation after theorem head>
  {.5em}%                   <space after theorem head>
  {}%                       <theorem head spec>
\theoremstyle{problem}
\newtheorem{problem}{Problem}

\begin{document}

\chapter{First}

\begin{problem}\label{prob:first}
  Some text
\end{problem}

\begin{problem}\label{prob:second}
  Some text
\end{problem}

\chapter{Second}

\begin{problem}\label{prob:third}
  Some text
\end{problem}

A reference to problem \ref{prob:second}

\end{document} 

Output:

enter image description here

4
  • Thanks, it works great thus far. Is it possible to change the size of the font of the thing that says "Problem 3" in your output example? Feb 24, 2015 at 12:42
  • 1
    @LoveLearning Yes, see the edit. Feb 24, 2015 at 13:05
  • Wow amazing, you're a true Maestro! Feb 24, 2015 at 13:22
  • 1
    @LoveLearning Thanks for your kind words, but "Maestro" here is someone else than me :-) I'm just a simple LaTeX user with 20 years of experience... Feb 24, 2015 at 15:51

You must log in to answer this question.

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