0

I am trying to attain the following style of customized horizontal rule for my document.

enter image description here

I tried the following LATEX code.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[top=1cm, left=1cm, right=1cm, bottom=1.5cm]{geometry}
\usepackage{xcolor,lipsum}

\begin{document}
\lipsum[1]\\
{\color{gray} \rule{4.85 cm}{2 pt}}\  {\color{lightgray} \rule{\linewidth}{2 pt}}
\lipsum[1]
\end{document}

This gives the following satisfying result but I am unable to break the rule from crossing the line width. How to solve this issue? Is there any other way to get this type of horizontal rule?

enter image description here

1 Answer 1

2

enter image description here

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[top=1cm, left=1cm, right=1cm, bottom=1.5cm, showframe]{geometry}
\usepackage{xcolor,lipsum,calc}
\newlength{\spacelength}
\setlength{\spacelength}{\widthof{\ }}

\begin{document}
   \lipsum[1]\\
   {\color{gray} \rule{4.85 cm}{2 pt}}\  {\color{lightgray} \rule{\dimexpr\linewidth-4.85cm-\spacelength\relax}{2 pt}}
   \lipsum[1]
\end{document}

The problem is that you wanted

  • a rule of 4.85cm
  • a space
  • and a rule of \linewidth. This is of course more than one line, so you have to shorten the last line. You want it to have \linewidth - 2.85cm - WidthOfASpace. You can calculate this length simply by typing \dimexpr WhatYouWantToCalculate \relax. To get the width of a space, I used \widthof from the calc-package.

I added the showframe-option to geometry just to show that the line has now the perfect length, you can remove it without breaking anything.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .