LaTeX 下線付きのセクションタイトル(右に下線なしの注釈付き)

LaTeX 下線付きのセクションタイトル(右に下線なしの注釈付き)

セクション タイトルに下線を付けたいのですが、下線を完全に延長せずに、右側に参照を配置したいと思います。下線付きのセクションを取得するために、sectsty と ulem を使用しています。以下は、私が実行しようとしていることの例ですが、下線は右に続きます。

\documentclass[12pt]{article}
\usepackage{sectsty}
\usepackage[normalem]{ulem}

\sectionfont{\ulemheading{\uuline}}

\begin{document}
    \section{Section Title\hfill [Ref]}
\end{document}

答え1

@egreg が下線を引く必要がないようにするべきだと言ったことに賛成します。しかし、時にはそれが避けられないこともあります (特定のスタイルを主張する他の人と作業している場合など)。そこで、あなたが望むところに到達できるようにお手伝いします。

このソリューションでは、完全な [二重] 下線 (MWE のプレーン ソリューションの場合と同様) を使用できますが、参照用の代替オプションも提供されます。

\section{...}と を通常どおり引き続き使用できるように、再定義しました\section*{...}。ただし、TOC 行を変更する代わりに、オプションの引数が参照に使用されます。

\section[{[ref]}]{Title}
\section[\cite{articleABC}]{Title}

適切な再定義を行った完全な例:

\documentclass[12pt]{article}
\usepackage{sectsty}
\usepackage[normalem]{ulem}
\usepackage{showframe} % For illustration

% Add reference functionality
\makeatletter
\sectionfont{\ulemheading{\uuline}}
\let\oldsection\section
\def\section{\@ifstar\s@section\@section}
\newcommand{\@section}[2][\relax]{\oldsection{\llap{\rlap{\hspace{\textwidth}\llap{#1}}\protect\phantom{\thesection\quad}}#2}}
\newcommand{\s@section}[2][\relax]{\oldsection*{\llap{\rlap{\hspace{\textwidth}\llap{#1}}}#2}}
\makeatother

\begin{document}
    \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
    \setcounter{section}{100}
    \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
\end{document}

これにより、次のセクションが作成されます。

例

答え2

これにより、セクション ヘッダーに下線が引かれますが、番号は通常のままです。

\documentclass[12pt]{article}
\usepackage[normalem]{ulem}

\begin{document}
    \section{\uuline{Section Title}\hfill [Ref]}
\end{document}

関連情報