Why does the following command not produce a horizontal rule filling the space until the end of the line?
Hello \rule[0.5em]{\fill}{1pt}
It is my understanding that this should print the text “Hello
” followed by a horizontal rule that extends until the end of the line, analogously to the macro \hfill
which is effectively equivalent to \hspace\fill
. – But in effect, this command just produces the text “Hello
”, no rule.
I am aware that the effect can be produced by \hrulefill
but it can’t be used here because I want a raised rule and \hrulefill
doesn’t work together with \raisebox
and I want my rule to hang above the baseline (at best in the middle of the line).
In some document, one wants to draw an horizontal line to separate paragraphs. It’s easy to do that in TeX or LaTeX, and you can even use packages to draw fancy rules. The ule command is used to draw a line.
Additionally, LaTeX provides the following advanced option for line break. It breaks the line at the point of the command. The number provided as an argument represents the priority of the command in a range of 0 to 4. (0 means it will be easily ignored and 4 means do it anyway).
Add a new paragraph in LaTeX When you want to start a new paragraph, you will have to leave a blank line in the input file. However, if you don’t believe in the algorithm used to break the lines, you can also produce your own line breaks with the special command \.
Breaking the document flow in LaTeX is not recommended unless you are creating a macro. Anyway, sometimes is necessary to have more control over the layout of the document; and for this reason in this article is explained how to insert line breaks, page breaks and arbitrary blank spaces.
I don't have a satisfying answer as to why the command you presented doesn't work, but I can offer an effective workaround. Put
% Raised Rule Command:
% Arg 1 (Optional) - How high to raise the rule
% Arg 2 - Thickness of the rule
\newcommand{\raisedrule}[2][0em]{\leaders\hbox{\rule[#1]{1pt}{#2}}\hfill}
into your document's preface, and then you can accomplish what you were hoping to with:
Hello \raisedrule[0.5em]{1pt}
The horizontal rule of 1pt height and raised by 1.5pt.
Hello \leaders\vrule height 2.5pt depth -1.5pt \hfill \null
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With