17

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

1
  • 5
    Look at the xhfill package
    – egreg
    May 14, 2016 at 20:09

4 Answers 4

12

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

1
  • Is there some online documentation for beginning users of key/value syntax?
    – A Feldman
    May 15, 2016 at 13:18
7

You could place your \hrulefill in \vtop boxes as below:

\documentclass[10pt,letterpaper]{article}

\begin{document}
    Please state your name: \hrulefill

    I was born on \hskip-1em\vtop{\vskip.05cm\hsize=2in \hrulefill}%
    ~~in \hskip-1em\vtop{\vskip.05cm\hsize=2in \hrulefill}

\end{document}

enter image description here

You could do the same thing using a macro:

\documentclass[10pt,letterpaper]{article}

\def\Lrule#1#2{\vtop{\vskip#1\hsize=#2 \hrulefill}}

\begin{document}
    Please state your name: \hrulefill

    I was born on\hskip-1em\Lrule{.05cm}{2in}~~in%
     \hskip-1em\Lrule{.05cm}{2in}

\end{document}

However, the above requires one to specify a line length, and therefore does not act like a \hrulefill because it has no glue.

A different way of doing it using leaders. This time the control sequence acts like a \hrulefill but has a variable height relative to baseline (first variable). It uses a repeated character to produce the line (second variable):

\documentclass[10pt]{article}

\def\Vrulefill#1#2{
    \leavevmode%
    \hskip-.2in%
    \leaders%
    \vtop{\hsize=.0025in\vskip#1#2}%
    \hfill%
    \hskip.3in%
}

\begin{document}



  %%With Zero \vskip and the period as the repeated character%%
  \Vrulefill{0in}{.}Hello Kitty\Vrulefill{0in}{.}Hello Kitty\Vrulefill{.02in}{.}%
Hello Kitty \vskip.1in

 %%With Zero \vskip and the \_ as the repeated character%%
  \Vrulefill{0in}{\_}Hello Kitty\Vrulefill{0in}{\_}Hello Kitty\Vrulefill{0in}{\_}%
Hello Kitty \vskip.1in

  %%With Zero \vskip and the dash as the repeated character%%
  \Vrulefill{0in}{-}Hello Kitty\Vrulefill{0in}{-}Hello Kitty\Vrulefill{0in}{-}%
Hello Kitty

  \vskip.5in

  %%With .05in \vskip and the period as the repeated character%%
  \Vrulefill{.05in}{.}Hello Kitty\Vrulefill{.05in}{.}Hello Kitty\Vrulefill{.05in}{.}%
Hello Kitty \vskip.1in

   %%With .05in \vskip and the \_ as the repeated character%%  
  \Vrulefill{.05in}{\_}Hello Kitty\Vrulefill{.05in}{\_}Hello Kitty\Vrulefill{.05in}{\_}%
Hello Kitty \vskip.1in

   %%With .05in \vskip and the dash as the repeated character%%
  \Vrulefill{.05in}{-}Hello Kitty\Vrulefill{.05in}{-}Hello Kitty\Vrulefill{.05in}{-}%
Hello Kitty
      \vskip.5in

     %%With negative .05in \vskip and the period as the repeated character%%
    \Vrulefill{-.05in}{.}Hello Kitty\Vrulefill{-.05in}{.}Hello Kitty\Vrulefill{-.05in}{.}%
Hello Kitty \vskip.1in

    %%With negative .05in \vskip and the dash as the repeated character%%
    \Vrulefill{-.05in}{\_}Hello Kitty\Vrulefill{-.05in}{\_}Hello Kitty\Vrulefill{-.05in}{\_}%
Hello Kitty \vskip.1in

   %%With negative .05in \vskip and the dash as the repeated character%%
    \Vrulefill{-.05in}{-}Hello Kitty\Vrulefill{-.05in}{-}Hello Kitty\Vrulefill{-.05in}{-}%
Hello Kitty


\end{document}

Which produces:

enter image description here

Changing

