# Underline the title of a subsection [duplicate]

Possible Duplicate:
Changing the section title style for an article document type

I'm trying to undeline the title of a set of subsections in my document. In order to achieve it, I have defined a new environment that encapsulates the format of this subsection.

My problem is that I can not achieve to underline the text of the title of the subsection. I don't want to use the package sectsty because if I do this I have conflicts with other definitions done using the titlesec package.

\newenvironment{UnderlineSubSection}{
\titleformat{\subsection}
{\normalfont\sffamily\bfseries\color{cyan}}
{\thesection}{1em}{}
}{}

-

## marked as duplicate by Thorsten, percusse, Marco Daniel, Claudio Fiandrino, Martin SchröderSep 9 '12 at 21:42

Welcome to TeX.sx! A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "{}" on it). –  Thorsten Aug 22 '12 at 13:28
Load for example the ulem package and add \uline to the last argument (i.e the one after {1em}) of \titleformat. –  cgnieder Aug 22 '12 at 13:36
@user17888 Good typography (see Bringhurst) recommend to use italic, not underline. Underline was used in manuscripts typed on a typewriter to indicate for the printing house that the text should be set in italic. So only use underlining if your boss sacks you if you are not using it. –  Sveinung Aug 22 '12 at 15:01

define it as a command, just as the default subsection. Instead of package soul you can use ulem alternetively

\documentclass[a4paper,12pt]{report}
\usepackage{soul}

\makeatletter
\def\UnderlineSubSection{\@ifnextchar*\UnderlineSubSection@i\UnderlineSubSection@ii}
\def\UnderlineSubSection@i*#1{\subsection*{\ul{#1}}}
\def\UnderlineSubSection@ii{\@ifnextchar[\UnderlineSubSection@iii\UnderlineSubSection@iv}
\def\UnderlineSubSection@iii[#1]#2{\subsection[#1]{\ul{#2}}}
\def\UnderlineSubSection@iv#1{\subsection{\ul{#1}}}
\makeatother

\begin{document}

\tableofcontents

\section{foo}
\subsection{foo}
\UnderlineSubSection{baz}
\UnderlineSubSection*{foobar}
\UnderlineSubSection[foobarbaz]{foo\_bar\_baz}

\end{document}


-
Thanks very much. This works fine as I want. –  EvaMonclús Aug 22 '12 at 14:06
@user17888 please consider accepting Herbert's answer (by clicking on the check-mark to the left of the answer, below its vote count). –  Gonzalo Medina Aug 22 '12 at 22:16