同一方程式線上的兩個標籤

同一方程式線上的兩個標籤

我希望在同一行上有一組緊湊的兩個方程,每個方程都有標籤,兩個標籤都在最右邊。程式碼類似:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
We have
\begin{equation}
a = b \label{eqab} \quad \text{and} \quad c = d \label{eqcd}
\end{equation}
and equations \ref{eqab} and \ref{eqcd} are nice.
\end{document}

(原始碼行中標籤的位置並不重要),並且會顯示如下:

We have\vspace{3ex}

\hfill $a=b \quad \text{and} \quad c=d$ \hfill (1) and (2)\vspace{3ex}

and equations (1) and (2) are nice.

但是將兩個\label放在同一行會導致「Package amsmath 錯誤:

Multiple \label...` (the same for `\tag`).

答案1

也許您正在尋找這樣的東西:

在此輸入影像描述

\documentclass{article}
\usepackage{amsmath}

\usepackage[a4paper,showframe]{geometry}

\begin{document}
We have:

    \noindent\begin{minipage}{0.4\textwidth}
\begin{equation}
a = b \label{eqab}
\end{equation} 
    \end{minipage}%
    \begin{minipage}{0.2\textwidth}\centering
    and 
    \end{minipage}%
    \begin{minipage}{0.4\textwidth}
\begin{equation}
c = d \label{eqcd}
\end{equation}
    \end{minipage}\vskip1em

Equations \ref{eqab} and \ref{eqcd} are nice. The same is valid for the next two:

\begin{subequations}\label{eq:3}
    \noindent\begin{minipage}{0.4\textwidth}
\begin{equation}
a = b \label{eq:3a}
\end{equation}
    \end{minipage}%
    \begin{minipage}{0.2\textwidth}\centering
    and
    \end{minipage}%
    \begin{minipage}{0.4\textwidth}
\begin{equation}
c = d \label{eq:3b}
\end{equation}
    \end{minipage}\vskip1em
\end{subequations}

which are  \ref{eq:3a} and \ref{eq:3b}.
    \end{document}

答案2

\documentclass{article}
\usepackage{amsmath,tabularx}
\begin{document}
We have

\noindent
\begin{tabularx}{\linewidth}{XXX}
\begin{equation}
    a = b \label{eqab}
\end{equation}
& \[ \text{and} \] &
\begin{equation}
    c = d \label{eqcd}
\end{equation}
\end{tabularx}

and equations \ref{eqab} and \ref{eqcd} are nice.
\end{document}

在此輸入影像描述

答案3

這是預期的,因為它不是\label產生方程式編號的。

如果你確實想要在同一行上有兩個編號的方程式(我不鼓勵這樣做),你可以求助於迷你頁:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
We have
\begin{center}
\begin{minipage}[b]{.3\textwidth}
\vspace{-\baselineskip}
\begin{equation}
a = b \label{eqab}
\end{equation}
\end{minipage}%
\hfill\hfill and\hfill
\begin{minipage}[b]{.3\textwidth}
\vspace{-\baselineskip}
\begin{equation}
c = d \label{eqcd}
\end{equation}
\end{minipage}
\end{center}
and equations \ref{eqab} and \ref{eqcd} are nice.
\end{document}

在此輸入影像描述

答案4

Amsmath 可能會明確禁止方程式中出現多個宏\label,但這並不意味著不能建立另一個宏來執行相同的任務。注意:此版本與 hyperref 不相容。

\documentclass{report}
\usepackage{amsmath}

\makeatletter
\newcommand{\steplabel}[1]% #1 = label name
{\refstepcounter{equation}%
 \protected@write\@auxout{}{\string\newlabel{#1}{{\theequation}{\thepage}}}}
\makeatother

\begin{document}
We have
\begin{equation}
a=b \quad \text{and} \quad c=d
\tag*{\steplabel{eqab}(\theequation) and \steplabel{eqcd}(\theequation)}
\end{equation}
and equations \eqref{eqab} and \eqref{eqcd} are nice.
\end{document}

相關內容