3

I have looked at this solution and while it works for items without labels in my case I have the labeling environment (to be more specific: \begin{labeling}{alligator} ... \end{labelling}) and obviously a labeling list without labels doesn't make much sense.

Currently it looks like this (right part is cut off since it's not related to the issue):

enter image description here

Initially (before I added the Python 3.4 item) it looked okay but then I noticed that due to the length of some of the labels things weren't "looking" as if they had the same alignment especially since my labels are also bold which makes the issue even more visible.

I would like to feed a line break and get the following result:

enter image description here

I've just started learning about defining custom commands (or redefining present ones) and I'm having a tough time figuring out how to do that for the \item[...] command. Adding \mbox{}\\ after every single item is a lot of unnecessary work and even if I didn't have to do it (that is another solution for my problem is present) I would still like to know how to handle such commands.

I have tried

\let\OldItem\item
\renewcommand{\item}[1]{\OldItem[#1]\mbox{}\\}

but it results in a horrible mess (plus it doesn't fix my issue at all):

enter image description here

Any ideas how to do this?

2 Answers2

3

Here's another way to do this using the enumitem package:

\documentclass{article}
\usepackage{enumitem}
\newcommand\lipsum{Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis.}
\begin{document}
\lipsum
\begin{description}[style=nextline,leftmargin=*,labelsep=2em]
\item[C]\lipsum
\item[C++]\lipsum
\item[Python 3.4]\lipsum
\end{description}
\end{document}

output of code

Alan Munn
  • 218,180
2

Your proposed solution almost works, you just have to treat the argument of \item as an optional argument in square brackets. It is probably better not to redefine \item globally but to do it only where needed.

enter image description here

\documentclass{article}
\let\OldItem\item
\newcommand\NewItem[1][]{\OldItem[#1]\mbox{}\\}
\newenvironment{mydescription}%
  {\begin{description}\let\item\NewItem}%
  {\end{description}}
\begin{document}
\begin{mydescription}
\item[C] for evaluation of bla bla bla
\item[C++] the main language for ble ble ble
\item[Pyton 3.4] for data evaluation of blu blu blu
\end{mydescription}
\end{document}
gernot
  • 49,614
  • Works like a charm! Thank you. I didn't think I have to define a whole environment for this. Is there a way to avoid this? (I don't mind using your solution at all) – rbaleksandar Mar 20 '17 at 18:08
  • 1
    @rbaleksandar What exactly is bad in defining a new environment to encapsulate the changes? Alternatively, you can use \let\OldItem\item\renewcommand\item[1][]{\OldItem[#1]\mbox{}\\} in the preamble, but this will affect all lists throughout your document; and \item commands are used in many places. – gernot Mar 20 '17 at 18:12