0

I am trying to draw a horizontal line to the right of some text and to the end of the page, but as the text lengths are variable, I have opted to use \hrulefill instead of \rule so that the length of the horizontal line drawn is calculated automatically.

For example, MWE 1 below shows how the default \hrulefill works.

MWE 1

\documentclass{article}

\begin{document}

Hi \hrulefill

Hello \hrulefill

\end{document}

Subsequently, I wanted to customise its thickness and found some code to do it. In particular, MWE 2 below changes the line's thickness from a default of 0.4 pt to 1.5 pt.

MWE 2

\documentclass{article}

\renewcommand{\hrulefill}{% \leavevmode\leaders\hrule height 1.5 pt\hfill\kern 0 pt}

\begin{document}

Hi \hrulefill

Hello \hrulefill

\end{document}

Finally, I would like the line to be drawn from the centre of the words i.e. slightly higher than what the above MWEs produce. Thus, I was wondering how I could further adapt the \renewcommand code to include how "high" the line is drawn as well.

I note that a similar question has been asked and some solutions have been given here, but I am hoping to find a solution that simply adapts the \renewcommand code above!

Any intuitive explanations or suggestions will be greatly appreciated!

  • 1
    Does this answer your question? https://tex.stackexchange.com/questions/664583/hrulefill-vertical-centering/664584#664584 – Heiko Theißen Dec 23 '22 at 14:50
  • @HeikoTheißen Oh, yes it does! Thank you! But since an answer has been given too, I think I'll accept that as well! – Ethan Mark Dec 23 '22 at 15:01

1 Answers1

1

Rules also have a third field (along with their width and height), their depth. A negative depth will raise the rule. Specifically, a rule with a depth of d and a height of h will seem to be lowered by d and have a width of h+d. Thus you can change your definition to:

\renewcommand{\hrulefill}[2][0pt]{%
    \leavevmode\leaders\hrule height \dimexpr#1+#2\relax depth -#1\hfill\kern0pt}

This creates \hrulefill which accepts its width as its mandatory parameter and how much it is raised as its optional parameter.

Slurp
  • 876