2

Here is MWE.

\documentclass[a4paper,10pt]{article}
\begin{document}

\begin{description} \item{Foo\ Bar \ Baz } : Foo, Bar and Baz are friends. \item a, b, c \end{description}

\end{document}

It produces this:

enter image description here

Linebreaks are working fine but Foo, Bar and Baz are not aligning to the left. Is there a way to fix this? I rather redefine the description environment rather than change the text inside item{} everywhere in my current doc which has many descriptions.

Dilawar
  • 992

1 Answers1

5

Two observations. First, in LaTeX's description environment, the argument of \item should be encased in square brackets, not curly braces. Second, to place several items in the argument of \item [pun intended] in a vertical stack, you could use a tabular environment. The following example code provides short-hand macro called \mystack that simplifies the creation of a stack of items.

enter image description here

\documentclass{article}
\newcommand\mystack[1]{\begin{tabular}[t]{@{}l@{}} #1 \end{tabular}}
\begin{document}
\begin{description}
    \item[\mystack{Foo \\ Bar \\ Baz}]: Foo, Bar, and Baz are friends.
    \item[a, b, c] \dots
\end{description}
\end{document}
Mico
  • 506,678
  • Thank @Mico. This is helpful. Is there a way to do this by redefining the \item? I rather add a redefinition at the top rather than change the doc at hundreds of places. – Dilawar Jun 10 '21 at 21:26
  • Currently I am using https://tex.stackexchange.com/a/230309/8087 i.e., \usepackage{enumitem} \setlist[description]{style=nextline}. – Dilawar Jun 10 '21 at 21:28
  • @Dilawar -- If I understand your document setup correctly, you have to input \item[, Foo \\ Bar \\ Baz -- I trust you don't literally work with these exact words in your real document ... -- and ] by hand. Is it really that much more work to enter \mystack{ and } as well? If it really is too burdensome to do so, please edit your posting and provide a more realistic example of stacked words, to give your readers a better sense of what exactly needs to (and what does not need to) be accomplished.. – Mico Jun 10 '21 at 21:34
  • Ah, sorry about that @Mico. The document I am dealing with is a large manual that needs to be converted to rst/markdown. Currently, the doc has \item{\texttt{foo}\n \texttt{bar}\n \texttt{baz}\n} etc and a very complicated redefinition of \texttt and \item which I have to remove else pandoc couldn't work. When I remove some complicated macros the alignment breaks. I can write a plugin for pandoc which can insert some macros/redefinitions at the top of the doc before converting. Another option is to use gawk/sed/regex which I am trying to avoid. Thanks for your time. – Dilawar Jun 10 '21 at 21:49