Given that there are packages available to typeset examples, problems and answers etc., it is not clear there is much point in doing this yourself. Nonetheless, if you wish to roll-your-own, I would try something like the following.
I drop enumerate
. It makes no sense to load it with enumitem
, especially if you are asking the latter to emulate the former with shortlabels
.
Based on your question I assume you want:
- no indentation from the left margin;
- no additional vertical spacing between items in the list, regardless of level.
Since this is not entirely straightforward to do, if you didn't mean it, you should have been clearer about your desiderata.
Based on my best attempt to understand your desiderata from your question and code, I used a 3-level list questions
defined with enumitem
. Within the list \qn
creates a question and \ans
creates an answer.
Hence,
\begin{questions}
\qn How many countries are there in the world?
\ans There are 196 countries in the world today. Unless you don't count Taiwan…
\begin{questions}
\qn How many countries are there in Europe?
\ans Approximately 50 countries.
\qn How many countries are there in Asia?
\ans 48.
\end{questions}
\qn What is the population of the world?
\ans Around 7.4 billion people
\begin{questions}
\qn What is the population of the US?
\ans 324,532,828 as of Sunday, September 4, 2016.
\begin{questions}
\qn What is the population of Nevada state?
\ans Around 2,943,409.
\end{questions}
\end{questions}
\end{questions}
produces
Code:
\documentclass{article}
\usepackage{enumitem}
\makeatletter
\newlist{questions}{enumerate}{3}
\setlist[questions]{itemindent=0pt, labelwidth=!,align=parleft,itemsep=\lineskip,parsep=\lineskip}
\setlist[questions,1]{label=Q\,\arabic*,leftmargin=1.5\parindent,labelindent=0pt,ref=\arabic*}
\setlist[questions,2]{label=Q\,\arabic{questionsi}.\arabic*,leftmargin=.5\parindent,labelindent=-1.5\parindent,ref=\arabic{questionsi}.\arabic*,topsep=\lineskip,partopsep=\lineskip}
\setlist[questions,3]{label=Q\,\arabic{questionsi}.\arabic{questionsii}.\arabic*,leftmargin=.5\parindent,labelindent=-2\parindent,ref=\arabic{questionsi}.\arabic{questionsii}.\arabic*,topsep=\lineskip,partopsep=\lineskip}
\newcommand*\qn{\stepcounter{cntquestions}\item\label{qn:\thecntquestions}}
\newcommand*\ans{\item[A\,\ref{qn:\thecntquestions}]}
\newcounter{cntquestions}
\setcounter{cntquestions}{0}
\makeatother
\begin{document}
\begin{questions}
\qn How many countries are there in the world?
\ans There are 196 countries in the world today. Unless you don't count Taiwan…
\begin{questions}
\qn How many countries are there in Europe?
\ans Approximately 50 countries.
\qn How many countries are there in Asia?
\ans 48.
\end{questions}
\qn What is the population of the world?
\ans Around 7.4 billion people
\begin{questions}
\qn What is the population of the US?
\ans 324,532,828 as of Sunday, September 4, 2016.
\begin{questions}
\qn What is the population of Nevada state?
\ans Around 2,943,409.
\end{questions}
\end{questions}
\end{questions}
\end{document}
Best Answer
With
enumitem
:There is also
label*
which will append the parent's label, but as you want parenthesis here, it may not be suitable.If you want labels to be flush to the left margin, add this in the preamble: