# Center Aligning Labels in a enumerate environment

I am trying to get enumerate environment do the following:

     (subgroup)   some description of a subgroup of a group G.
(hello!)    This subgroup is a hello subgroup of G and satisfies an
awkward  condition that it does not occur often!
(long enough) It also satisfies long enough condition so that it is not trivial!


Based on the answer of Peter Grill and the ensuing discussion here, I came up with the following code:

\documentclass{article}
\usepackage{enumitem}
\SetLabelAlign{Center}{\makebox[1em]{(#1)}}
\begin{document}
\begin{enumerate}[align=Center]
\item[subgroup] Some description of a subgroup of a group $G$.
\item[hello!] This subgroup is a hello subgroup of G and satisfies an awkward  condition that it does not occur often!
\item[long enough] It also satisfies long enough condition so that it is not trivial!
\end{enumerate}
\end{document}


This leaves me with:

I'd be glad if somebody can help me fix this code!

Edit Playing around a little bit, I figure that increasing the \makebox width(?), I could get it to write things without overlapping. But, this breaks alignment. Could someone please explain this?

-
Not sure this is what you're looking for, but increasing the width of your box to, say, 6em stops the overlapping. – Jonathan Aug 1 '13 at 19:44
@Jonathan Yes, I just figured that out and even edited to add it! – kan Aug 1 '13 at 19:45

I would use a description list here instead of misusing itemize. In order for this to work you need to specify the longest label you will have. You need to have enumitem calculate the left margin for you, using leftmargin=!.

\documentclass{article}
\usepackage{enumitem}
\usepackage{calc}
\newlength{\mylongest}
\setlength{\mylongest}{\widthof{The longest label I will need}}
\SetLabelAlign{CenterWithParen}{\makebox[\mylongest]{(#1)}}
\begin{document}
\begin{description}[style=unboxed,align=CenterWithParen,labelwidth=\mylongest,leftmargin=!]
\item[Foo]{This is a foo item}
\item[FooBar]{This is a foobar item}
\item[A longer description]{A longer label}
\end{description}
\end{document}


-
One can use environ and \NewEnviron in order to avoid guessing the widest label. There's no need to load calc, because \settowidth{\mylongest}{<text>} is defined in the kernel. – egreg Aug 1 '13 at 20:55

One can use environ and so avoid guessing at the widest label.

\documentclass{article}
\usepackage{enumitem}
\usepackage{environ}
\newlength{\cdescwidth}
\SetLabelAlign{CenterWithParen}{\makebox[\cdescwidth]{\normalfont(#1)}}

\NewEnviron{cdesc}{%
\setbox0=\vbox{% measure the label widths
\global\cdescwidth=0pt
\def\item[##1]{%
\settowidth{\dimen0}{(##1)}%
\ifdim\dimen0>\cdescwidth
\global\cdescwidth=\dimen0
\fi}
\BODY}
% set the label width
\begin{description}[
font=\normalfont,
style=unboxed,
align=CenterWithParen,
labelwidth=\cdescwidth,
leftmargin=!
]
% typeset the contents
\BODY
\end{description}
}

\begin{document}
\begin{cdesc}
\item[Foo] This is a foo item
\item[FooBar] This is a foobar item
\item[A longer description] A longer label
\end{cdesc}
\end{document}


-