# indenting exercises

I am typing up homework problems and I would like a very specific format but I'm not sure where to begin. I'd like the exercise numbers to line up in a column and then have the questions and the answers flush left with another "column" so to speak. To get an idea of what I mean this simple code works:

\documentclass{article}

\begin{document}
\begin{tabular}{l l}
5.  & This is the question          \\
& This is where the answer goes \\

11. & Another Questions             \\
\end{tabular}
\end{document}


This looks like what I want, but its annoying to put my whole assignment in a tabular environment and worry about alignment characters, ect. What I would really like is an environment where I can specify the exercise number and it will create the proper layout for the question and answer. Is this possible? Thanks!

• Are the numbers going to be not in order? For instance, you may be assigning the problems 5, 11, 21 and 37 and so on... from a text. Am I right in understanding this?
– kan
Aug 28, 2012 at 20:50
• Correct, the numbers will not necessarily be in order. Aug 28, 2012 at 20:52
• Concerning not-in-order numbered lists, see tex.stackexchange.com/questions/29850/… Aug 29, 2012 at 7:59

There are lots of ways to do this. A simple way using just an enumerate environment

\begin{enumerate}
\item[5] This is the question.
\item[] This is where the answer goes
\end{enumerate}


or perhaps you want your own environment; I've posted a few different options below- take your pick, or perhaps build one based off one of them.

\documentclass{article}
\usepackage{calc}

\newcommand{\question}[1]{\item[#1]}
\newenvironment{anotherapproach}{\enumerate}{\endenumerate}

\begin{document}

This is where the answer goes

\begin{anotherapproach}
\question{5} This is the question.
\end{anotherapproach}

\begin{enumerate}
\item[5] This is the question.
\item[] This is where the answer goes
\end{enumerate}
\end{document}


If you want to change the indentation of the enumerate environment, then the enumitem package is the most sensible way to go:

\documentclass{article}
\usepackage{calc}
\usepackage{enumitem}
\setlist[enumerate]{leftmargin=*}

• This works great and with so many options! One last question, how to I force the enumerate environment to flushleft? If there is other text on the page the enumerate starts indented further towards the middle. ***Nevermind I got it to work Aug 28, 2012 at 21:07
• @mikev This could be modified using the leftmargin key of the enumitem package.
– kan
Aug 28, 2012 at 21:11
• @mikev see my update Aug 28, 2012 at 21:12
• @cmhughes I thought mikev wanted the whole environment to flushleft and not just the text, was I wrong?
– kan
Aug 28, 2012 at 21:18
• @cmhuges, Yes, I tried the leftmargin key and it worked great, but it doesn't work when I use \begin{enumerate}{labelsep=*} to get a nice space between the numbers and the text. Aug 28, 2012 at 21:38

You can use an enumerate environment; the optional argument of \item allows you to assign the desired label:

\documentclass{article}
\usepackage[nopar]{lipsum}% just to generate text for the example

\begin{document}

\begin{enumerate}
\item This is the question.

And this is where the question goes. \lipsum[2]
\item[11.] This is another question.

And this is where the question goes. \lipsum[4]
\end{enumerate}

\end{document}


• That looks great but how do I change the numbering? My assignments jump around in the exercises, for instance 5, 11, 18, 23 Aug 28, 2012 at 20:55
• @mikev my example shows how to do it; use the optional argument of \item, as in \item[5.] Aug 28, 2012 at 20:58
• yes I see that now, this was very helpful thanks! Aug 28, 2012 at 21:06

If you're particular about having the spacing between the label, the following code, copied from Gonzalo's answer and modified suitably looks good to me:

\documentclass{article}
\usepackage{enumitem}%provides the key labelsep

\begin{document}

\begin{enumerate}[labelsep=*]
\item[5.] This is the question.

And this is where the question goes. I use \texttt{labelsep}=*
\item[11.] This is another question.

And this is where the question goes. I use \texttt{labelsep}=*
\end{enumerate}

\begin{enumerate}
\item[5.] This is the question.

And this is where the question goes. No \texttt{labelsep}=*
\item[11.] This is another question.

And this is where the question goes. No \texttt{labelsep}=*
\end{enumerate}

\end{document}


An Output:

• Thank you! The label separation looks really nice, I'm using this with a combination of the accepted answer. I really appreciate all the help from all of you! Aug 28, 2012 at 21:16
• @mikev Glad to have helped you. :)
– kan
Aug 28, 2012 at 21:21
• I really like the look that labelsep adds, but when I use it the \setlist{leftmargin=*} (as proposed by cmhughes) no longer works. Do you know how to use labelsep and still have enumerate flush left? Thanks! Aug 28, 2012 at 21:24
• That's exactly what I am experimenting with. @mikev But, I'd like to know if you want the whole enumerate environment (together with the numbers) to shift towards the center...
– kan
Aug 28, 2012 at 21:27
• I'd like the whole environment, including the numbers, to shift away from the center, towards the left side of the page. So that the numbers are flush with the regular text of the page. Aug 28, 2012 at 21:31