[Tex/LaTex] LaTeX Underlined section titles with note to right without underline


I would like to have underlined section titles. However, I would like to put a reference to the right, without extending the underline completely. I am using sectsty and ulem to get the underlined section. Below is an example of what I am trying to do, but the underline continues to the right.



    \section{Section Title\hfill [Ref]}

Best Answer

I would second what @egreg said about avoiding the need for underlining. But sometimes it can't be helped (like when you're working with others who insist on particular styling). So I'll help you to get where you want to be.

This solution allows a full [double] underline (just like with the plain solution you had in your MWE), but also gives an alternate option for the reference.

I have redefined things to allow you to continue to use \section{...} and \section*{...} as normal. But now, instead of changing the TOC line, the optional argument is used for the reference:


A full example, with the appropriate redefinitions:

\usepackage{showframe} % For illustration

% Add reference functionality

    \section[\cite{test}]{Section Title}  Regular section
    \section*[{[1]}]{Section Title} Starred section % Manually give reference
    \section{Section Title} Without reference
    \section*{Section Title} Without reference, starred section
    \section[\cite{test}]{Section Title} With a large section number
    \section[\cite{test}]{This is a Very, Very, Very Long\\Section Title} With a very long title, you must manually break the line to avoid overlapping the reference

This will make the following sections:


Related Question