\hrule length inconsistent

I'm using the tufte-book document class. When I use \hrule, sometimes it extends the text width (which I want), and other times it extends the full page width, apparently randomly.

How can I get it to remain the text width length consistently between uses? Thanks!

• \hrule consistently makes a rule of the width of the current vertical box. If you are getting different widths then code you have not shown is changing the width of the text blocks but if you show no example document impossible to guess what code you have used. Make a small but complete example document with rules of different widths, then someone will debug it for you. – David Carlisle Jul 18 '18 at 7:52

You can replace

\hrule


with

\noindent\rule{\textwidth}{0.4pt}


This will set the width of the rule to the text length, which will be consistent between uses (unless something changes the width of the text; in that case the rule will fit the new text width). The {0.4pt} is the default height of rule.

As David Carlisle rightfully points out in the comments this does introduce \baselineskip and \parskip, whereas \hrule does not. So be aware that paragraphs will be started after those rules.

• note that \rule will by default be indented by the paragraph indentation, so a \textwidth rule will stick in to the right margin. – David Carlisle Jul 18 '18 at 7:50
• @DavidCarlisle would prefixing the command with \noindent solve that problem? – Flexo013 Jul 18 '18 at 8:12
• yes, but that isn't what you told the OP to do. (there are other differences too, \rule will introduce \baselineskip and \parskip vertical space which is not generated by \hrule which does not start a paragraph, so replacing \hrule by \rule may introduce additional changes. Perhaps that's OK but just saying "simply replace" is rather misleading. – David Carlisle Jul 18 '18 at 8:56
• @DavidCarlisle Thanks for the feedback! I have updated my answer accordingly. – Flexo013 Jul 18 '18 at 9:19