我更改了公式编号格式,以避免在没有子部分时出现 0。输出示例:
方程(1.1.a)
代替
方程(1.1.0.a)
但是现在,当我使用\ref
或\eqref
命令时,它们在括号前有额外的空格。输出示例:
(1.1.a)
代替
(1.1.a)
你有解决办法吗?
完整 Latex 示例:
\documentclass [11pt, twoside]{article}
\usepackage{amsmath}
\numberwithin{equation}{subsection}
\numberwithin{equation}{subsubsection}
\renewcommand{\theequation}{
\ifnum\value{subsubsection}=0
\thesubsection
\else
\thesubsubsection
\fi
.\alph{equation}
}
\begin{document}
\section{Section}
\subsection{Subsection}
\begin{equation}
equation = 1
\label{eq1}
\end{equation}
\subsubsection{Subsubsection}
\begin{equation}
equation = 2
\label{eq2}
\end{equation}
\subsection{Ref.}
Eqref for First equation \eqref{eq1}
Ref for Second equation (\ref{eq2})
\end{document}
输出 :
答案1
未受保护的行尾!请参阅
\renewcommand{\theequation}{% <--- HERE
\ifnum\value{subsubsection}=0
\thesubsection
\else
\thesubsubsection
\fi
.\alph{equation}% <--- HERE
}
答案2
请注意标有以下行的百分号here
:
\documentclass [11pt, twoside]{article}
\usepackage{amsmath}
\numberwithin{equation}{subsection}
\numberwithin{equation}{subsubsection}
\renewcommand{\theequation}{% here
\ifnum\value{subsubsection}=0
\thesubsection
\else
\thesubsubsection
\fi
.\alph{equation}% here
}
\begin{document}
\section{Section}
\subsection{Subsection}
\begin{equation}
equation = 1
\label{eq1}
\end{equation}
\subsubsection{Subsubsection}
\begin{equation}
equation = 2
\label{eq2}
\end{equation}
\subsection{Ref.}
Eqref for First equation \eqref{eq1}
Ref for Second equation (\ref{eq2})
\end{document}