4

I kinda succeeded in doing with without using the enumitem package, by doing this: (disregard the lines, it's made with showframe)

\newenvironment*{keywordlist}{%
    \list{}{%
        \setlength{\labelwidth}{\marginparwidth}%
        \setlength{\labelsep}{\marglistsep}%
        \setlength{\leftmargin}{0pt}%
        \renewcommand*{\makelabel}[1]{\hss\marglistfont##1}%
    }%
}{%
    \endlist%
}

enter image description here

This works like a description environment, but the labels are moved to the margin. The labels also align to the right, i.e. the text body, separated by \marglistsep. the long label in the middle shows what should happen if the label is too long to fit entirely in the margin.

Now, I tried doing this with the function set provided by enumitem, but I got only this far:

\newlist{keywordlist}{description}{1}
\setlist[keywordlist]{style=multiline, labelsep=5pt, leftmargin=0pt, labelindent=-\marginparwidth}

enter image description here

This will put the labels into the margin, but I pretty much lost the separator value, and all labels are aligned to the left border, which puts a huge gap between the label and the text body. Which doesn't look too good. I like that I can make this label span multiple lines, which is why I'd like to use that over my first approach.

In essence, I'd kinda like to have best of both worlds, so the labels are aligned to the text body, could span multiple lines, but if one of those lines gets too long, it'll push the body contents inward.

1
  • Did you try with align=right? And please post a complete minimal document people can work with. That is much more useful than mere code fragments.
    – cfr
    Jul 25, 2014 at 0:08

1 Answer 1

3

You can try with align key of enumitem and define your own align key:

 \SetLabelAlign{myright}{strut\smash{\parbox[t]{\labelwidth}{\raggedleft#1}}}

and use it as align=myright.

\documentclass{article}
\usepackage{enumitem,showframe}
\SetLabelAlign{myright}{strut\smash{\parbox[t]{\labelwidth}{\raggedleft#1}}}
\newlist{keywordlist}{description}{1}
\setlist[keywordlist]{style=multiline, labelsep=5pt, leftmargin=0pt,align=myright,
           labelindent=-\marginparwidth}
\begin{document}
 \begin{keywordlist}
 \item[yow] So this is some thing
 \item[This is very long item] This is one kind. This is one kind. This is one kind. This is one kind. This is one kind. This is one kind. This is one kind.
 \item[abcde] This is another kind.
 \end{keywordlist}
\end{document}

enter image description here

But note that if the item label is longer and the description is shorter, you will have the overlapping of the items.

4
  • Any ideas how I could make the labels push the contents inward? This helps a lot such as it is, but pushing contents inward would be a big benefit to me.
    – polemon
    Jul 25, 2014 at 12:21
  • @polemon Will you please elaborate - pushing contents inward? Sorry I don't understand well.
    – user11232
    Jul 25, 2014 at 13:48
  • Just like in my opening post: if one of those lines becomes too long, it'll push the contents inward, rather than overlapping them (the "longitemname" in the first picture)
    – polemon
    Jul 25, 2014 at 15:04
  • @polemon That means, you don't want description labels to break in to second line? Use sameline instead of multiline.
    – user11232
    Jul 25, 2014 at 23:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .