TransWikia.com

Applying different formatting to different description lists

TeX - LaTeX Asked by Chris Kern on October 23, 2020

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.

One Answer

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=mdseriesscshape,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=mdseriesscshape]
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=mdseriesscshape,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

Correct answer by campa on October 23, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP