Hyperref 为自定义方程引用添加水平空间

Hyperref 为自定义方程引用添加水平空间

hyperref使用包时,

  • Equation (Section#-Equation#)

变成

  • Equation ( Section#-Equation#)

我很难缩小超链接添加空间的方式。

平均能量损失

\documentclass{scrartcl}

\usepackage{geometry}                   % margin/page layout settings
\usepackage{scrlayer-scrpage}           % improved header commands. [supercedes `fancyhdr' package].

\usepackage{mathtools}                  % includes amsmath, supplements it.
\usepackage{chngcntr}                   % allows changing equation section depth mid-document
\usepackage{etoolbox}

\usepackage[hidelinks]{hyperref}

% Margin Settings:
\KOMAoptions{fontsize   = 12pt    ,
             parskip    = half-   ,
             headheight = 1.000em , 
             footheight = 2.700em , 
             DIV        = current }

\geometry{letterpaper              ,
          hmargin      = 0.750in   ,
          tmargin      = 0.750in   ,
          bmargin      = 0.750in   ,
          headsep      = 1.000em   ,
          footskip     = 3.700em   } % [ = Footheight + Footsep]


%Initialize headers and footers
\chead{\normalfont Header 1 \\ Header 2}
\cfoot{\normalfont Footer 1 \\ Footer 2}
\ofoot{\normalfont Page \thepage}


% Section numbering: Format \paragraph like \subsection
\newcommand{   \subsubsubsection} [1] {    \paragraph{#1} }
\newcommand{\subsubsubsubsection} [1] { \subparagraph{#1} }

\setcounter{secnumdepth}{5}

\makeatletter
\renewcommand{\paragraph}               %
  {\@startsection{paragraph}{4}{\z@}    %
  {-2.5ex\@plus -1ex \@minus -.25ex}    %
  {1.25ex \@plus .25ex}                 %
  {\normalfont\sffamily\normalsize\bfseries}     }

\renewcommand{\subparagraph}               %
  {\@startsection{subparagraph}{4}{\z@}    %
  {-2.5ex\@plus -1ex \@minus -.25ex}    %
  {1.25ex \@plus .25ex}                 %
  {\normalfont\sffamily\normalsize\bfseries}     }

\makeatother




\let\origtheequation\theequation

% Equation Numbering
\counterwithin*{equation}{section}       % Reset equation at \section
\counterwithin*{equation}{subsection}    % Reset equation at \subsection
\counterwithin*{equation}{subsubsection} % Reset equation at \subsubsection
\counterwithin*{equation}{paragraph}     % Reset equation at \paragraph
\counterwithin*{equation}{subparagraph}  % Reset equation at \subparagraph

\newcommand{\xequationFormat} {\determineSection-\arabic{equation}}
\newcommand{\determineSection}{
  \ifnum\value{subsection}    > 0
  \ifnum\value{subsubsection} > 0
  \ifnum\value{paragraph}     > 0
  \ifnum\value{subparagraph}  > 0 \thesubparagraph
  \else                           \theparagraph      \fi
  \else                           \thesubsubsection  \fi
  \else                           \thesubsection     \fi
  \else                           \thesection        \fi
}




\begin{document}

\setcounter{section}{-1}
\let\theequation\origtheequation

\section{Level 1}
\begin{equation} x \label{level-0.1a} \end{equation}
\begin{equation} x \label{level-0.1b} \end{equation}
\subsection{Level 2}
\begin{equation} x \label{level-0.2a} \end{equation}
\begin{equation} x \label{level-0.2b} \end{equation}
\subsubsection{Level 3}
\begin{equation} x \label{level-0.3a} \end{equation}
\begin{equation} x \label{level-0.3b} \end{equation}
\subsubsubsection{Level 4}
\begin{equation} x \label{level-0.4a} \end{equation}
\begin{equation} x \label{level-0.4b} \end{equation}
\subparagraph{Level 5}
\begin{equation} x \label{level-0.5a} \end{equation}
\begin{equation} x \label{level-0.5b} \end{equation}

Equation~\eqref{level-0.1a}\\
Equation~\eqref{level-0.2a}\\
Equation~\eqref{level-0.3a}\\
Equation~\eqref{level-0.4a}\\
Equation~\eqref{level-0.5a}

\clearpage

\let\theequation\xequationFormat

\section{Level 1}
\begin{equation} x \label{level-1.1a} \end{equation}
\begin{equation} x \label{level-1.1b} \end{equation}
\subsection{Level 2}
\begin{equation} x \label{level-1.2a} \end{equation}
\begin{equation} x \label{level-1.2b} \end{equation}
\subsubsection{Level 3}
\begin{equation} x \label{level-1.3a} \end{equation}
\begin{equation} x \label{level-1.3b} \end{equation}
\subsubsubsection{Level 4}
\begin{equation} x \label{level-1.4a} \end{equation}
\begin{equation} x \label{level-1.4b} \end{equation}
\subparagraph{Level 5}
\begin{equation} x \label{level-1.5a} \end{equation}
\begin{equation} x \label{level-1.5b} \end{equation}

Equation~\eqref{level-1.1a}\\
Equation~\eqref{level-1.2a}\\
Equation~\eqref{level-1.3a}\\
Equation~\eqref{level-1.4a}\\
Equation~\eqref{level-1.5a}

\clearpage

\section{Level 1}
\begin{equation} x \label{level-2.1a} \end{equation}
\begin{equation} x \label{level-2.1b} \end{equation}
\subsection{Level 2}
\begin{equation} x \label{level-2.2a} \end{equation}
\begin{equation} x \label{level-2.2b} \end{equation}
\subsubsection{Level 3}
\begin{equation} x \label{level-2.3a} \end{equation}
\begin{equation} x \label{level-2.3b} \end{equation}
\subsubsubsection{Level 4}
\begin{equation} x \label{level-2.4a} \end{equation}
\begin{equation} x \label{level-2.4b} \end{equation}
\subparagraph{Level 5}
\begin{equation} x \label{level-2.5a} \end{equation}
\begin{equation} x \label{level-2.5b} \end{equation}

Equation~\eqref{level-2.1a}\\
Equation~\eqref{level-2.2a}\\
Equation~\eqref{level-2.3a}\\
Equation~\eqref{level-2.4a}\\
Equation~\eqref{level-2.5a}

\end{document}

答案1

有一个不受保护的行尾:

\newcommand{\determineSection}{% <----- THIS ONE
  \ifnum\value{subsection}    > 0
  \ifnum\value{subsubsection} > 0
  \ifnum\value{paragraph}     > 0
  \ifnum\value{subparagraph}  > 0 \thesubparagraph
  \else                           \theparagraph      \fi
  \else                           \thesubsubsection  \fi
  \else                           \thesubsection     \fi
  \else                           \thesection        \fi
}

不过,我会将其编码为

\newcommand{\determineSection}{% <----- THIS ONE
  \ifnum\value{subsection} > 0
    \ifnum\value{subsubsection} > 0
      \ifnum\value{paragraph} > 0
        \ifnum\value{subparagraph} > 0
          \thesubparagraph
        \else
          \theparagraph
        \fi
      \else
        \thesubsubsection
      \fi
    \else
      \thesubsection
    \fi
  \else
    \thesection
  \fi
}

在我看来,这更清楚地显示了嵌套。

您的编码风格将会给您带来一些不受保护的空间。

相关内容