sectsty
我曾经使用包将章节标题设置为大写\MakeUppercase
。但这在章节标题中使用引用时会出现问题。那么如何正确做到这一点呢?
这是一个简单的例子:
\documentclass{article}
\usepackage{nameref}
\usepackage{sectsty}
\sectionfont{\MakeUppercase}
\begin{document}
\begin{description}
\item [Keyword\label{key}] This is the description text.
\end{description}
\section{Here it does not work: \nameref{key}}
Here it works: \nameref{key}.
\end{document}
答案1
您需要一个可扩展的版本\nameref
。
\documentclass{article}
\usepackage{nameref}
\usepackage{sectsty}
\sectionfont{\MakeUppercase}
\makeatletter
\newcommand\enameref[1]{%
\expandafter\ifx\csname r@#1\endcsname\relax
??\typeout{^^JLaTeX Warning: Reference #1 undefined on input line \the\inputlineno}%
\else
\expandafter\expandafter\expandafter\@thirdoffive\csname r@#1\endcsname
\fi
}
\makeatother
\begin{document}
\begin{description}
\item [Keyword\label{key}] This is the description text.
\end{description}
\section{Here it does not work: \enameref{key}}
Here it works: \nameref{key}.
\end{document}