3

I am trying to use the ulem package to underline section titles while still being able to have automatic line breaking:

\documentclass{scrartcl} 
\usepackage[normalem]{ulem}
\begin{document}
    \addtokomafont{section}{\uline}
    \section{A section title so long that it causes a line break. A section title so long that it causes a line break.}
\end{document}

This works like expected. Once I add the hyperref package, the automatic line breaking seems to be disabled, e.g.

\documentclass{scrartcl} 
\usepackage[normalem]{ulem}
\usepackage{hyperref}
\begin{document}
    \addtokomafont{section}{\uline}
    \section{A section title so long that it causes a line break. A section title so long that it causes a line break.}
\end{document}

yields an overfull line for the section title.

If a remove the \addtokomafont{section}{\uline} the line breaking is back again, but of course there is no underlining any more ...

How can I achieve underlined section titles with automatic line breaking enabled?

NOTE: I know I shouldn't use underlining for section titles, but this was not my decision.

NOTE 2: For those who complain about using underlining at all: The issue also occurs if I use strikeout via \sout instead of \uline, which is definitely useful during the editing process of a document.

4
  • Remark to the NOTE. Alas, TeX primitive \dump is not applicable to a stupid boss/institution. :-) Commented Jun 23, 2014 at 12:55
  • 1
    Break manually. Or use short titles.
    – egreg
    Commented Jun 23, 2014 at 13:15
  • Sorry for being so late; I probably forgot about my comment because I greatly dislike underlining. I know it's not your fault, but… ;-)
    – egreg
    Commented Apr 21, 2015 at 20:36
  • Well, non of the answers tries to solve the actual incompatibility between uelm and hyperref. But since it's a good workaround and I also dislike underlining, I accept it as an answer.
    – porst17
    Commented Apr 22, 2015 at 6:13

2 Answers 2

1

This requires all section titles use the optional argument, but at least does the breaking you require.

\documentclass{scrartcl}
\usepackage[normalem]{ulem}
\usepackage{hyperref}

\renewcommand\othersectionlevelsformat[3]{%
  \ifnum\pdfstrcmp{#3}{\thesection}=0
    \uline{#3\autodot\enskip}%
  \else
    #3\autodot\enskip
  \fi
}

\begin{document}

\section
 [A section title so long that it causes a line break.
  A section title so long that it causes a line break.]
 {\uline{A section title so long that it causes a line break.
  A section title so long that it causes a line break.}}

\subsection{Whatever}

\end{document}

Some trick has to be used to underline also the section number, but not do the same to subsections.

enter image description here

0

use the optional argument and \uline in the title itself:

\documentclass{scrartcl} 
\usepackage[normalem]{ulem}
\usepackage{hyperref}
\begin{document}
    \section[A section title so long that it causes a line break. A section title so long that it causes a line break.]
    {\uline{A section title so long that it causes a line break. A section title so long that it causes a line break.}}
\end{document}
3
  • This idea is not bad. But unfortunately, the solution is not complete: The section number is not underlined if I use \uline inside the \section command.
    – porst17
    Commented Jun 25, 2014 at 9:34
  • If you need it for all section numbers: \renewcommand\thesection{\uline{\arabic{section}}}
    – user2478
    Commented Jun 25, 2014 at 9:42
  • Is it possible to also have the space between the section number and the section title underlined? With your solution, there is still a gap.
    – porst17
    Commented Jun 25, 2014 at 11:46

You must log in to answer this question.

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