[Tex/LaTex] Underline the section title text in table of contents

table of contentstext-decorationstocloft

Hopefully this is easy. I would like to underline the text of the section title in the table of contents (with the section number removed). Similar to this picture, with the red line where the underline should be:

enter image description here

Please note that I don't want to underline the section title in the document, as per this question, only its entry in the table of contents.

I have tried the following code, but it doesn't work, as \underline expects the text to be supplied as a parameter.

\documentclass[a4paper]{article}

\usepackage{lipsum}
\RequirePackage[titles]{tocloft}

\makeatletter
\renewcommand{\cftsecpresnum}{\begin{lrbox}{\@tempboxa}}
\renewcommand{\cftsecaftersnum}{\end{lrbox}}
\setlength{\cftsecnumwidth}{0pt}
\renewcommand{\cftsecfont}{\underline}    % Doesn't work
\makeatother

\begin{document}
\tableofcontents
\section{Section 1 title}
\lipsum[1-2]
\section{Section 2 title}
\lipsum[3-4]
\end{document}

Best Answer

I won't recommend it, as it hard to read: see http://practicaltypography.com/underlining.html You can do this by:

\documentclass{article}
\usepackage{soul,xcolor}
\setul{1ex}{0.8ex}
\setulcolor{red}
\begin{document}
\tableofcontents
\section[\ul{Foobar}]{Foobar}
\end{document}

Underlined

EDIT: Maybe this helps, but I didn't get it managed to work with soul, nor to get the correct spacing:

\documentclass{article}
\usepackage{titletoc}
\titlecontents{section}{\thecontentslabel\quad}{\underline}{}{\hfill\thecontentspage}
\begin{document}
\tableofcontents
\section{Foobar}
\end{document}

enter image description here