11

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

7
  • 1
    use \titlerule Jul 11, 2013 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. Jul 11, 2013 at 12:20
  • 1
    I edited my question to show what \titlerule does
    – xApple
    Jul 11, 2013 at 12:27
  • It depends on what kind of document. This could be true for HTML, but not for an article destined to be printed in a journal.
    – xApple
    Jul 11, 2013 at 12:49
  • 3
    @xApple In good typography underlining is not used.
    – egreg
    Jul 11, 2013 at 13:00

2 Answers 2

12

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.

4
  • I will think about good typography and the use of underlines. Thanks for the solution !
    – xApple
    Jul 11, 2013 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, 2013 at 14:15
  • @xApple load the package with the normalem option, as in \usepackage[normalem]{ulem}. Jul 12, 2013 at 14:22
  • Thanks ! Is it possible to have the line extend till the end of the page ? Edit: it seems so Feb 25, 2017 at 17:29
6

As @egreg has 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

6
  • 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, 2013 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, 2013 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, 2013 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, 2013 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, 2013 at 5:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .