Align list ignoring negative sign of the first number in items
What i do is to redefine \item
inside the environment to examine the first token of \item
(following an optional argument). If it is a -
token, I \mathllap
it and then continue, else I just typeset it directly.
\documentclass{article}
\usepackage{enumitem,mathtools}
\let\svitem\item
\newenvironment{alternativas}[1][0]
{
\renewcommand\item[2][\relax]{%
\ifx\relax##1\def\next{}\else\def\next{[##1]}\fi
\ifx-##2\def\nnext{$\mathllap{##2}$}\else\def\nnext{##2}\fi
\expandafter\svitem\next\nnext}
\begin{enumerate}[label={\Alph*)}, itemsep=#1cm, topsep = 0.5cm,
wide=0pt, labelwidth=.5cm,leftmargin=!,labelsep=10pt]
}
{
\end{enumerate}
}
\begin{document}
\begin{alternativas}
\item -1
\item 4
\item -5
\item 6
\end{alternativas}
\end{document}
ADDENDUM
OP clarified in comments that all numbers are entered in math mode (via leading $
). However, not all items begin with math. So, some revisions were required:
\documentclass{article}
\usepackage{enumitem,mathtools}
\let\svitem\item
\newenvironment{alternativas}[1][0]
{
\renewcommand\item[3][\relax]{%
\ifx\relax##1\def\next{}\else\def\next{[##1]}\fi
\ifx$##2\ifx-##3\def\nnext{##2\mathllap{##3}}\else\def\nnext{##2##3}\fi
\else\def\nnext{##2##3}\fi
\expandafter\svitem\next\nnext}
\begin{enumerate}[label={\Alph*)}, itemsep=#1cm, topsep = 0.5cm,
wide=0pt, labelwidth=.5cm,leftmargin=!,labelsep=10pt]
}
{
\end{enumerate}
}
\begin{document}
\begin{alternativas}
\item $-1$
\item $4$
\item $-\frac{5}{7}$
\item $\frac{6}{11}$
\item text
\end{alternativas}
\end{document}
You can load mathtools
(needless to load amsmath
in this case) to use its \mathllap
command and slightly increase \labelsep
:
\documentclass{article}
\usepackage{enumitem}
\usepackage{mathtools}
\newenvironment{alternativas}[1][0]
{
\begin{enumerate}[label={\Alph*)}, itemsep=#1cm, topsep = 0.5cm, labelsep=6pt, wide=0pt,labelwidth=.5cm,leftmargin=!]
}
{
\end{enumerate}
}
\begin{document}
\begin{alternativas}
\item $\mathllap{-}1 $
\item $ 4 $
\item $ \mathllap{-}5 $
\item $ 6 $
\end{alternativas}
\end{document}