2

This is what I'm trying to achieve: enter image description here I'm trying to obtain it using this code:

documentclass{article}
\usepackage{enumitem}
\begin{document}

\newcounter{entry}
\setcounter{entry}{1000}

\newcommand{\xlistformat}[1]{\theentry.~(#1)} % This is the interesting part

\newlist{xlist}{enumerate}{1}
\setlist[xlist]{
  label = {\xlistformat{\alph*}},
  leftmargin = *,
  align = left
}

\begin{xlist}
\item Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut 
      purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis.

      Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget,
      consectetuer id, vulputate a, magna.
\end{xlist}
\end{document}

This doesn't work. I get this instead: enter image description here

I can make it work by changing

\newcommand{\xlistformat}[1]{\theentry.~(#1)}

to

\makeatletter
\newcommand{\xlistformat}[1]{\number\c@entry.~(#1)}
\makeatother

but this has many other problems.

I'm not sure what I need to change to get this working. I've tried using the format key instead of the label, but that has given essentially the same result. My guess is that something's going wrong with the expansion of \theentry, but my experiments in that direction have borne no fruit.

1 Answer 1

1

Use the widest key:

\documentclass{article}
\usepackage{enumitem, fmtcount, siunitx}
\usepackage[showframe]{geometry}

\begin{document}

\newcounter{entry}
\setcounter{entry}{100000000}

\newlength\entrylg\settowidth{\entrylg}{\theentry.}

\newcommand{\xlistformat}[1]{\theentry.~(#1)} % This is the interesting part

\newlist{xlist}{enumerate}{1}
\setlist[xlist]{
label = {\xlistformat{\alph*}},
widest = \makebox[\entrylg]{}, 
align=left,
leftmargin =*, 
}

\begin{xlist}
\item Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut
      purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis.

      Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget,
      consectetuer id, vulputate a, magna.

\setcounter{xlisti}{12}
\item Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut
      purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis.

      Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget,
      consectetuer id, vulputate a, magna.

\end{xlist}

\end{document} 

enter image description here

5
  • widest doesn't work if the definition of \xlistformat (or, for that matter, \theentry or the entry counter itself) changes. It also doesn't explain why simply replacing \theentry with \number\c@entry fixes the problem.
    – Derek
    Apr 5, 2017 at 17:01
  • @Derek: I've modified the code to take your observation into account, adding a new length (\entrylg), which is read by widest.
    – Bernard
    Apr 5, 2017 at 17:55
  • Thanks for the suggestion. Unfortunately, when I set the value of entry to 1 (for example) instead of 100000000, there's a huge gap between the right edge of "(a)" and the start of the item text. Not sure why. I appreciate the help, though!
    – Derek
    Apr 5, 2017 at 20:13
  • @Derek: I've changed the definition of widest, and it seems to work.
    – Bernard
    Apr 5, 2017 at 20:39
  • Although I tweaked this some to get the final effect I wanted, it had a lot of good ideas. Thanks.
    – Derek
    Apr 11, 2017 at 20:24

You must log in to answer this question.

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