有什么方法可以让“分段”命令(\section
\subsection
等)创建自动地带有指定符号的链接至其父节项?
如下图所示
上述代码的底层
\documentclass{article}
\usepackage{lipsum}
\begin{document}
\section{Section 1}
\lipsum[66]
\subsection{Foo}
\subsubsection{Smaller 1}
\lipsum[66]
\subsubsection{Smaller 2}
\lipsum[66]
\subsection{Bar}
Some text.
\end{document}
答案1
请注意,hyperref 已经为每个部分、小节等提供了目标。唯一棘手的一点是\subsection
(例如)实际上并不处理标题,而只是将其传递给\@startsection
。
\documentclass{article}
\usepackage{fontawesome}
\usepackage{hyperref}
\usepackage{lipsum}
\let\oldsubsection=\subsection
\renewcommand{\subsection}[2][\empty]{% #1 = short tietle (optional), #2 = title
\ifx\empty#1\relax
\oldsubsection[#2]{#2~\hyperlink{section.\thesection}{\faPaperclip}}
\else
\oldsubsection[#1]{#2~\hyperlink{section.\thesection}{\faPaperclip}}
\fi}
\let\oldsubsubsection=\subsubsection
\renewcommand{\subsubsection}[2][\empty]{% #1 = short tietle (optional), #2 = title
\ifx\empty#1\relax
\oldsubsubsection[#2]{#2~\hyperlink{subsection.\thesubsection}{\faPaperclip}}
\else
\oldsubsubsection[#1]{#2~\hyperlink{subsection.\thesubsection}{\faPaperclip}}
\fi}
\begin{document}
\section{Section 1}
\lipsum[66]
\subsection{Foo}
\subsubsection{Smaller 1}
\lipsum[66]
\subsubsection{Smaller 2}
\lipsum[66]
\subsection{Bar}
Some text.
\end{document}
答案2
当然有可能。TeX 是图灵完备的。