[Tex/LaTex] Raise or lower \hrulefill

rules

I am editing a questionnaire that uses \hrulefill as a text entry "field".

I would like to lower the \hrulefill a bit to give participants more room to write. For a fixed-length rule I would use something like \rule[-3pt]{#1}{0.6pt}. Can I raise or lower an \hrulefill in a similar way or add the fill behaviour to a \rule?

Please state your name: \hrulefill
I was born on \hrulefill in \hrulefill
...

enter image description here

Best Answer

You may want to look at the xhfill package. Here's a version using xparse to define the placement of the rule with a key/value syntax.

With height you specify the rule's bottom position, with respect to the baseline (default 0pt); with thickness the rule's thickness (default 0.4pt); with fill the behavior (default \fill).

In particular, \xhrulefill with no argument is equivalent to \hrulefill.

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\xhrulefill}{O{}}
 {
  \group_begin:
  \severin_xhrulefill:n { #1 }
  \group_end:
 }

\keys_define:nn { severin/xhrulefill }
 {
  height .dim_set:N    = \l_severin_xhrule_height_dim,
  thickness .dim_set:N = \l_severin_xhrule_thickness_dim,
  fill .skip_set:N     = \l_severin_xhrule_fill_skip,
  height .initial:n    = 0pt,
  thickness .initial:n = 0.4pt,
  fill .initial:n      = 0pt plus 1fill,
 }

\cs_new_protected:Nn \severin_xhrulefill:n
 {
  \keys_set:nn { severin/xhrulefill } { #1 }
  \leavevmode
  \leaders\hrule 
    height \dim_eval:n { \l_severin_xhrule_thickness_dim + \l_severin_xhrule_height_dim }
    depth  \dim_eval:n { -\l_severin_xhrule_height_dim }
  \skip_horizontal:N \l_severin_xhrule_fill_skip
  \kern 0pt
}
\ExplSyntaxOff

\setlength{\textwidth}{6cm} % just for the test

\begin{document}

abc\hrulefill

abc\xhrulefill

abc\xhrulefill[height=-3pt]

abc\xhrulefill[height=-2pt,thickness=1pt,fill=3cm]

abc\xhrulefill[height=-3pt,thickness=1pt]

abx\xhrulefill[height=0pt,thickness=1ex]

\end{document}

enter image description here