Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LaTeX \rule filling the line

Tags:

latex

rule

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).

like image 778
Konrad Rudolph Avatar asked Mar 31 '10 13:03

Konrad Rudolph


People also ask

How to draw a horizontal line to separate paragraphs in latex?

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.

How do you break a line in latex?

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).

How do you add a new paragraph in latex?

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 \.

Is it possible to break the document flow in latex?

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.


2 Answers

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}
like image 76
RTBarnard Avatar answered Sep 21 '22 08:09

RTBarnard


The horizontal rule of 1pt height and raised by 1.5pt.

Hello \leaders\vrule height 2.5pt depth -1.5pt \hfill \null
like image 45
Alexey Malistov Avatar answered Sep 20 '22 08:09

Alexey Malistov