2

I have recently downloaded the tasks package which align a list horizontally in columns by using an environment tasks, And tried it on this MWE

\documentclass{article}
\usepackage{tasks}

\begin{document}
\settasks{counter-format = tsk/}
\begin{tasks}(2)

\task $f(x)=3x+4$  
\task $f(x)=2x^4+3x^3-x^2+17$  
\task $f(x)=cos(x)sin(x)$  
\task $f(x)=\dfrac{4x}{\sqrt{x}}$  
\task $f(x)=x^2-1$
\task $f(x)=(x^2-1)\sqrt{x}$
\task $f(x)=\dfrac{-2}{x+1}$ 
\task $f(x)=(-x-2)^2$

\end{tasks}
\end{document}

when compiled with PdfLaTeX i have error

! LaTeX Error: Something's wrong--perhaps a missing \item.

and we have no result in the preview part (my IDE is texmaker), but the PDF File appears in the tex file directory enter image description here how to solve this problem with tasks, and is there other packages to do this?

1
  • BTW: why download the package? It is part of both TeX Live and MiKTeX...?!
    – cgnieder
    Aug 1 '14 at 11:57
3

Remove the empty line at the beginning before the first \task and the error is gone.

\documentclass{article}
\usepackage{tasks,amsmath}

\begin{document}
\settasks{counter-format = tsk/}
\begin{tasks}(2)
  \task $f(x)=3x+4$  
  \task $f(x)=2x^4+3x^3-x^2+17$  
  \task $f(x)=\cos(x)\sin(x)$  
  \task $f(x)=\dfrac{4x}{\sqrt{x}}$  
  \task $f(x)=x^2-1$
  \task $f(x)=(x^2-1)\sqrt{x}$
  \task $f(x)=\dfrac{-2}{x+1}$ 
  \task $f(x)=(-x-2)^2$
\end{tasks}
\end{document}

The tasks list is not a list in the sense it is used usually in LaTeX, i.e., it doesn't actually use LaTeX's list mechanism (this is explained in the manual). It tries to mimic the behavior, though. LaTeX's lists issue \@noitemerr if you add text before the first \item. tasks mimics this by testing if everything between the start of the environment and the first \task is blank (contains only of spaces) or not. If it isn't it issues \@noitemerr. Since a blank line (nearly) always implicitly inserts a \par token and a \par token is not a space you get the error. (IMHO since you don't want to end a paragraph there the empty line is wrong, anyway.) If you want an empty line in your source for whatever reasons then comment it:

\documentclass{article}
\usepackage{tasks,amsmath}

\begin{document}
\settasks{counter-format = tsk/}
\begin{tasks}(2)
%
  \task $f(x)=3x+4$  
  \task $f(x)=2x^4+3x^3-x^2+17$  
  \task $f(x)=\cos(x)\sin(x)$  
  \task $f(x)=\dfrac{4x}{\sqrt{x}}$  
  \task $f(x)=x^2-1$
  \task $f(x)=(x^2-1)\sqrt{x}$
  \task $f(x)=\dfrac{-2}{x+1}$ 
  \task $f(x)=(-x-2)^2$
%
\end{tasks}
\end{document}

BTW: you also don't want the empty line at the end: the newest version of tasks (v0.10a) adds a \strut at the end of an item which starts a new paragraph if the line before it was empty and as a consequence adds vertical space that you don't want.

Another BTW: you really shouldn't write cos(x)sin(x) but \cos(x)\sin(x). Typing $sin(x)$ means »s times i times n times x« (or more likely »s times i times n of x«) while $\sin(x)$ means »sine of x«. Compare the first (wrong) with the second (correct) version:

enter image description here

This prints sin and cos in an upright font (like math operators should be) and also affects the spacing. You'll find a number of questions and answers regarding this topic on TeX.sx.

2
  • 1
    Please, use \cos and \sin, with a note explaining why.
    – egreg
    Aug 1 '14 at 12:40
  • @egreg I didn't notice them, thanks. I added something.
    – cgnieder
    Aug 1 '14 at 12:48
0

You forgot to load amsmath (or better, mathtools), where \dfrac is defined and delete the blank lines:

\documentclass{article}
\usepackage{tasks}
\usepackage{mathtools}

\begin{document}
\settasks{counter-format = tsk/}
\begin{tasks}(2)
\task $f(x)=3x+4$
\task $f(x)=2x^4+3x^3-x^2+17$
\task $f(x)=\cos(x)\sin(x)$
\task $f(x)=\dfrac{4x}{\sqrt{x}}$
\task $f(x)=x^2-1$
\task $f(x)=(x^2-1)\sqrt{x}$
\task $f(x)=\dfrac{-2}{x+1}$
\task $f(x)=(-x-2)^2$
\end{tasks}

\end{document} 

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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