TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'll explain what I'm doing first:

I'm transcribing a set of seminars into LaTeX. Scattered around the text there are questions from people, that I have included as Question 1, Question 2, and so on. But I have written the number of all questions manually, so now if I have to insert another question in between questions I have to change manually all the questions that come after.

There must be a way for LaTeX to keep track of those items so that it generates the appropriate number automatically, but I don't want to make a list or an enumerate because there are big chunks of text in between questions.

(I have tried google, but I keep getting information about lists and enumerates)

Any ideas?

share|improve this question

migrated from stackoverflow.com Apr 20 '12 at 20:26

This question came from our site for professional and enthusiast programmers.

Welcome to TeX.sx! Your question was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. – Werner Apr 20 '12 at 21:14
up vote 6 down vote accepted

You probably want to use counters.

Usage is quite simple:

\paragraph{Question \arabic{question_num}}
Here you write about awsome question number \arabic{question_num}

\paragraph{Question \arabic{question_num}}
Here you write about other question, and this time number will increase :D
share|improve this answer
In general '\stepcounter{question_num}' might be a little more intuitive to increase the counter by one, but '\addtocounter' supports different step sizes of course. – Johannes Apr 22 '12 at 7:56

I would use theorem:

At the beginning of your document, you define

\newtheorem{question}{Question: }

and then, within your text, you can put at any time

\begin{question}[A very short version of the question]
Text of question and answer go here.

Counting and formatting will all be done for you. This may not be suitable for long texts, though.

share|improve this answer

I also would suggest using a theorem-type environment. One big advantage is that if you decide later that you want to change how the questions are typeset, or if you want different questions typeset differently, you can go through and simply change one setting in the preamble and have all the questions' typesetting change, while still retaining all the numbering. For example, see the following minimal code:

\newtheorem{question}{Important Question}%[section]
\newtheorem{smallQ}[question]{A small question}
\begin{question} Why is the sky blue?\end{question}
\begin{question} Why is the sky green?\end{question}
\begin{question2} Why is the sky green?\end{question2}
\begin{smallQ} Are there cows outside?\end{smallQ}

(I don't have a way to post images, but this will show blocks of text, with questions interspersed. The first two questions are styled Important Question 1 Some Question?, the third is styled Question 1 and the text normal, and there's a third style as well.

share|improve this answer

You could also use the list resume feature available with the enumitem package to define a custom question environment:

enter image description here


    \begin{enumerate}[series=Questions,resume=*,label={\textbf{Question \arabic*:}},leftmargin=*]%

    What is the meaning of this?
some more text
    What was the meaning of that?
share|improve this answer

Try setting a new counter to accomplish that.

\newcommand{\qn}{\refstepcounter{qNum} \theqNum}

than, after the \begin{document} you have to do:

Question number \qn
... bla bla ...

Question number \qn
... bla bla bla ....

and so on.

What it does, the \newcounter sets up a new counter. It starts from 0. Than, the \qn define a new command. It first increment by one the counter calling \refstepcounter. Than it prints the counter, calling \theqNum. \theqNum is generated automatically by LaTeX, and it purpose is to print the number in the counter. You could also associate a label to make possible referring later to a specific question. Hope it helps.

share|improve this answer
Welcome to TeX.sx! Your answer was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or edit your answer. – Werner Apr 20 '12 at 21:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.