I use \usepackage[explicit]{titlesec} to customize the design of my sections, subsections...
In particular, i have :
\titleformat{\section}%
{\large\sffamily\bfseries}%
{My Section \arabic{section} }%
{0.5em}%
{#1}% \\ \hspace*{-1.5cm}
[{\color{blue}\titlerule[2.5pt]}]
where the {\color{blue}\titlerule[2.5pt]} produces an underline. The problem is, that a page breaking can happen just after the section title, and the line would appear on the next page. Is there a way to prevent that ?
EDIT : Minimal Example:
\documentclass[12pt]{article}
\usepackage[explicit]{titlesec}
\usepackage[dvipsnames]{xcolor}
\titleformat{\section}%
{\large\sffamily\bfseries}%
{Section \arabic{section}}%
{0.5em}%
{#1}% \\ \hspace*{-1.5cm}
[{\color{blue}\titlerule[2.5pt]}]
\begin{document}
\section{titre1}
blabla
\vspace{16cm}\\
blabla
\section{titre2}
blabla blabla
\end{document}