Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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
    
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
add comment

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

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

5 Answers

up vote 5 down vote accepted

You probably want to use counters.

Usage is quite simple:

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

\addtocounter{question_num}{1}
\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
add comment

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.
\end{question}

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

share|improve this answer
add comment

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:

\documentclass[11pt]{amsart}
\usepackage{geometry}               
\geometry{letterpaper}                   
\usepackage{amsthm}
\usepackage{lipsum}
\theoremstyle{plain}
\newtheorem{question}{Important Question}%[section]
\theoremstyle{definition}
\newtheorem{question2}[question]{Question}
\theoremstyle{remark}
\newtheorem{smallQ}[question]{A small question}
\begin{document}
\lipsum[1]
\begin{question} Why is the sky blue?\end{question}
\lipsum[2]
\begin{question} Why is the sky green?\end{question}
\lipsum[3]
\begin{question2} Why is the sky green?\end{question2}
\begin{smallQ} Are there cows outside?\end{smallQ}
\lipsum[6]
\end{document}  

(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
add comment

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

enter image description here

\documentclass{article}
\usepackage{enumitem}

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

\begin{document}
\begin{question}
    What is the meaning of this?
\end{question}
%
some more text
%
\begin{question}
    What was the meaning of that?
\end{question}
\end{document}
share|improve this answer
add comment

Try setting a new counter to accomplish that.

\newcounter{qNum}
\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
add comment

Your Answer

 
discard

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