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 want to format a list of "Question + Answer" pairs in a TeX-document.

In HTML I use the <dl> command: http://www.w3.org/TR/html401/struct/lists.html, e.g.:

<dl>
<dt>Question?</dt>
<dd>
    Answer
</dd>
</dl>

In TeX I thought using the description environment would be good for those purposes.

\begin{description}
\item[Question?] Answer
\end{description}

But when the question becomes very long, it does not break into a new line. When the question is short, the answer begins directly behind the question and not in a new line.

What environment should I use for this problem?

share|improve this question
add comment

3 Answers

up vote 18 down vote accepted

The deficiency you've noticed in the LaTeX description environment -- that if an item's "label" (the part in brackets) is longer than one line, it won't produce a proper line break -- is well known. The easiest workaround I'm aware of is to use the enumitem package and to start the description list with the option style=nextline, as in the following MWE:

\documentclass{article}
\usepackage{enumitem}
\begin{document}
    \begin{description}[style=nextline]
    \item[Why is there a deficiency in the basic description environment 
       that I have to struggle with?] Answer: Just use the enumitem package
       and start the description environment with the "style=nextline" option.
    \item[Question 2?] Answer 2.
    \end{description}
\end{document}

Note that if you do not want the "Answer" (i.e., the text after the item's "label") to start on a new line, all you need to change is to set the option style=sameline at the beginning the description environment.

Addendum: If you wish to have the "style=nextline" instruction apply to all description environments, it would be tedious to have to remember to specify this option every single time. Instead, you should issue the instruction

\setlist[description]{style=nextline}

after loading the enumitem package to set this option globally. The resulting behavior can be overridden if need be, on a case-by-case basis, by supplying the option [style=same-line] when a given description environment is initiated.

share|improve this answer
add comment

I would suggest just using the \paragraph or \subparagraph sectioning commands. Not only they produce the similar "FAQ" look, but they also allow to create a ToC with the questions.

If, in contract, you don't want the run-in titles, you can use \subsubsection in a similar way.

\documentclass{article}

\usepackage{lipsum}

\begin{document}

\paragraph{What is the answer to the Ultimate Question of Life, the Universe, and Everything?}
42

\paragraph{How does the Lorem Ipsum text read?}
\lipsum[1]

\end{document}

Note that you can also change the appearance of sectioning commands with the titlesec package.

share|improve this answer
add comment

I would suggest defining a new environment, and using that. Building on other answers:

% Use for advanced enum-list functionality
\usepackage{enumitem}

% Define question and answer environment
\newenvironment{faq}{\begin{description}[style=nextline]}{\end{description}}

And then use it the same as description:

\begin{faq}
  \item[What is the day today?]
    Monday
  \item[How much is it?]
    Alot!
\end{faq}

Gives us something like this:

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.