2

My question is actually a generalization of this scenario: I'm using the xhfill package to fill the last line corresponding to each item in a given list (set through the enumitem package) with a horizontal filling rule (terrible typesetting, but it's required for some legal documents). I wonder if there is a way to automate adding the rule command after the text for each list item instead of having to add it manually. My point is actually if there is a way to do this so that any command or macro may be added at that point.

1
  • 3
    Hi, please prepare a minimal working example so we all are on the same page and know the basics of your question. That way it's much easier to help.
    – Johannes_B
    Mar 9, 2014 at 20:58

1 Answer 1

5

Next time, please provide a Minimal Working Example as Johannes_B mentioned. That would have made it easier to help and more likely that my answer actually will be of some use (which I'm not sure about).

Is this the kind of thing you are looking for? This image shows a 'legal' enumeration between two 'regular' enumerations.

Regular and legal enumerations

The code uses the before* and after* options provided by enumitem:

\documentclass{article}
\usepackage{enumitem}
\usepackage{xhfill}
\newcommand{\xfill}[2][1ex]{{%
  \dimen0=#2\advance\dimen0 by #1
  \leaders\hrule height \dimen0 depth -#1\hfill%
}}
\newlist{mylegal}{enumerate}{1}
\newif\iffirstlegal\firstlegalfalse% We need a toggle to track whether the item is first in the list or not
\setlist[mylegal]{%
  label=\arabic*.,
  before*={% This saves the standard definition of \item and then redefines it to add the fill if the item is not first on the list; if it is the first item, it omits the fill but toggles the firstlegal switch so the next item will trigger it
    \let\olditem\item% save the standard definition of \item in a macro, \olditem
    \firstlegaltrue% set the toggle for first item in the list to true
    \def\item{\iffirstlegal\olditem\firstlegalfalse\else \xfill{.5pt}\mbox{}\olditem\fi}% new, temporary defition of \item
    },
  after*={% This takes care of adding the fill for the final item on the list and just makes sure that \item is reset to its standard definition
    \xfill{.5pt}\mbox{}% fill for final item in list
    \let\item\olditem% restore standard definition of \item
    }%
  }

\begin{document}

% Get a baseline so we know what the regular enumerated list looks like...
A regular enumeration:
\begin{enumerate}
    \item An item
    \item Another item
\end{enumerate}

% Demonstrate the effect of the new list environment
A legal enumeration:
\begin{mylegal}
     \item An item
     \item Another item
\end{mylegal}

% Make sure that \item is correctly reset by comparing the output here with the baseline
A regular enumeration:
\begin{enumerate}
    \item An item
    \item Another item
\end{enumerate}

\end{document}

Note that the way this works involves redefining \item to add the fill first. This is why it is necessary to exclude the first list item (we don't want a line before we start) and to handle the final list item specially (since it would otherwise not get a line at all).

1
  • It fits perfectly what I was looking for. I thought the MWE would not be needed for this question and when I came back your answer was already available, so the MWE was not needed anyway. I'll keep it in mind for future posts, though.
    – Marcos
    Mar 17, 2014 at 1:13

You must log in to answer this question.

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