How can a list be created, whose items are both
- enumerated (a,b,c,d,...)
- and allow for setting a description via
\item[texthere]
?
Im am using MikTex on Windows.
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityEDIT
Comment of Ben:
Could I also have a separate listclass, say enumdescript, such that I don't have to apply the settings manually everytime I want to use one of those lists?
The package enumitem
provides a simple way to define you own list environments. The command \newlist
in combination with setlist
are the relavant commands. With \newlist
you can define you own list and via \setlist
set the settings. In the following example I define the environment enumdescript
with the depth 2. Both commands are well explained in the documentation.
\documentclass{scrbook}
\usepackage{enumitem}
\newcounter{descriptcount}
\newlist{enumdescript}{description}{2}
\setlist[enumdescript,1]{%
before={\setcounter{descriptcount}{0}%
\renewcommand*\thedescriptcount{\alph{descriptcount}}}
,font=\bfseries\stepcounter{descriptcount}\thedescriptcount~
}
\setlist[enumdescript,2]{%
before={\setcounter{descriptcount}{0}%
\renewcommand*\thedescriptcount{\roman{descriptcount}}}
,font=\bfseries\stepcounter{descriptcount}\thedescriptcount~
}
\begin{document}
\begin{enumdescript}
\item item one
\item item two
\item[Some Text] item three
\begin{enumdescript}
\item item one
\item item two
\item[Some Text] item three
\end{enumdescript}
\item item four
\item item five
\end{enumdescript}
\end{document}
ORIGNIAL Answer:
Use the package enumitem
in the newest version:
\documentclass{scrbook}
\usepackage{enumitem}
\newcounter{descriptcount}
\renewcommand*\thedescriptcount{\alph{descriptcount}}
\begin{document}
\begin{description}[%
before={\setcounter{descriptcount}{0}},%
,font=\bfseries\stepcounter{descriptcount}\thedescriptcount~]
\item item one
\item item two
\item[Some Text] item three
\end{description}
\end{document}
This is actually an enhancement of Marco Daniel’s answer and slightly off-topic with regard to the question. But I think, it still fits better here than elsewhere.
For a FAQ-list I needed an enumerated description list, where I could refer to the items, so I’ve added some things:
I’ve added more custom counters (I needed 4) and redefined them
\newcounter{enumdesci}
\newcounter{enumdescii}[enumdesci] % note the optional reset value
\newcounter{enumdesciii}[enumdescii]
\newcounter{enumdesciv}[enumdesciii]
%
\renewcommand*{\theenumdesci}{\Roman{enumdesci}} % the default is "\arabic{enumdesci}"
\renewcommand*{\theenumdescii}{\theenumdesci.\Alph{enumdescii}}
\renewcommand*{\theenumdesciii}{\theenumdescii.\arabic{enumdesciii}}
\renewcommand*{\theenumdesciv}{\theenumdesciii.\alph{enumdesciv}}
I use four different representations for the counters here just for illustration.
If you need a period also after the last counter, take care where to add it (and where to remove in comparison to the version above; in my eyes the first variant above is better, the enddot could also be added in enumdescript
definition below):
\renewcommand*{\theenumdesci}{\Roman{enumdesci}.}
\renewcommand*{\theenumdescii}{\theenumdesci\Alph{enumdescii}.}
\renewcommand*{\theenumdesciii}{\theenumdescii\arabic{enumdesciii}.}
\renewcommand*{\theenumdesciv}{\theenumdesciii\alph{enumdesciv}.}
Once defined I found this useful also for other lists, but now hyperref
complained, that the counters were not unique (cf. hyperref
documentation, as e.g. cited by mafp), so I had to add some lines straight after the others:
% for "hyperref", not needed without this or for a single list:
\newcounter{enumdesc}
\newcommand*{\theHenumdesci}{\theenumdesc\theenumdesci}
\newcommand*{\theHenumdescii}{\theenumdesc\theenumdescii}
\newcommand*{\theHenumdesciii}{\theenumdesc\theenumdesciii}
\newcommand*{\theHenumdesciv}{\theenumdesc\theenumdesciv}
Now the part more or less adapted from Marco’s answer – defining a new list (here enumdescript
) and setting the levels. Remember, I said, I needed 4.
\newlist{enumdescript}{description}{4}
%for a single list (without "hyperref" the "\phantomsection"s must be removed, too):
\setlist[enumdescript,1]{before={\setcounter{enumdesci}{0}},style=nextline,leftmargin=0pt,topsep=0.5\baselineskip,%
font={\phantomsection\normalfont\normalsize\bfseries\refstepcounter{enumdesci}\theenumdesci~}}
\setlist[enumdescript,2]{style=nextline,leftmargin=0.75em,labelindent=0.75em,topsep=0.5\baselineskip,%
font={\phantomsection\normalfont\normalsize\bfseries\refstepcounter{enumdescii}\theenumdescii~}}
\setlist[enumdescript,3]{style=nextline,leftmargin=1.5em,labelindent=1.5em,topsep=0.5\baselineskip,%
font={\phantomsection\normalfont\normalsize\bfseries\refstepcounter{enumdesciii}\theenumdesciii~}}
\setlist[enumdescript,4]{style=nextline,leftmargin=2.25em,labelindent=2.25em,topsep=0.5\baselineskip,%
font={\phantomsection\normalfont\normalsize\bfseries\refstepcounter{enumdesciv}\theenumdesciv~}}
Note the before={\setcounter{enumdesci}{0}}
in the first level, which resets the counters, if you start a new list. I’ve also added some \phantomsection
s from the package “hyperref” and replaced \stepcounter
s for the possibility of referencing with \refstepcounter
s. The margins and labelindents should be adjusted according to the wanted indentation and used font. The style nextline
could be changed for shorter items, see the “enumitem” documentation for that.
With hyperref
and more than one list a command for increasing of the counter enumdesc
must be added. This is best done in the before
key of the first level definition. So this becomes
%for more than one list and "hyperref":
\setlist[enumdescript,1]{before={\stepcounter{enumdesc}\setcounter{enumdesci}{0}},%
style=nextline,leftmargin=0pt,topsep=0.5\baselineskip,%
font={\phantomsection\normalfont\normalsize\bfseries\refstepcounter{enumdesci}\theenumdesci~}}
For the internal “TOC” or overview (the FAQ is part of a bigger document) I defined an additional list with a new command:
\newlist{edtoclist}{itemize}{4}
\setlist[edtoclist,1]{label=\hspace*{1.25em},labelwidth=*,leftmargin=*}
\setlist[edtoclist,2]{label=\hspace*{1.3em},labelwidth=*,leftmargin=*}
\setlist[edtoclist,3]{label=\hspace*{2.1em},labelwidth=*,leftmargin=*}
\setlist[edtoclist,4]{label=\hspace*{3.0em},labelwidth=*,leftmargin=*}
\newcommand*{\edtitem}[2]{\item[\ref{#1}] \hyperref[#1]{#2}}
It must be 4 levels here also, of course. \hspace*
needs manual adjustment depending on the font, your counter definition and the actual level depth. For the whole list one must take care of manually adjusting the levels according to the enumdescript
levels. Also the items have to copied by hand.
All together (only 3 list levels used here):
\documentclass{article}
\usepackage[ngerman,english]{babel} % needed for "blindtext",
% "english" is the active language
\usepackage [pangram,random]{blindtext} % for some filler text
\usepackage{lipsum,kantlipsum} % also for filler text
\usepackage{enumitem}
\usepackage[%
colorlinks=true,%
linkcolor=blue,%
]{hyperref}
%-----------------------%
% Further settings for "enumitem"
%-----------------------%
% Custom counters:
\newcounter{enumdesci}
\newcounter{enumdescii}[enumdesci]
\newcounter{enumdesciii}[enumdescii]
\newcounter{enumdesciv}[enumdesciii]
% Redefinition:
\renewcommand*{\theenumdesci}{\Roman{enumdesci}}
\renewcommand*{\theenumdescii}{\theenumdesci.\Alph{enumdescii}}
\renewcommand*{\theenumdesciii}{\theenumdescii.\arabic{enumdesciii}}
\renewcommand*{\theenumdesciv}{\theenumdesciii.\alph{enumdesciv}}
% For "hyperref":
\newcounter{enumdesc}
\newcommand*{\theHenumdesci}{\theenumdesc\theenumdesci}
\newcommand*{\theHenumdescii}{\theenumdesc\theenumdescii}
\newcommand*{\theHenumdesciii}{\theenumdesc\theenumdesciii}
\newcommand*{\theHenumdesciv}{\theenumdesc\theenumdesciv}
%
\newlist{enumdescript}{description}{4}
\setlist[enumdescript,1]{before={\stepcounter{enumdesc}\setcounter{enumdesci}{0}},style=nextline,leftmargin=0pt,%
font={\phantomsection\normalfont\normalsize\bfseries\refstepcounter{enumdesci}\theenumdesci~}}
\setlist[enumdescript,2]{style=nextline,leftmargin=0.75em,labelindent=0.75em,%
font={\phantomsection\normalfont\normalsize\bfseries\refstepcounter{enumdescii}\theenumdescii~}}
\setlist[enumdescript,3]{style=nextline,leftmargin=1.5em,labelindent=1.5em,%
font={\phantomsection\normalfont\normalsize\bfseries\refstepcounter{enumdesciii}\theenumdesciii~}}
\setlist[enumdescript,4]{style=nextline,leftmargin=2.25em,labelindent=2.25em,%
font={\phantomsection\normalfont\normalsize\bfseries\refstepcounter{enumdesciv}\theenumdesciv~}}
%-----------------------%
% Definition of a new list for own "TOC":
\newlist{edtoclist}{itemize}{4}
\setlist[edtoclist,1]{label=\hspace*{1.1em},labelwidth=*,leftmargin=*}
\setlist[edtoclist,2]{label=\hspace*{1.37em},labelwidth=*,leftmargin=*}
\setlist[edtoclist,3]{label=\hspace*{2.16em},labelwidth=*,leftmargin=*}
\setlist[edtoclist,4]{label=\hspace*{2.94em},labelwidth=*,leftmargin=*}
\newcommand*{\edtitem}[2]{\item[\ref{#1}] \hyperref[#1]{#2}}
%-----------------------%
\begin{document}
\section*{Overview}
% first level
\begin{edtoclist}
\edtitem{bltxt-xmpl}{``blindtext'' examples}
% second level
\begin{edtoclist}
\edtitem{bltxt-xmplen}{English}
% third level
\begin{edtoclist}
\edtitem{bltxt-xmplen1}{Example~1}
\edtitem{bltxt-xmplen2}{Example~2}
\end{edtoclist}
% second level
\edtitem{bltxt-xmplde}{German}
% third level
\begin{edtoclist}
\edtitem{bltxt-xmplde1}{Beispiel~1}
\edtitem{bltxt-xmplde2}{Beispiel~2}
\end{edtoclist}
\end{edtoclist}
% first level
\edtitem{lkl-xmpl}{``lipsum'' and derived ``kantlipsum''}
% second level
\begin{edtoclist}
\edtitem{lips-xmpl}{``lipsum'' examples}
% third level
\begin{edtoclist}
\edtitem{lips-xmpl10}{Tenth section}
\edtitem{lips-xmpl20}{Twentieth section}
\end{edtoclist}
% second level
\edtitem{klips-xmpl}{``kantlipsum'' examples}
% third level
\begin{edtoclist}
\edtitem{klips-xmpl15}{Fifteenth section}
\edtitem{klips-xmpl30}{Thirtieth section}
\end{edtoclist}
\end{edtoclist}
\end{edtoclist}
%\newpage
\section*{Examples}
% first level
\begin{enumdescript}
\item[``blindtext'' examples\label{bltxt-xmpl}]
~\\[-2\baselineskip]
% second level
\begin{enumdescript}
\item[English\label{bltxt-xmplen}]
~\\[-2\baselineskip]
% third level
\begin{enumdescript}
\item[Example~1:\label{bltxt-xmplen1}]
\blindtext[1]
\item[Example~2:\label{bltxt-xmplen2}]
\blindtext[1]
\end{enumdescript}
% second level
\item[German\label{bltxt-xmplde}]
~\selectlanguage{ngerman}\\[-2\baselineskip]
% third level
\begin{enumdescript}
\item[Beispiel~1:\label{bltxt-xmplde1}]
\blindtext[1]
\item[Beispiel~2:\label{bltxt-xmplde2}]
\blindtext[1]
\end{enumdescript}
\selectlanguage{english}
\end{enumdescript}
% first level
\item[``lipsum'' and derived ``kantlipsum''\label{lkl-xmpl}]
~\\[-2\baselineskip]
% second level
\begin{enumdescript}
\item[``lipsum'' examples\label{lips-xmpl}]
~\\[-2\baselineskip]
% third level
\begin{enumdescript}
\item[Tenth section\label{lips-xmpl10}]
\lipsum[10]
\item[Twentieth section\label{lips-xmpl20}]
\lipsum[20]
\end{enumdescript}
% second level
\item[``kantlipsum'' examples\label{klips-xmpl}]
~\\[-2\baselineskip]
% third level
\begin{enumdescript}
\item[Fifteenth section\label{klips-xmpl15}]
\kant[15]
\item[Thirtieth section\label{klips-xmpl30}]
\kant[30]
\end{enumdescript}
\end{enumdescript}
\end{enumdescript}
\end{document}
You can use the enumerate
package for this:
\documentclass{scrbook}
\usepackage{enumerate}
\begin{document}
\begin{enumerate}[a)]
\item item one
\item item two
\end{enumerate}
\end{document}
Another alternative to Raphink method is such:
You can make use of the itemize
environment like the following:
\documentclass{article}
\begin{document}
\begin{itemize}
\item[a]
\item[b)]
\item[(c)]
\item[d.]
\end{itemize}
\end{document}
Producing the following output:
Notice how you are able to created different styles for your list of items using thing such as: )
, ( )
, .
simultaneously if preferred for some reason.
Hope this was helpful to know.
(a)
and 'b' be b)
and maybe 'c' being (c)
. Just one example. Instead of them all being the same like: a)
, b)
, c)
vertically and so on.
Oct 1, 2011 at 23:10
\item[text here]
which was desired.
Oct 1, 2011 at 23:18
Using the enumitem
package it is possible to extend the enumerate
environment in order to have a description like feature.
In comparison to the opposite approach of extending the description
environment the new enumdescript
can take optional label formatting commands.
\documentclass{article}
\usepackage{enumitem}
\makeatletter
\newlist{enum@descript}{enumerate}{1}
\setlist[enum@descript]{label=\arabic*.}
\newenvironment{enumdescript}[1][]{
\begin{enum@descript}[#1]
\let\old@item\item
\renewcommand{\item}[1][]{
\old@item\ifx&##1&\else\textbf{##1}~\fi
\@ifnextchar\par\@gobble\relax
}
}{\end{enum@descript}}
\makeatother
\begin{document}
\begin{enumdescript}[label=\roman*)]
\item[first]\label{one}Text
\item [second] \label{two} Text
\item
[third]
\label{three} Text
\end{enumdescript}
\begin{enumdescript}[label=\{\alph*\}]
\item\label{four}Text
\item \label{five} Text
\item
\label{six} Text
\end{enumdescript}
Items \ref{one}, \ref{two}, \ref{three}, \ref{four}, \ref{five}, and \ref{six}.
\end{document}
I have not implemented list nesting.
item[]
command, rather than defining a new command\litem{}
as Mike did. Hence the enumitem package can still be used straightforwardly for formatting the list without having to ask yourself: What didlitem{}
do again...