Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
2  
\textcolor{red}{\rule{16cm}{1mm}} –  Sigur Jul 19 at 1:28
    
Related: How do I insert a border below text? –  Werner Jul 19 at 4:01

2 Answers 2

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

share|improve this answer

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

share|improve this answer
    
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 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 at 15:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.