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*{...}但現在,不再更改目錄行,而是使用可選參數作為參考:

\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}

相關內容