`\vtop{\hsize=.0025in\vskip#1#2}%

to:

`\vtop{\hsize=.05in\vskip#1#2}%`

gives you some very nice dotted and dashed lines:

enter image description here

and using the same \vtop{\hsize=.05in\vskip#1#2}%

\Vrulefill{0in}{/}
            \vskip.2in

    \Vrulefill{0in}{@}
                \vskip.2in

     \Vrulefill{0in}{[]}
              \vskip.2in

    \Vrulefill{0in}{\}\{}

can produce some interesting decorative rules:

enter image description here

Thick and skinny lines, or dashes, can be made by using a \vline as the "character":

     \Vrulefill{0in}{\vline height .2em width 4pt}

     \Vrulefill{0in}{\vline height .001em width 4pt}

enter image description here

1
  • Question within the question; does anybody know why using the - character as the repeated character results in a lower lying line than using the \_ control sequence?
    – A Feldman
    May 15, 2016 at 4:39
4

Here I use leaders to provide \drulefill (dashed rule fill), with 4 governing parameters:

\ruleht is the elevation of the dash, what the OP of this question is seeking to control

\repfrac is a fraction between 0 and 1 (inclusive) that indicates the solid fraction of the dashed line. By setting the value=1, the dashed line becomes solid, which is what the OP wants.

\replength is the period (length) of the dash/gap cycle.

\rulewidth is the thickness of the fill rule.

In the MWE below, I compare the customized \drulefill with the standard \hrulefill.

\documentclass[10pt]{article}
\newlength\replength
\newcommand\ruleht{3pt}% ELEVATION OF RULE
\newcommand\repfrac{.66}% SOLID FRACTION OF DASH LINE [0->1] (USE 1 FOR SOLID)
\replength=.6em\relax% PERIOD OF DASHED RULE
\newcommand\rulewidth{1pt}% THICKNESS OF RULE
\newcommand\drulefill{\leavevmode\dashfill\hfil%
  \kern\dimexpr\repfrac\replength-\replength\relax}
\newcommand\dashfill[1][\repfrac]{\cleaders\hbox to \replength{%
  \smash{\rule[\ruleht]{\repfrac\replength}{\rulewidth}}}\hfill}
\begin{document}
X\drulefill\par
Z\drulefill dhf\drulefill sj\drulefill

\renewcommand\ruleht{-2pt}% ELEVATION OF RULE
\renewcommand\repfrac{1}% SOLID FRACTION OF DASH LINE [0->1] (USE 1 FOR SOLID)
\replength=1.5pt\relax% PERIOD OF DASHED RULE
\renewcommand\rulewidth{.4pt}% THICKNESS OF RULE

X\drulefill\par
Z\drulefill dhf\drulefill sj\drulefill

X\hrulefill\par
Z\hrulefill dhf\hrulefill sj\hrulefill
\end{document}

enter image description here

6
  • Hello, thank you for your solution. Is it possible to color these lines in blue, red or grey? And if so, how?
    – AndréC
    Oct 26, 2021 at 14:06
  • @AndréC You can certainly do \textcolor{red}{\drulefill} if you have loaded the xcolor package. Oct 26, 2021 at 14:11
  • Thanks. Is it possible to set a parameter to define this color like you did for the line thickness and texture (dashed or solid) ?
    – AndréC
    Oct 26, 2021 at 14:21
  • 1
    @AndréC You can change the definition \newcommand\drulefill{\leavevmode\textcolor{\rulecolor}{\dashfill}\hfil\kern\dimexpr\repfrac\replength-\replength\relax} and define \rulecolor with, for example, \newcommand\rulecolor{cyan} Oct 26, 2021 at 14:31
  • 1
    Anything defined with a \newcommand can be made local by placing it in a braced group {\renewcommand\rulewidth{1ex}...} (or, alternately, \begingroup...\endgroup). The only global declaration in my MWE is the length \replength. There are ways around that, but it takes a bit more work, @AndréC. Oct 26, 2021 at 16:41
1

Play with the footline in every way with following tiny code lines: (Follow two steps properly)

  1. Include the following in the header or top section. (Macro):

    \def\Vrulefill#1#2#3#4{
    \color{gray}% You can keep any color you like.
    \leavevmode%
    \hskip-.2in%
    \leaders%
    \vtop{\hsize=#1\vskip#2#3}%
    \hfill%
    \hsize #4%
    \hskip.1in%**
    }
    
  2. Include any of the following code whenever you want to insert a footline:

    \Vrulefill{0.0025in}{0.1in}{\vline height .1em width 1pt }{3in}
    

Description:
Each brace bracket will determine the attribute of footrule. #1 determines density of points to make a line, #2 determines vertical offset of line, #3 determines the height or thickness of line, #4 determines the length of line. \Vrulefil is a macro defined at top.

\Vrulefill{0.05in}{0.1in}{@ }{3in}

Description:
If #1 is reduced and #3 is @ or / etc. then some interesting decorative rules can be produced.

1
  • +1 and welcome to TeX.SE! Sorry that no one welcomed you before. This looks like an excellent first answer, and hopefully you come back! Sep 27 at 17:08

You must log in to answer this question.

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