# How can I set a color for the title rule?

I'm writing a document which uses titlesec, and I'd like to set the title rule to a different color.

How can I do that?

This is what I currently have, which produces section titles with black rules:

\titleformat{\section}
{\Large\sffamily}
{\thesection.}{.5em}{}[\titlerule]


Note: I want to change the color of the rule that appears below a section title.

-
Welcome to TeX.SX! It's difficult to say without an example of the code you're using and an indication of what rule you want to color. – egreg May 17 '12 at 16:12
Thanks! I've added a snippet of the code I'm using. – alemartini May 17 '12 at 16:17

In a very simple manner:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage{titlesec}
\titleformat{\section}
{\Large\sffamily}
{\thesection.}{.5em}{}[\color{red}\titlerule]

\begin{document}
\section{Hello}
\vspace{5cm}
\section{Hello again}
\end{document}


I add the resulting image of my code:

EDIT

As @lockstep noticed, to avoid that \color inserts break points (reference answer) should be better to use:

\titleformat{\section}
{\Large\sffamily}
{\thesection.}{.5em}{}[\titleline{\color{red}\titlerule}]

-
Claudio, thanks a lot for your answer! – alemartini May 17 '12 at 16:32