2

I'm using description lists for several different purposes in something I'm writing. I would like to somehow define these lists differently so that I could apply different formatting or style to the different types. In HTML/CSS I would use the "class" attribute to do this. Is there something similar that can be done in LaTeX? The only thing I could think of was to make sort of a wrapper \NewDocumentCommand or environment that would get the list passed to it as an argument.

EDIT:I meant the description environment. So sometimes I might want the descriptions on the same line as the items, other times offset on the next line. I know how to do this, but I don't want to have to do it individually for each list. The project may have as many as 240 description lists of three different types.

I wanted to keep things flexible in case I had different ideas, but maybe I'm applying too much of an HTML/CSS mindset -- there I would use class attributes even if I had no specific plans to style things differently, just in case I wanted to do it later.

3
  • 1
    By "description" do you mean that you are really using the description environment?
    – campa
    Aug 7, 2020 at 14:50
  • Could you include some examples of the different styles you have in mind. If you are referring to the description environment, you might want to have a look at the enumitem package and its various list customization options.
    – leandriis
    Aug 7, 2020 at 14:53
  • Yes, let me edit the original post.
    – Chris Kern
    Aug 7, 2020 at 14:56

1 Answer 1

4

The package enumitem offers the possibility of adapting the description environment and to define custom lists, e.g.

\documentclass{article}

\usepackage{enumitem}

% Define small caps description-like environment
\newlist{scdesc}{description}{1}
\setlist[scdesc]{font=\mdseries\scshape,noitemsep}

\begin{document}

\begin{description}
\item[Foo] explanation for foo
\item[Bar] explanation for baz
\item[Baz] explanation for baz
\end{description}

\begin{description}[font=\slshape]
\item[Foo] explanation for foo
\item[Bar] explanation for baz
\item[Baz] explanation for baz
\end{description}

\begin{description}[font=\mdseries\scshape]
\item[Foo] explanation for foo
\item[Bar] explanation for baz
\item[Baz] explanation for baz
\end{description}

\begin{scdesc}
\item[Foo] explanation for foo
\item[Bar] explanation for baz
\item[Baz] explanation for baz
\end{scdesc}

\end{document}

enter image description here


EDIT With the macro \SetEnumitemKey you can define a shorthand for a (more or less arbitrary) list of keys:

\documentclass{article}

\usepackage{enumitem}
\SetEnumitemKey{myclassA}{font=\slshape,noitemsep}
\SetEnumitemKey{myclassB}{font=\mdseries\scshape,noitemsep}

\begin{document}

\begin{description}[myclassA]
\item[Foo] explanation for foo
\item[Bar] explanation for bar
\item[Baz] explanation for baz
\end{description}

\begin{description}[myclassB]
\item[Foo] explanation for foo
\item[Bar] explanation for bar
\item[Baz] explanation for baz
\end{description}

\end{document}

enter image description here

9
  • 2
    @ChrisKern Well, you just define three types of description with \newlist like I did with the scdesc in the example.
    – campa
    Aug 7, 2020 at 15:04
  • 1
    @ChrisKern Are you saying you would like to have a \begin{description}[myclass] type of solution?
    – ivankokan
    Aug 18, 2020 at 9:58
  • 1
    That sounds promising.
    – Chris Kern
    Aug 19, 2020 at 13:26
  • 2
    @ChrisKern See edit.
    – campa
    Aug 19, 2020 at 13:36
  • 1
    Thank you! I appreciate it.
    – Chris Kern
    Aug 19, 2020 at 15:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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