3

I'd like to make a timeline with a description environment.

If I use the following:

\documentclass{article}
\usepackage{enumitem}

\begin{document}

\begin{description}[leftmargin=*,label=0000]
\item[1987]Something really exciting happened in that year, but I’m not sure exactly what.
\item[1990]Bar
\end{description}

\end{document}

I get an error:

ERROR: Missing control sequence inserted.

--- TeX said ---
<inserted text> 
\inaccessible 
l.7 \begin{description}[leftmargin=*]

It seems that label=0000 doesn't work for description environments?

If I simply put leftmargin=2.8em (for this particular case), then I get what I want: the second line of the first item lines up with the first line:

What I'd like to get

But obviously I'd prefer to achieve this by giving the label to be measured dynamically.

8

Here are two ways:

\documentclass{article}
\usepackage{enumitem}
\usepackage{calc}

\begin{document}

\begin{description}[labelwidth =\widthof{\bfseries9999}, leftmargin = !]
\item[1987]Something really exciting happened in that year, but I’m not sure exactly what.
\item[1990]Bar
\end{description}
\bigskip

\begin{enumerate}[wide = 0pt, widest = {\bfseries9999}, leftmargin =*, font = \bfseries]
\item[1987]Something really exciting happened in that year, but I’m not sure exactly what.
\item[1990]Bar
\end{enumerate}

\end{document} 

enter image description here

| improve this answer | |
  • This is great; it works and measures the argument as desired. I'd like to understand better what's going on if possible. First, I think it can be simpler: \begin{description}[noitemsep,labelwidth=widthof{\bfseries9999},leftmargin=!] seems to work. Secondly, any clue why setting labelwidth works but setting label gives an error? Is it a bug in enumitem? – Reuben Thomas Nov 21 '17 at 21:15
  • Thanks for your remark. You're right: leftmargin=! works (and it is indeed simpler). I thought I has tried it , but it didn't work for some reason. As I tested several other possibilities, I probably forgot this one. I've modified the code. For your second question, I don't quite understand what you mean with ‘setting label’, for a description environment? – Bernard Nov 21 '17 at 21:24
  • Answer accepted, thanks. I mean, why does setting label=0000 in the optional parameter to \begin{description}, as I did in my question, give an error? – Reuben Thomas Nov 21 '17 at 21:25
  • Probably because there can be no more or less standard pre-defined label for a description environment as there is for enumerate or itemize. I even tried widest= (which can be a string), but it doesn't work either. – Bernard Nov 21 '17 at 21:29
5

You can use labeling:

\documentclass{article}
\usepackage{scrextend}
\setkomafont{labelinglabel}{\bfseries}

\begin{document}

\begin{labeling}{9999}
\item[1987]Something really exciting happened in that year, but I’m not sure exactly what.
\item[1990]Bar
\end{labeling}

\end{document}

result using scrextend

If you already use a KOMA-Script class, you can and should omit package scrextend:

\documentclass{scrartcl}
\setkomafont{labelinglabel}{\bfseries}

\begin{document}

\begin{labeling}{9999}
\item[1987]Something really exciting happened in that year, but I’m not sure exactly what.
\item[1990]Bar
\end{labeling}

\end{document}

result using KOMA-Script class

| improve this answer | |
  • Thanks very much for this; this looks like a decent answer, but I'm going to prefer the one that uses enumitem which I'm already using (and I'm not using KOMA-Script for this document; maybe II should be!). – Reuben Thomas Nov 21 '17 at 21:12
  • Thanks for the reminder; I've upvoted both answers, as they're both good! – Reuben Thomas Nov 22 '17 at 13:09

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.