You are missing \usepackage{calc}
to allow you to use +
in the environment definition.
The environment wants one optional argument and one normal argument, and the first one should be a valid TeX length. The optional argument wants square brackets not braces.
You need to give each \item
an optional label.
If you want the labels in bold sans, then use \textbf{}
rather than \bf
inside the \textsf{}
, as the old commands like \bf
ignore the enclosing font choice.
Try it like this:
\documentclass[10pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{calc}
\newenvironment{alignedDescription}[2][0pt]
{\begin{list}{}%
{\renewcommand\makelabel[1]{\textsf{\textbf{##1}}\hfil}%
\settowidth\labelwidth{\makelabel{#2}}%
\setlength\leftmargin{\labelwidth+\labelsep + #1}}}%
{\end{list}}
\begin{document}
\begin{alignedDescription}[5pt]{Longest label}
\item[Label] A first thing
\item[B] Another thing
\end{alignedDescription}
\end{document}
How does \newenvironment
work?
To define a simple new environment with no arguments in LaTeX we write
\newenvironment{name}{...opening commands...}{...closing commands...}
If we want to pass (up to 9) arguments to the environment we write
\newenvironment{name}[n]{...opening stuff...}{...closing stuff...}
where n
is a number from 1 to 9 and each argument is then available in ...opening stuff...
as #1
, #2
, and so on. So an environment defined as
\newenvironment{foo}[3]{...opening...}{...closing...}
would be called as
\begin{foo}{a}{b}{c}
... foo contents ...
\end{foo}
As an added sophistication, LaTeX allows us to make the first argument optional.
To do this we provide a default value, like this:
\newenvironment{name}[n][default_for_#1]{...opening...}{...closing...}
So an environment defined as
\newenvironment{bar}[3][3.1415]{...open...}{...close...}
could be called as
\begin{bar}{b}{c}
... contents of bar with #1=3.1415 ...
\end{bar}
or as
\begin{bar}[2.718]{b}{c}
... contents of bar with #1=2.718 ...
\end{bar}
Notice that the optional first argument must be in [brackets] if it is present.
What happened in the original problem was that the defined environment wanted 2 arguments and the first one was optional, but the OP gave two arguments both in {braces}; so TeX used the default value for the first argument, the first {brace} as the second argument and treated the second {brace} as part of the content of the environment. Since the environment was a list, the contents were supposed to start with an \item
, which is why the OP got a "missing item" error.
I can recommend The Latex Companion as a reference for this sort of thing.
\bf
, please read Does it matter if I use\textit
or\it
,\bfseries
or\bf
, etc. and Will two-letter font style commands (\bf
,\it
, …) ever be resurrected in LaTeX? – Werner Jan 27 '14 at 20:13