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.

I am able to make subsections italic and larger using the titlesec package, but there seems to be no working solution to make them underlined. Here is my current document:

\documentclass[11pt]{article}
\usepackage{titlesec}
\titleformat*{\subsection}{\normalfont\large\itshape}

\begin{document}
\section*{Materials and Methods}
\subsection*{Sampling}
Lorem ipsum
\end{document}

enter image description here

I tried adding \titlerule but this just drew a large line above the subsection title:

\documentclass[11pt]{article}
\usepackage{titlesec}
\titleformat*{\subsection}{\normalfont\large\itshape\titlerule}

\begin{document}
\section*{Materials and Methods}
\subsection*{Sampling}
Lorem ipsum
\end{document}

enter image description here

share|improve this question
    
use \titlerule –  Sean Allred Jul 11 '13 at 12:16
1  
Welcome to TeX.SX! You can have a look on our our starter page to familiarize yourself further with our format. –  Claudio Fiandrino Jul 11 '13 at 12:20
    
I edited my question to show what \titlerule does –  xApple Jul 11 '13 at 12:27
    
It is not a goof typography to underline headings. Nowadays underlining is only used for the marking of links ... –  Kurt Jul 11 '13 at 12:42
3  
@xApple In good typography underlining is not used. –  egreg Jul 11 '13 at 13:00
show 3 more comments

2 Answers 2

up vote 5 down vote accepted

I'd like to propose a different approach, using the titlesec package. The reason is the the standard \underline command used in the other answer doesn't support line breaks, so one could end up with undesired results for long titles, as the following example illustrates:

\documentclass[11pt]{article}
\usepackage{sectsty}
\subsectionfont{\normalfont\large\itshape\underline}

\begin{document}
\section*{Materials and Methods}
\subsection*{Sampling and some other words just to show what might go wrong with a long title for a subsection}
Lorem ipsum
\end{document}

enter image description here

Using the explicit option for titlesec, you have easy access to the title, and the \uline command from the ulem package (for example) can be used, so that now line breaks are allowed:

\documentclass[11pt]{article}
\usepackage[explicit]{titlesec}
\usepackage{ulem}

\titleformat{\subsection}
  {\normalfont\large\itshape}{\thesubsection}{1em}{\uline{#1}}

\begin{document}
\section*{Materials and Methods}
\subsection*{Sampling and some other words just to show what might go wrong with a long title for a subsection}
Lorem ipsum
\end{document}

enter image description here

Enough has been said in comments and in the other answer about whether or not to underline, so I will not insist on this here.

share|improve this answer
    
I will think about good typography and the use of underlines. Thanks for the solution ! –  xApple Jul 11 '13 at 14:53
    
Today I noticed that the code you suggested works, but also affects the style of the automatically generated bibliography. In particular, the journal names now get underlined similarly to the subsection titles. This happens as soon as one includes the ulem package. This is rather strange ! –  xApple Jul 12 '13 at 14:15
    
@xApple load the package with the normalem option, as in \usepackage[normalem]{ulem}. –  Gonzalo Medina Jul 12 '13 at 14:22
    
That solved the issue. Thanks ! –  xApple Jul 12 '13 at 14:45
add comment

As @egreg and @Kurt have pointed out, underlining is not standardly considered good practice in typography nowadays, which is just something you many want to keep in mind. Nonetheless, I don't think that should prevent you from receiving an answer to your question. If you do in fact want to underline subsections, you can do so using the sectsty package. Here's an MWE:

Update: As @GonzaloMedina points out in the other answer, my previous answer ran into problems with long (sub)section titles that needed to break over multiple lines. The approach that uses the sectsty package can also be remedied by loading the ulem package with the optional [normalem] argument. (The [normalem] argument prevents the ulem package from enabling the feature of the ulem package that replaces italics with underlining of text that is emphasized with the \emph and \em commands.)

\documentclass[11pt]{article}
\usepackage[normalem]{ulem}
\usepackage{sectsty}
\subsectionfont{\normalfont\large\itshape\underline}

\begin{document}
\section*{Materials and Methods}
\subsection*{Sampling}
\subsection*{A very long sectional heading title that will probably have to be split over two lines}
Lorem ipsum
\end{document}

enter image description here

share|improve this answer
    
Your answer has a simpler syntax, but ended up being incompatible with some other package I was using in my document. I think \usepackage{lineno} is the culprit. –  xApple Jul 11 '13 at 14:52
    
@xApple Hmm, I tried loading that package with my MWE and it worked fine (both when it was loaded before and when it was loaded after sectsty). If you're really interested in pursuing it, you could read section 9 of the sectsty documentation. That might give you some clues as to what is going on. At any rate, I'm glad you have something that is working for you. Cheers. –  Adam Liter Jul 11 '13 at 15:14
    
The two lines that prevent the document from compiling are the following: \usepackage{lineno} \linenumbers. Both placed before the \begin{document}. –  xApple Jul 12 '13 at 14:14
    
@xApple I think it's going to take someone more knowledgeable than me to figure this out. If you're interested, you should ask it as another question. –  Adam Liter Jul 12 '13 at 20:25
    
@xApple, I ended up posting a follow up question myself, asking about the compatibility issue, as I was somewhat curious. I hope you don't mind that I went ahead and did this! :) –  Adam Liter Aug 6 '13 at 5:25
show 1 more comment

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.