I am fiddling with various ways of filling a line with a vertically centered line and experimenting with the answers here: https://stackoverflow.com/questions/2553392/latex-rule-filling-the-line and here: Vertically centered horizontal rule filling the rest of a line?. Now, I would like the line to fill the beginning (left) of the line - not the rest. It seems "fill" commands do not do anything unless the line contains "something" before the fill part. How can I do this so that I can fill the line with a rule like this:

----------------------------------------------- Text

Where the text is flush right?

  • 2
    \leavevmode\null or \noindent\null should do it. – barbara beeton Jan 18 '14 at 20:29
  • Great, that does the trick. – Thomas Arildsen Jan 18 '14 at 20:35

What you place before can be empty. The following example is taken from Vertically centered horizontal rule filling the rest of a line?:

enter image description here

\usepackage{xhfill}% http://ctan.org/pkg/xhfill
  \dimen0=#2\advance\dimen0 by #1
  \leaders\hrule height \dimen0 depth -#1\hfill%
\mbox{}\xfill{1pt} Here is some text \par
\mbox{}\xfill{8pt} Here is some text \par
\mbox{}\xhrulefill{blue}{2pt} Here is some text \par
\mbox{}\xhrulefill{cyan}{1ex} Here is some text \par
\mbox{}\xrfill[0ex]{1ex}[red]{} Here is some text \par

\mbox{} sets an empty box and initiates a paragraph (similar to what TeX's \leavevmode does). Also, to avoid paragraph indentation, I've set \parindent to 0pt. However, you can control this individually using \noindent.

|improve this answer|||||
  • An \mbox seems to take up a little bit of horizontal space, whereas \leavevmode\null suggested by @barbara-beeton does not. P.S. I avoided the above solution because I was trying to accomplish it with a simple one-liner, not requiring extra packages such as xhfill. – Thomas Arildsen Jan 18 '14 at 20:38
  • @ThomasArildsen: That should not be the case, however, if you feel comfortable with it, \leavevmode only should do the job. You can also open xhfill.sty and use the code in there for horizontal rules (or leaders) in whichever way you want. – Werner Jan 18 '14 at 20:42
  • @ThomasArildsen: Probably there is a space after \mbox{...} before the rule. This space after the curly brace is not ignored in horizontal mode unlike spaces after command names. Technically \mbox{} is the same as \leavevmode\null, because \mbox{} expands to \leavevmode\hbox{} and \null expands to \hbox{}. – Heiko Oberdiek Jan 18 '14 at 21:25
  • Ah, OK. I had a space after the \mbox{}. – Thomas Arildsen Jan 19 '14 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.