平均能量损失

平均能量损失

平均能量损失

\documentclass{article}
\usepackage{appendix}
\usepackage{lipsum}
\usepackage[colorlinks]{hyperref}

\def\sectionautorefname{Section} 
\def\subsectionautorefname{Section} 
\def\appendixautorefname{Appendix}

\begin{document}

First appendix section: \autoref{app sec} 

First appendix subsection: \autoref{app sub}

\appendix
\appendixpage
\section{First appendix section}\label{app sec}
\subsection{First appendix subsection}\label{app sub}
\lipsum[1]

\end{document}

输出

在此处输入图片描述

问题

有可能\autoref小节在附录中以 的形式出现Appendix A.1,而不是Section A.1(如 MWE 中所示)?

我知道cleveref解决方案这个帖子。但是,如果可能的话,我想要一个只涉及hyperref包的解决方案。

答案1

下面将附录名称应用于位于环境之下\appendixsubappendices环境中的所有节类型标签。示例代码的一部分借用自“章节级”附录。我还添加了一些引用的方程式,以表明这些方程式应保留其通常的名称。需要注意的是,在使用环境时,appendices您还需要添加\appendix

\documentclass{article}
\usepackage{appendix}
\usepackage{lipsum}
\usepackage{geometry}
\usepackage[colorlinks]{hyperref}

\def\sectionautorefname{Section}
\def\subsectionautorefname{Section}
\def\appendixautorefname{Appendix}

% begin appendix autoref patch [\autoref subsections in appendix](https://tex.stackexchange.com/questions/149807/autoref-subsections-in-appendix)
\usepackage{etoolbox}
\makeatletter
\patchcmd{\hyper@makecurrent}{%
    \ifx\Hy@param\Hy@chapterstring
        \let\Hy@param\Hy@chapapp
    \fi
}{%
    \iftoggle{inappendix}{%true-branch
        % list the names of all sectioning counters here
        \@checkappendixparam{chapter}%
        \@checkappendixparam{section}%
        \@checkappendixparam{subsection}%
        \@checkappendixparam{subsubsection}%
        \@checkappendixparam{paragraph}%
        \@checkappendixparam{subparagraph}%
    }{}%
}{}{\errmessage{failed to patch}}

\newcommand*{\@checkappendixparam}[1]{%
    \def\@checkappendixparamtmp{#1}%
    \ifx\Hy@param\@checkappendixparamtmp
        \let\Hy@param\Hy@appendixstring
    \fi
}
\makeatletter

\newtoggle{inappendix}
\togglefalse{inappendix}

\apptocmd{\appendix}{\toggletrue{inappendix}}{}{\errmessage{failed to patch}}
\apptocmd{\subappendices}{\toggletrue{inappendix}}{}{\errmessage{failed to patch}}
% end appendix autoref patch




\begin{document}


First main section: \autoref{main sec} (sectionautorefname).

Subappendix: \autoref{sub}.

Second main section: \autoref{aftersub}.

First appendix section: \autoref{app sec} (appendixautorefname).

First appendix subsection: \autoref{app sub} (appendixautorefname).

Main equation: \autoref{eqn:main}.

Subappendix equation: \autoref{eqn:sub}.

Following equation: \autoref{eqn:aftersub}.

Appendix equation: \autoref{eqn:app}.


\section{foofirst}
\label{main sec}

\begin{equation}
a^2 + b^2 = c^2\label{eqn:main}
\end{equation}

\begin{subappendices}

\subsection{foofirstappendix}
\label{sub}

\begin{equation}
e = mc^2\label{eqn:sub}
\end{equation}

\end{subappendices}

\section{barfirst}
\label{aftersub}

\begin{equation}
g^2 + h^2 = i^2\label{eqn:aftersub}
\end{equation}

\appendix
\appendixpage
\section{First appendix section}\label{app sec}
\subsection{First appendix subsection}\label{app sub}
\lipsum[1]
\begin{equation} e=mc^2 \label{eqn:app} \end{equation}

\end{document}

输出

相关内容