3

I have to list the hardware of a computer, and I'd like to use the description environment from the enumitem package.

I have several problems of alignment as you can see on the picture.

I want the labels to be on the left margin (as they actually are), and the content to be aligned with the longest element. The last thing I want is to have the \\ command setting the text on the same alignment (600 GB aligned with the 160 GB)

Here is a MWE :

\documentclass{article}
\usepackage[english]{babel}
\usepackage{lipsum} % for dummy text only
\usepackage{enumitem}
\usepackage{calc}
\usepackage[locale = FR, binary-units, abbreviations,per-mode=symbol]{siunitx}


\begin{document}
\lipsum[1]

    \begin{description}[labelwidth=\widthof{Connectivity},
        leftmargin=\widthof{Connectivity},align=left]%2.9cm
    \item[Processor] Intel Xeon i7 64 bits 16 cœurs @\SI{2.9}{\giga\hertz}
    \item[Memory] \SI{64}{\giga\byte} RAM DDR3 @\SI{1600}{\mega\hertz}
    \item[Storage] \SI{160}{\giga\byte} : partition \texttt{boot}\\ \SI{600}{\giga\byte} : partition \texttt{home}
    \item[Connectivity] 3xUSB 3.0
    \item[Internet] 2xGigabit Ethernet
\end{description}


\lipsum[1]

\end{document}

I tried setting the \labelwidth of the longest word (Connectivity), but it fails because

  • Content is not aligned: 3xUSB is not in the same vertical as the rest(Intel)
  • The second line of Storage doesn't start at the same point as the first line

MWE Result

Any ideas on how to solve this problem ?

  • 2
    For the width problem, you can try \widthof{\textbf{Connectivity}} since the word connectivity is in bold and has a bigger width than non-bold connectivity – AJN Apr 26 '16 at 8:32
4

Since the left hand column of the description is in bold letters, you have to calculate the the width based on bold letters. Trying \widthof{\textbf{Connectivity}} solves that problem.

As for the insufficient indenting when multiple lines are present, they seem to be about one n space and so I gave a dummy character n or y to the argument of the second widthof command and it seems to work. This may not be the right way to solve the second problem though.

\documentclass{article}
\usepackage[english]{babel}
\usepackage{lipsum} % for dummy text only
\usepackage{enumitem}
\usepackage{calc}
\usepackage[locale = FR, binary-units, abbreviations,per-mode=symbol]{siunitx}


\begin{document}
\lipsum[1]

    \begin{description}[labelwidth=\widthof{\textbf{Connectivity}},
        leftmargin=\widthof{\textbf{Connectivityy}},align=left]%2.9cm
    \item[Processor] Intel Xeon i7 64 bits 16 cœurs @\SI{2.9}{\giga\hertz} \lipsum[1]
    \item[Memory] \SI{64}{\giga\byte} RAM DDR3 @\SI{1600}{\mega\hertz}
    \item[Storage] \SI{160}{\giga\byte} : partition \texttt{boot}\\ \SI{600}{\giga\byte} : partition \texttt{home}
    \item[Connectivity] 3xUSB 3.0
    \item[Internet] 2xGigabit Ethernet
\end{description}

\end{document}

widthof and description commands

  • Yeah, it seems to work perfectly. I have another \description with other labels, and it does the trick :) – EisenHeim Apr 26 '16 at 8:50
  • I'm not quite understanding what you mean by "gave a dummy character" as I can't see it in your example. I don't have any labels that are longer than the standard indent but the first line starts before the rest of the paragraph. – Kajsa Feb 11 at 11:29
  • 1
    There is an additional 'y' in \widthof{\textbf{Connectivityy}} – AJN Feb 11 at 13:38

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.