微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Latex:在节名称中使用自定义计数器时,名称引用不正确

如何解决Latex:在节名称中使用自定义计数器时,名称引用不正确

当部分名称基于自定义计数器(带有 \newcounter)时,\nameref 文本不是好的。

下面是一个简单的例子:

\documentclass{article}
\usepackage{nameref}
\usepackage{hyperref}
\hypersetup{hidelinks,colorlinks=true,linkcolor=blue}

\begin{document}
    \newcounter{my.counter}

\section{Section \arabic{my.counter}}
    \label{sct\arabic{my.counter}}
    Content of section \arabic{my.counter}.
    \begin{verbatim}
        \nameref{sct1}
    \end{verbatim}
    \nameref{sct1}

\stepcounter{my.counter}
\section{Section \arabic{my.counter}}\label{sct\arabic{my.counter}}
    \begin{verbatim}
        \nameref{sct0}
    \end{verbatim}
    \nameref{sct0}.

\end{document}

结果是:

example of improper PDF

这个例子是在背页上编译的,以避免“配置”问题。

解决方法

您可以使用 \GetTitleStringSetup{expand} 确保您的标题得到扩展:

\documentclass{article}
\usepackage{nameref}
\usepackage{hyperref}
\hypersetup{hidelinks,colorlinks=true,linkcolor=blue}


\GetTitleStringSetup{expand}

\begin{document}
    \newcounter{my.counter}

\section{Section \arabic{my.counter}}
    \label{sct\arabic{my.counter}}
    Content of section \arabic{my.counter}.
    \begin{verbatim}
        \nameref{sct1}
    \end{verbatim}
    \nameref{sct1}

\stepcounter{my.counter}
\section{Section \arabic{my.counter}}\label{sct\arabic{my.counter}}
    \begin{verbatim}
        \nameref{sct0}
    \end{verbatim}
    \nameref{sct0}.

\end{document}

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。