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 write the code like:

...
    \item
    \textbf{Differentiation}.

    Differentiate with respect to $x$:
    \begin{exercises}{3}
        \item$x^{2} - 3x$.
        \item$x^{5} - \dfrac{x^3}{3}$.
        \item$x + \dfrac{1}{x}$.
        ...
    \end{exercises}

    \item
    Differentiate with respect to $x$:
        \begin{exercises}{2}
        \item$y = x\cos\frac{1}{2}x$.
        \item$y = \sin\left(\dfrac{\pi x}{180}\right)$.
        \item$y = \frac{x^2}{1+x}$.
        ...
        \end{exercises}
    ...
...

sample pic

But if I use shortlst package as an advice from An environment which be used to arrange exercises mostly similiar with common enumerate list, the content after second \item Differentiate with respect to $x$ in pic above will typeset in three columns.

----EDIT---- The proposal that use a minipage environment is restricted with the minipage's width defined in advance, that say, it is not suit for different page width. change

\documentclass{article}
\usepackage{shortlst}
\usepackage[width=10cm]{geometry}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\newenvironment{exercises}[1]
    {#1:\\ \begin{minipage}[t]{0.9\textwidth}\begin{shortenumerate}}
    {\end{shortenumerate}\end{minipage}}
\begin{enumerate}
\item
\begin{exercises}{\textbf{Differentiation}\\ Differentiate with respect to $x$}
     \item $x^3-3x$
     \item $x^5-\frac{x^3}{3}$
     \item $x+\frac{1}{x}$
     \item $(x+1)^2(x-1)^2$
     \item $x\sin x$
\end{exercises}
\item
\begin{exercises}{Differentiate with respect to $x$}
     \item $y=x\cos \frac{1}{2}x$
     \item $y=\sin\left(\frac{\pi x}{180}\right)$
     \item $y=\frac{x^2}{1+x}$ 
\end{exercises}
\end{enumerate}
\end{document}

to

\documentclass{article}
\usepackage{shortlst}
\usepackage[width=9cm]{geometry}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\newenvironment{exercises}[1]
    {#1:\\ \begin{minipage}[t]{0.9\textwidth}\begin{shortenumerate}}
    {\end{shortenumerate}\end{minipage}}
\begin{enumerate}
\item
\begin{exercises}{\textbf{Differentiation}\\ Differentiate with respect to $x$}
     \item $x^3-3x$
     \item $x^5-\frac{x^3}{3}$
     \item $x+\frac{1}{x}$
     \item $(x+1)^2(x-1)^2$
     \item $x\sin x$
\end{exercises}
\item
\begin{exercises}{Differentiate with respect to $x$}
     \item $y=x\cos \frac{1}{2}x$
     \item $y=\sin\left(\frac{\pi x}{180}\right)$
     \item $y=\frac{x^2}{1+x}$ 
\end{exercises}
\end{enumerate}
\end{document}

will get

sample2

so is the code given by Schweinebacke unless I changed the width individually

\documentclass{article} 
\usepackage{shortlst}% http://ctan.org/pkg/shortlst 
\usepackage{scrextend} 
\usepackage{lipsum} 
\usepackage[width=10cm]{geometry} %added
\begin{document} 

\lipsum[1] 
\begin{enumerate} 
\item {Differentiate with respect to $x$: 
  \begin{addmargin}[0pt]{0.1\linewidth} 
    \begin{shortenumerate} 
      \item $x^3-3x$  
      \item $x^5-\frac{x^3}{3}$ 
      \item $x+\frac{1}{x}$ 
      \item $(x+1)^2(x-1)^2$ 
      \item $x\sin x$ 
    \end{shortenumerate} 
  \end{addmargin} 
} 
\item {Differentiate with respect to $x$: 
  \begin{addmargin}[0pt]{.4\linewidth} 
    \begin{shortenumerate} 
      \item $y=x\cos \frac{1}{2}x$ 
      \item $y=\sin\left(\frac{\pi x}{180}\right)$ 
      \item $y=\frac{x^2}{1+x}$ 
      \item $y=x\cos \frac{1}{2}x$ 
      \item $y=\sin\left(\frac{\pi x}{180}\right)$ 
      \item $y=\frac{x^2}{1+x}$ 
      \item $y=x\cos \frac{1}{2}x$ 
      \item $y=\sin\left(\frac{\pi x}{180}\right)$ 
      \item $y=\frac{x^2}{1+x}$ 
      \item $y=x\cos \frac{1}{2}x$ 
      \item $y=\sin\left(\frac{\pi x}{180}\right)$ 
      \item $y=\frac{x^2}{1+x}$ 
    \end{shortenumerate} 
  \end{addmargin} 
} 
\end{enumerate} 
\end{document}

sample3

share|improve this question
    
Have you considered the multicol package? –  cmhughes Nov 20 '11 at 16:33

4 Answers 4

up vote 2 down vote accepted

The result of your earlier question, possibly in a minipage, and an ordinary enumeration environment should get the result you want.

\documentclass{article}
\usepackage{shortlst}% http://ctan.org/pkg/shortlst
\begin{document}

\newenvironment{exercises}[1]
    {#1:\\ \begin{minipage}[t]{0.9\textwidth}\begin{shortenumerate}}
    {\end{shortenumerate}\end{minipage}}

\begin{enumerate}
\item 
\begin{exercises}{\textbf{Differentiation}\\ Differentiate with respect to $x$}
     \item $x^3-3x$ 
     \item $x^5-\frac{x^3}{3}$
     \item $x+\frac{1}{x}$
     \item $(x+1)^2(x-1)^2$
     \item $x\sin x$
\end{exercises}
\item 
\begin{exercises}{Differentiate with respect to $x$}
     \item $x^3-3x$ 
     \item $x^5-\frac{x^3}{3}$
     \item $x+\frac{1}{x}$
     \item $(x+1)^2(x-1)^2$
     \item $x\sin x$
\end{exercises}
\end{enumerate}

\end{document}

which looks like

enter image description here

If you want a table like environment to handle a specific number of columns of equations, then you can define a new counter to do this.

\newcounter{innerlist} 
\renewcommand{\theinnerlist}{\arabic{innerlist}} 
\newcommand{\inneritem}[1]{\refstepcounter{innerlist}\theinnerlist.\ #1}

\newenvironment{exercises}[2]
    {\setcounter{innerlist}{0}\begin{minipage}[t]{0.9\textwidth}#1:\\ \begin{tabular}{#2}}
    {\end{tabular}\end{minipage}}


\begin{enumerate}
    \item 
    \begin{exercises}{\textbf{Differentiation}\\ Differentiate with respect to $x$}{ll}
        \inneritem{$x^3-3x$} & \inneritem{$x^5-\frac{x^3}{3}$}\\
        \inneritem{$x+\frac{1}{x}$} & \inneritem{$(x+1)^2(x-1)^2$}\\
        \inneritem{$x\sin x$} & \inneritem{$x\sin x$}
    \end{exercises}
    \item
    \begin{exercises}{\textbf{Differentiation}\\ Differentiate with respect to $x$}{lll}
        \inneritem{$x^3-3x$} & \inneritem{$x^5-\frac{x^3}{3}$} & \inneritem{$x+\frac{1}{x}$}\\
        \inneritem{$(x+1)^2(x-1)^2$} & \inneritem{$x\sin x$} & \inneritem{$x\sin x$}
    \end{exercises}
\end{enumerate}

enter image description here

This version shouldn't have any big issues spreading over pages. Each minipage shouldn't spread between pages, but the items in the outer enumerated list will spread fine.

An alteration using the longtables package allows this to run over pages:

\newenvironment{exercises}[2]
    {\setcounter{innerlist}{0}#1:\\ \begin{longtable}[t]{#2}}
    {\end{longtable}}
share|improve this answer
    
Thank you. But a minipage environment can not break page down nicely. –  Tau spit Nov 20 '11 at 11:14
    
I'm not sure what you mean, can you explain what is wrong with minipage? See the image I included above as an example. –  qubyte Nov 20 '11 at 11:23
    
Note that you must include t as an optional argument to minipage to get the numbers in the right place. –  qubyte Nov 20 '11 at 11:24
    
I mean if the quantity of items inside a minipage is too large, there will occur an overfull. –  Tau spit Nov 20 '11 at 11:29
    
That doesn't make sense. You can limit the horizontal size of a minipage. In this code I have to 0.9\textwidth. –  qubyte Nov 20 '11 at 11:50

I would suggest to combine Mark's answer with package scrextend. That would support page breaks inside the exercise:

\documentclass{article}
\usepackage{shortlst}% http://ctan.org/pkg/shortlst
\usepackage{scrextend}
\usepackage{lipsum}
\begin{document}

\lipsum[1-4]
\begin{enumerate}
\item {Differentiate with respect to $x$:
  \begin{addmargin}[0pt]{2em}
    \begin{shortenumerate}
      \item $x^3-3x$ 
      \item $x^5-\frac{x^3}{3}$
      \item $x+\frac{1}{x}$
      \item $(x+1)^2(x-1)^2$
      \item $x\sin x$
    \end{shortenumerate}
  \end{addmargin}
}
\item {Differentiate with respect to $x$:
  \begin{addmargin}[0pt]{2em}
    \begin{shortenumerate}
      \item $y=x\cos \frac{1}{2}x$
      \item $y=\sin\left(\frac{\pi x}{180}\right)$
      \item $y=\frac{x^2}{1+x}$
      \item $y=x\cos \frac{1}{2}x$
      \item $y=\sin\left(\frac{\pi x}{180}\right)$
      \item $y=\frac{x^2}{1+x}$
      \item $y=x\cos \frac{1}{2}x$
      \item $y=\sin\left(\frac{\pi x}{180}\right)$
      \item $y=\frac{x^2}{1+x}$
      \item $y=x\cos \frac{1}{2}x$
      \item $y=\sin\left(\frac{\pi x}{180}\right)$
      \item $y=\frac{x^2}{1+x}$
    \end{shortenumerate}
  \end{addmargin}
}
\end{enumerate}
\end{document}

Note: If you're already using a KOMA-Script class you don't need to load the package scrextend.

You may define an enviroment for this:

\documentclass{article}
\usepackage{shortlst}% http://ctan.org/pkg/shortlst  
\usepackage{scrextend}
\usepackage{lipsum}% 
\usepackage[width=10cm]{geometry} %added

\newenvironment{exercise}[1][\strut]{%
  \item #1\begin{addmargin}[0pt]{2em}\begin{shortenumerate} 
}{%
  \end{shortenumerate}\end{addmargin} 
}
\begin{document} 

\lipsum[1] 
\begin{enumerate}
  \begin{exercise}[{Differentiate with respect to $x$:}]
  \item $x^3-3x$  
  \item $x^5-\frac{x^3}{3}$ 
  \item $x+\frac{1}{x}$ 
  \item $(x+1)^2(x-1)^2$ 
  \item $x\sin x$ 
  \end{exercise}
  \begin{exercise}[{Differentiate with respect to $x$:}]
  \item $y=x\cos \frac{1}{2}x$ 
  \item $y=\sin\left(\frac{\pi x}{180}\right)$ 
  \item $y=\frac{x^2}{1+x}$ 
  \item $y=x\cos \frac{1}{2}x$ 
  \item $y=\sin\left(\frac{\pi x}{180}\right)$ 
  \item $y=\frac{x^2}{1+x}$ 
  \item $y=x\cos \frac{1}{2}x$ 
  \item $y=\sin\left(\frac{\pi x}{180}\right)$ 
  \item $y=\frac{x^2}{1+x}$ 
  \item $y=x\cos \frac{1}{2}x$ 
  \item $y=\sin\left(\frac{\pi x}{180}\right)$ 
  \item $y=\frac{x^2}{1+x}$ 
  \end{exercise} 
\end{enumerate} 
\end{document}

Result of both examples

share|improve this answer
    
If I add \usepackage[b5paper]{geometry} I couldn't get a desired result. –  Tau spit Nov 20 '11 at 12:28
    
@Tau spit: I get the desired result even if I add \usepackage[b5paper]{geometry} to my MWE. Page break would be earlier, but first has still three columns while second has two columns. Nevertheless you may simply change value 0.1\linewidth and 0.4\linewidth at the example to the value you need to get one, two or three columns as you like. BTW: IMHO b5paper is a strange paper width for a document. a5paper would be more common. In this case you may use .3\linewidth at the second exercise to get two columns. –  Schweinebacke Nov 20 '11 at 12:46
    
Thanks for your explain. I have edited the question. The problem is I don't want change the width one by one. –  Tau spit Nov 20 '11 at 13:04
    
@Tau spit: I still do not understand the problem. Why shouldn't the second exercise be set in three columns (that would be, if you simply remove minipage or addmargin from the suggested answers). If you just want little more right indention, just try my changed example with always 2em right indention and three columns for the first exercise but two for the second, without changing the width. –  Schweinebacke Nov 20 '11 at 13:18
    
I just want my result's appearance is close to the origin document as far as possible. As for the origin doc, why shouldn't the second exercise be set in three columns? I don't know either. Maybe just for neat and tidy. –  Tau spit Nov 20 '11 at 13:32

You could use a combination of multicols with a newlist using the enumitem package, as demonstrated below.

It allows pagebreaks too.

screenshot

\documentclass{article} 
\usepackage{lipsum} 
\usepackage{multicol}             % multicols
\usepackage{enumitem}             % customized lists
\usepackage[width=10cm]{geometry} % page dimensions

% setup a new list (terminology from enumitem)
\newlist{mylist}{enumerate}{5}
\setlist[mylist]{label=(\alph*)}

\newenvironment{exercises}[1]{\begin{multicols}{#1}\begin{mylist}}{\end{mylist}\end{multicols}}

\begin{document} 

\vspace*{4cm}   % purely to demonstrate the pagebreak
\lipsum[1-2] 

\begin{enumerate} 
 \item {Differentiate with respect to $x$:}
  \begin{exercises}{2}
      \item $x^3-3x$  
      \item $x^5-\frac{x^3}{3}$ 
      \item $x+\frac{1}{x}$ 
      \item $(x+1)^2(x-1)^2$ 
      \item $x\sin x$ 
  \end{exercises} 
 \item Differentiate with respect to $x$:
 \begin{exercises}{2}
      \item $y=x\cos \frac{1}{2}x$ 
      \item $y=\sin\left(\frac{\pi x}{180}\right)$ 
      \item $y=\frac{x^2}{1+x}$ 
      \item $y=x\cos \frac{1}{2}x$ 
      \item $y=\sin\left(\frac{\pi x}{180}\right)$ 
      \item $y=\frac{x^2}{1+x}$ 
      \item $y=x\cos \frac{1}{2}x$ 
      \item $y=\sin\left(\frac{\pi x}{180}\right)$ 
      \item $y=\frac{x^2}{1+x}$ 
      \item $y=x\cos \frac{1}{2}x$ 
      \item $y=\sin\left(\frac{\pi x}{180}\right)$ 
      \item $y=\frac{x^2}{1+x}$ 
  \end{exercises} 
\end{enumerate} 
\end{document}
share|improve this answer

Here is another solution using the {tasks} environment provided by the exsheets package. There is at least one downside to it, though: it cannot safely be nested with other {tasks} environments. (It is not a real list in the LaTeX sense although the syntax is similar.)

The environment has an optional argument that specifies the number of columns:

\begin{tasks}{<num of cols>}
 \task first item
 \task second item
 ...
\end{tasks}

Here is the full example:

\documentclass{article}
\usepackage[load-headings]{exsheets}

\SetupExSheets{
  % first the number then the title:
  headings=block-rev,
  % number tasks (a), (b), ...
  tasks/label=(tsk[a]),
  % make sure the task item labels have enough space:
  tasks/label-width=2em
}
\usepackage{lipsum}% dummy text

\begin{document} 

\lipsum[1]\bigskip

\begin{question}[name=Differentiation]
 Differentiate with respect to $x$: 
 \begin{tasks}{3}% three columns
   \task $x^3-3x$  
   \task $x^5-\frac{x^3}{3}$ 
   \task $x+\frac{1}{x}$ 
   \task $(x+1)^2(x-1)^2$ 
   \task $x\sin x$
 \end{tasks}
\end{question}

\begin{question}[name=More Differentiation]
 Differentiate with respect to $x$: 
 \begin{tasks}{2}% two columns
   \task $y=x\cos \frac{1}{2}x$ 
   \task $y=\sin\left(\frac{\pi x}{180}\right)$ 
   \task $y=\frac{x^2}{1+x}$ 
   \task $y=x\cos \frac{1}{2}x$ 
   \task $y=\sin\left(\frac{\pi x}{180}\right)$ 
   \task $y=\frac{x^2}{1+x}$ 
   \task $y=x\cos \frac{1}{2}x$ 
   \task $y=\sin\left(\frac{\pi x}{180}\right)$ 
   \task $y=\frac{x^2}{1+x}$ 
   \task $y=x\cos \frac{1}{2}x$ 
   \task $y=\sin\left(\frac{\pi x}{180}\right)$ 
   \task $y=\frac{x^2}{1+x}$ 
 \end{tasks}
\end{question}

\end{document}

enter image description here

share|improve this answer

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.