# Text between before the actual description in a description list

How do I insert a custom (constant) text before all item descriptions in a description list?

For instance, I want to create something like this:

 Question 1: My question


Generated from a code like:

\begin{questionsandanswers}


I'm using enumitem to edit some parts of the description list. My code until now follows:

    \usepackage{enumitem}

\newcounter{descriptcount}
\newlist{enumdescript}{description}{2}
\setlist[enumdescript,1]{%
before={\setcounter{descriptcount}{0}%
\renewcommand*\thedescriptcount{\arabic{descriptcount}}}
,font=\textbf{\stepcounter{descriptcount}Question \thedescriptcount:~} \normalfont
}
\setlist[enumdescript,2]{%
before={\setcounter{descriptcount}{0}%
\renewcommand*\thedescriptcount{\alph{descriptcount}}}
,font=\textbf{\stepcounter{descriptcount}Question \thedescriptcount:~} \normalfont
}



With such a code a get something like:

Question 1: My question


But I can't find how to put the "Answer" word before the actual answer. Also, follows a minimal working example:

\documentclass{article}[12pt,a4paper]

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{enumitem}

\newcounter{descriptcount}
\newlist{enumdescript}{description}{2}
\setlist[enumdescript,1]{%
before={\setcounter{descriptcount}{0}%
\renewcommand*\thedescriptcount{\arabic{descriptcount}}}
,font= \textbf{\stepcounter{descriptcount}Question \thedescriptcount.~} \normalfont
}
\setlist[enumdescript,2]{%
before={\setcounter{descriptcount}{0}%
\renewcommand*\thedescriptcount{\alph{descriptcount}}}
,font= \textbf{\stepcounter{descriptcount}Question \thedescriptcount.~} \normalfont
}

\begin{document}

Desired syntax:

Desired result:

\end{document}

• Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
– user31729
Feb 25, 2015 at 20:54
• I would use an interface that resembles \begin{questionsandanswers} \newquestion This is the question? \newanswer This is the answer. \newquestion This is another question? \newanswer This is another answer. \end{questionsandanswers}, or even simplify it to \question and \answer. Are you open to such a suggestion?
– Werner
Feb 25, 2015 at 21:36
• @Werner I though of such solution, but it is more loose than my desired syntax. By replacing the \item by two separated commands I let go off the need for an actual answer. One can put several \question without appearing a single \answer. Other solution would be an \questionanswer{My Question}{My Answer} (two parameters), but I really want to know if it can be done using the \item ...
– Isma
Feb 25, 2015 at 21:44
• @Isma: You can force the user to require a \newanswer with every \newquestion, thereby not "let[ting] go of the need for an actual answer".
– Werner
Feb 25, 2015 at 21:56

Here's a rather hacky way to achieve your desired output:

\documentclass{article}

\usepackage{enumitem}

\newcounter{descriptcount}
\newlist{enumdescript}{description}{2}
\setlist[enumdescript,1]{%
before={\setcounter{descriptcount}{0}%
\renewcommand*\thedescriptcount{\arabic{descriptcount}}}
,font= \textbf{\stepcounter{descriptcount}Question \thedescriptcount.~} \normalfont
}
\setlist[enumdescript,2]{%
before={\setcounter{descriptcount}{0}%
\renewcommand*\thedescriptcount{\alph{descriptcount}}}
,font= \textbf{\stepcounter{descriptcount}Question \thedescriptcount.~} \normalfont
}

\renewcommand{\descriptionlabel}[1]{%
\hspace\labelsep
\normalfont\bfseries##1}%
\let\oldnewline\newline
\begin{enumdescript}[style=nextline,labelindent=\parindent,leftmargin=\parindent]
\end{enumdescript}
}

\begin{document}

Desired syntax:

\end{document}


I'd much rather prefer the following setup though:

\documentclass{article}

\usepackage{enumitem}

\newcounter{descriptcount}
\newlist{enumdescript}{description}{2}
\setlist[enumdescript,1]{%
before={\setcounter{descriptcount}{0}%
\renewcommand*\thedescriptcount{\arabic{descriptcount}}}
,font= \bfseries
}
\setlist[enumdescript,2]{%
before={\setcounter{descriptcount}{0}%
\renewcommand*\thedescriptcount{\alph{descriptcount}}}
,font= \bfseries
}
\newcommand{\newquestion}{%
\stepcounter{descriptcount}%
\item[Question~\thedescriptcount.]}
\par\vspace{-.5\baselineskip}

\begin{enumdescript}[labelindent=\parindent,leftmargin=\parindent]
\end{enumdescript}
}

\begin{document}

Desired syntax:

\newquestion My question
\newquestion Another question

\end{document}


The above doesn't force the user to have a \newanswer with every \newquestion. However, you can force this with the following definitions \newquestion:

\long\def\newquestion#1\newanswer{%
\stepcounter{descriptcount}%
\item[Question~\thedescriptcount.] #1


The parameter text of \newquestion now includes \newanswer. As such, without it in the input stream, TeX will complain, forcing the user to have a \newanswer with every \newquestion.

try this code

\documentclass{article}[12pt,a4paper]

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\makeatletter
\newcounter{descriptcount}
\labelwidth0pt\itemindent-\leftmargin
\let\makelabel\qudescriptionlabel}
\def\item[##1]{%
\@inmatherr\item
{\endlist}
\makeatother
\newcommand\qudescriptionlabel[1]{%
\refstepcounter{descriptcount}\hspace\labelsep
\normalfont\bfseries Question \thedescriptcount.~ #1}

\begin{document}

• I tried your solution and it was almost effective. However, I couldn't put a line break before "Answer". I tried to put \normalfont\bfseries Question \thedescriptcount.~ #1 \\ Answer: }, also tried \normalfont\bfseries Question \thedescriptcount.~ #1 \newline Answer: } (both with and withoud \hfill).
– Isma
Feb 25, 2015 at 21:52
• Yes this is enside sbox so no line break here Feb 25, 2015 at 22:44
• @Isma I edit my answer. Feb 25, 2015 at 23:01