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?

6
  • 1
    Can you add a MWE? Mar 20 '17 at 16:29
  • 1
    Could you provide a complete, minimal example of your setup? Specific to \letting commands that have optional arguments. See When to use \LetLtxMacro?
    – Werner
    Mar 20 '17 at 16:33
  • 1
    You might like enumitem. In particular look for the nextline style in the docs.
    – Thruston
    Mar 20 '17 at 16:37
  • May the answers to tex.stackexchange.com/questions/359306/… can help.
    – Fran
    Mar 20 '17 at 17:34
  • @moewe You are right. It's not a duplicate. Answer from gernot fits perfectly although I would prefer not to create a custom environment (which I'm completely not familiar with). Mar 20 '17 at 18:10
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}
2
  • 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) 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
2

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

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