8

How I can get color horizontal line between two texts? I am using command \rule{16cm}{1mm}. Can any one suggest how to change the color of horizontal line.

2

2 Answers 2

14

Very simply (don't forget \noindent if it's between paragraphs):

    \documentclass{article}

    \usepackage[utf8]{inputenc}
    \usepackage[x11names]{xcolor}
    \usepackage{lipsum}
    \usepackage[textwidth = 16cm]{geometry}
    \begin{document}
    \lipsum[1]

    \noindent\textcolor{PaleVioletRed3}{\rule{16cm}{1mm}}

    \lipsum[2]
    \end{document} 

enter image description here

2
  • I am using \newcommand{\divider}{\vskip1pt\hrule\vskip1pt} , it works. but it gives the black color line. If i changed the color, the space between line and text become more.
    – mustamus
    Jul 20, 2014 at 12:41
  • It's normal you get a black rule, since you have no colour command. As for the second sentence I don't know what happening since it's unfinished…
    – Bernard
    Jul 20, 2014 at 15:44
12

The following example defines \sepline that prints a colored line between paragraphs, if the end of the first and the start of the second paragraph are on the same page. The line vanishes at page breaks.

\sepline is vertically centered between the paragraphs. If \parskip is non-zero, then half of \parskip is put before and the other half after the line.

The line can be configured by:

  • Length \seplinewidth: line width/thickness
  • Length \seplinesep: additional vertical space around the line
  • Color sepline: The color for the line, can be changed by \colorlet or \definecolor.

Full Example:

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[x11names]{xcolor}
\usepackage{lipsum}
\usepackage[textwidth = 16cm]{geometry}

\newlength{\seplinewidth}
\newlength{\seplinesep}
\setlength{\seplinewidth}{1mm}
\setlength{\seplinesep}{2mm}
\colorlet{sepline}{PaleVioletRed3}
\newcommand*{\sepline}{%
  \par
  \vspace{\dimexpr\seplinesep+.5\parskip}%
  \cleaders\vbox{%
    \begingroup % because of color
      \color{sepline}%
      \hrule width\linewidth height\seplinewidth
    \endgroup
  }\vskip\seplinewidth
  \vspace{\dimexpr\seplinesep-.5\parskip}%
}

\begin{document}
\lipsum[1]
\sepline
\lipsum[2]
\setlength{\parskip}{5mm}
\sepline
\lipsum[3]
\end{document}

Result

You must log in to answer this question.

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