2

I want to set a counter (auto) like:

\newcounter{question}
\newcounter{example}

Question 1. Question 2. Example 3. Example 4. Question 5. Question 6.

Can you help me. Thankyou so much.

  • 1
    Welcome to TeX.SE! – Mensch Apr 3 at 8:10
4

Welcome Đặc Vụ :))) Although using question and example from amsthm is the best way, one can always define a new counter and use it.

\documentclass{article}
\setlength{\parskip}{1ex}
\newcounter{yourcounter}
\newcommand\yourquestion[1]{%
\textbf{\stepcounter{yourcounter}Question \arabic{yourcounter}:} \textit{#1}\par}
\newcommand\yourexample[1]{%
\textbf{\stepcounter{yourcounter}Example \arabic{yourcounter}:} \textit{#1}\par}
\begin{document}
\yourquestion{How many continents are there?}
\yourexample{This example is for no purposes.}
\yourexample{And this is another example.}
\yourquestion{This is another question.}
\yourexample{How about the numbering of this example?}
\yourquestion{Lorem ipsum dolor sit amet, consectetur adipiscing elit. In eget viverra eros. Donec commodo dapibus dictum. Etiam non ex placerat, fermentum ex sed, suscipit sem. Praesent facilisis vel quam non fringilla. Morbi sagittis tortor sed varius luctus. Curabitur ullamcorper ante scelerisque quam commodo, quis imperdiet sapien maximus. Phasellus bibendum, ligula eu tempor vulputate, tortor erat bibendum sem, eget lacinia mauris dui ac elit.}
\end{document}

enter image description here

5

Like this?

\documentclass{article}
\usepackage{amsmath,amsthm}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

\newtheorem{question}{Question} 
\newtheorem{example}[question]{Example}

\begin{document}
\section{Questions and Examples}

\begin{question}
$2+2=?$
\end{question}

\begin{question}
$\int \dfrac{1}{1+x} \mathrm{d}x=?$
\end{question}

\begin{example}
$2+2=4$
\end{example}

\begin{example}
Air...
\end{example}

\begin{question}
$2\times 5=10$
\end{question}

\end{document}

enter image description here

  • That's right what I need. Thank you so much. – Đặc Vụ X Nguyễn Apr 3 at 8:45
  • @ĐặcVụXNguyễn, your welcome. But, I think you will use JoulV's answer. – ferahfeza Apr 3 at 8:55
  • @ĐặcVụXNguyễn, did you copy my answer? I will delete it soon. – ferahfeza Apr 3 at 9:17
  • @ferahfeza Please don't delete your answer! – user156344 Apr 3 at 9:20

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.