5

I'm writing a report and would like to put several questions in a \subsubsection{} with the following format (questions appear in the middle of the page)

1.2. Questions

                          *This is the question one*

This is the answer for question one.

                          *This is another question*

This is the answer for the question two.

azetina
  • 28,884
asghar ashgari
  • 305
  • 1
  • 2
  • 10

2 Answers2

10

As cgnieder mentioned in his comment, the exercise package offers you ready to use environments and commands that could be useful for your purpose. A little example:

\documentclass{article}
\usepackage{exercise}
\usepackage{lipsum}% just to produce filler text

\renewcommand\ExerciseName{Question~}
\renewcommand\AnswerName{Answer to question}
\renewcommand\ExerciseHeader{%
  \noindent\parbox[t]{.18\textwidth}{%
    \bfseries\large\ExerciseName\ExerciseHeaderNB\hfill}%
  \parbox[t]{.72\textwidth}{%
    \centering\bfseries\large%
    \ExerciseHeaderTitle\ExerciseHeaderOrigin}%
  \par\medskip
}

\begin{document}

\section{Questions}
\begin{Exercise}[title={Some easy question}, label=que1]
\lipsum[2]
\end{Exercise}
\begin{Answer}[ref=que1]
\lipsum[2]
\end{Answer}
\begin{Exercise}[title={Some difficult question with a really really long title}, label=que2]
\lipsum[2]
\end{Exercise}
\begin{Answer}[ref=que2]
\lipsum[2]
\end{Answer}

\end{document}

enter image description here

Gonzalo Medina
  • 505,128
  • Thanks for the reply. I personally do not like the "Answer to question x" part. So for now I just use : \begin{Exercise} ... \end{Exercise} for both question and its answer. – asghar ashgari May 15 '12 at 14:11
  • I also found a problem with the solution, if the question is long it exceeds the page margins. Any solution to this? – asghar ashgari May 15 '12 at 14:21
  • @asgharashgari all you have to do is to redefine \ExerciseHeader according to your needs; see my updated answer. – Gonzalo Medina May 15 '12 at 14:38
  • Thanks it improved a lot. There is one main thing I can't get around it. Questions have different lengths and the 'Question' keyword is not inline with the other 'Question' keywords. How can I achieve this effect?. Thanks. – asghar ashgari May 15 '12 at 15:04
  • @asgharashgari: please see my updated answer. Is something like that what you want? – Gonzalo Medina May 15 '12 at 15:18
  • @GonzaloMedina, how to remove the the unwanted para "Nam dui ligula, ........., luctus mauris" below the question ? – learner Mar 02 '23 at 03:00
5

Consider the exam class. In the example below, comment or uncomment the \printanswers command to replace the ruled space for a student to write their answers with your own typeset content. No problems with questions spanning multiple pages, either.

\documentclass{exam}
\usepackage{lipsum}
%\printanswers

\begin{document}

\section{Questions}

\begin{questions}
\question[10] Why is there air?
\begin{solutionorlines}[1in]
For several reasons.
\end{solutionorlines}

\question What if there were no air?
\begin{parts}
\part[5] Describe the effect on the balloon industry.
\begin{solutionorlines}[0.5in]
Bad.
\end{solutionorlines}
\part[5] Describe the effect on the aircraft industry.
\begin{solutionorlines}[0.5in]
Worse,
\end{solutionorlines}
\end{parts}

\question[20]
\begin{parts}
\part Define the universe. Give three examples.
\part If the universe were to end, how would you know?
\begin{solutionorlines}[1in]
Something else goes here.
\end{solutionorlines}
\end{parts}

\question[60] \lipsum

\end{questions}

\end{document}

enter image description here

Mike Renfro
  • 20,550
  • Thanks for the reply. This is not a good solution in my case; because I already have a \documentclass{} for my report and I can't change that. – asghar ashgari May 15 '12 at 14:41