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.

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}{}  
}{}
share|improve this question

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

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
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
    
Please think twice about this. Underlining is really ugly. –  mrf Aug 22 '12 at 13:32
    
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
1  
@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

1 Answer 1

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}

enter image description here

share|improve this answer
    
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

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