[Tex/LaTex] A horizontal line with the same space-filling behaviour as /hfill

packagesspacing

Is there a command or package which would allow me to draw a line in the largest available space in the way that \hfill fills up the remaining space in a line?

i.e., a command to draw a line from the end of the text, wherever it happens to fall, to the right edge of the textwidth (leaving space for any additional text indented to be at the end of the line)?

Best Answer

You can use ordinary \hrulefill. There is also \dotfill for dots. For advanced control xhfill may be used.

\documentclass{article}
\usepackage{showframe}      %% just to show the frame
\usepackage{xhfill}
\setlength{\parindent}{0pt}
\begin{document}

%% Usage
%% \xhrulefill{<color>}{<height>}
%% \xrfill[raise]{ruleheight}[color]
%% \xhrectanglefill{<height>}{<linewidth>}
%% \xhrectanglefill{1cm}{1pt}

First \verb|\xrfill|\xrfill{1pt}

This is \verb|\xrfill|\xrfill[0pt]{3pt}[blue]

A take with \verb|\xhrulefill|\xhrulefill{cyan}{1cm}

With \verb|\xhrectanglefill|\xhrectanglefill{0.5cm}{1pt}

%% Ordinary \hrulefill

With \verb|Ordinary \hrulefill|\hrulefill

With \verb|Ordinary \dotfill|\dotfill
\end{document}​

enter image description here

Related Question