# What is the default length of \hrule?

When used without parameters, what varfiable controls the length of \hrule?

I.e., how can I change the default length of \hrule, other than adding parameters to each instance -- say, to affect existing commands defined in a package?

The following example shows that it does not seem to depend on margins or \textwidth:

\documentclass{article}
\usepackage{changepage}
\begin{document}
\hrule
a\dotfill\verb|\textwith|=\the\textwidth
a\dotfill\verb|\textwith|=\the\textwidth
\hrule
a\dotfill\verb|\textwith|=\the\textwidth
\dotfill
a\dotfill\verb|\textwith|=\the\textwidth
\hrule
\end{document}

• – touhami Sep 28 '15 at 6:51
• @touhami I tried to change \textwidth, \linewidth, and \hsize, but it has no effect on \hrule. – Alexander Gelbukh Sep 28 '15 at 6:58
• You can't: \hrule (as explained by Mico) has no default width; either you explicitly specify a width, or the one of the enclosing vertical box will be used. – egreg Sep 28 '15 at 8:29
• @egreg In fact yours is the best answer: "\hrule has no default width". – Alexander Gelbukh Sep 28 '15 at 9:40

It is a rule in vertical mode. You need a vbox if you want to change the width:

\documentclass{article}
\begin{document}

a\dotfill\verb|\textwith|=\the\textwidth
\hrule

\vspace{5mm}
\begin{minipage}{5cm}
foo\hrule
\end{minipage}

\end{document}


• So there is no simple variable to treak, other than enclose the whole thing in minipage? – Alexander Gelbukh Sep 28 '15 at 7:00
• @AlexanderGelbukh - See my answer for a method that sets the width directly. – Mico Sep 28 '15 at 7:03
• @AlexanderGelbukh: Instead of \hrule use \rule{<width>}{<height>} or define the width of the \hrule. \rule works in horizontal mode like \hrulefill. – user2478 Sep 28 '15 at 7:04

\hrule is a TeX primitive. On p. 221 of the TeXbook, Knuth says that the width of the rule that is created by \hrule

depends on the context; the rule will extend to the boundary of the smallest box or alignment that encloses it.

Quite frequently, this means that the width of the rule will equal \textwidth, since the box that encases the rule encases the entire textblock.

If you need to set the width explicitly (and want to stick with the \hrule syntax), you should write, say,

\hrule width0.5\textwidth


or

\hrule width5cm

• Yes, I know I can set it on each instance. The question is how can I change the default for some block. It seems that minipage is an option, but is there any simple variable to tweak, like {\somelength=1cm lots of code with many \hrule}? – Alexander Gelbukh Sep 28 '15 at 7:03