方程式、方程式编号和分项项目符号都在同一行

方程式、方程式编号和分项项目符号都在同一行

我认为下面的示例说明了一切。我需要将项目项目符号放在与方程式相同的行上的正确位置,并在其后跟一个正常的方程式编号。有人问了同样的问题,但答案都给出了下面所示的不想要的结果之一。如果您正在编写条件列表,并且有些需要文本序言而有些只是方程式,则会出现这个问题。感谢任何人提供的帮助。

\documentclass{article}
\begin{document}

\begin{itemize}
\item This item looks fine in terms of both number and bullet because the bullet sensibly appears on a line with some text on it, preceeding an equation like
\begin{equation}
2+2=4,
\end{equation}
but if there is no text in the item there is no way to get it right, for example
\item
\begin{equation}
2+2=4;
\end{equation}
The bullet is on the wrong line.
\item $\displaystyle 2+2=4;$ \\
No equation number.
\begin{equation}
\bullet \quad 2+2=4.
\end{equation}
Bullet in wrong position.
\end{itemize}
\end{document}

在此处输入图片描述

答案1

以下示例定义了\itemequation设置\item模拟方程的方程。方程的中心位置与环境的中心位置相同equation。还可以在方程前面添加文本。

\documentclass{article}

% \itemequation[label]{text before}{equation}
\makeatletter
\newcommand*{\itemequation}[3][]{%
  \item
  \begingroup
    \refstepcounter{equation}%
    \ifx\\#1\\%
    \else  
      \label{#1}%
    \fi
    \sbox0{#2}%
    \sbox2{$\displaystyle#3\m@th$}%
    \sbox4{\@eqnnum}%
    \dimen@=.5\dimexpr\linewidth-\wd2\relax
    % Warning for overlapping
    \ifcase
        \ifdim\wd0>\dimen@
          \z@
        \else
          \ifdim\wd4>\dimen@
            \z@
          \else 
            \@ne
          \fi 
        \fi
      \@latex@warning{Equation is too large}%
    \fi
    \noindent   
    \rlap{\copy0}%
    \rlap{\hbox to \linewidth{\hfill\copy2\hfill}}%
    \hbox to \linewidth{\hfill\copy4}%
    \hspace{0pt}% allow linebreak
  \endgroup
  \ignorespaces 
}
\makeatother  

\begin{document}

\begin{itemize}
\item Equation environment in next line for comparison:
  \begin{equation}2+2=4\end{equation}
\itemequation[eq:second]{}{2+2=4}
\itemequation{}{2+2=4}
  with text in the following line.
\itemequation{Same as eq. (\ref{eq:second}): }{2+2=4}
\end{itemize}   

\end{document}

结果

等式前有长文本

如果等式前的文本太长,则可以使用以下变体将等式置于剩余空间的中心:

\documentclass{article}

% \itemequation[label]{text before}{equation}
\makeatletter
\newcommand*{\itemequation}[3][]{%
  \item
  \begingroup
    \refstepcounter{equation}%
    \ifx\\#1\\%
    \else
      \label{#1}%
    \fi
    \sbox0{#2}%
    \sbox2{$\displaystyle#3\m@th$}%
    \sbox4{ \@eqnnum}%
    \dimen@=.5\dimexpr\linewidth-\wd2\relax
    % Warning for overlapping
    \let\CenterInSpace=N%
    \ifcase
        \ifdim\wd0>\dimen@
          \z@
        \else
          \ifdim\wd4>\dimen@
            \z@
          \else
            \@ne
          \fi
        \fi
      \let\CenterInSpace=Y%
    \fi
    \ifdim\dimexpr\wd0+\wd2+\wd4\relax>\linewidth
      \@latex@warning{Equation is too large}%
    \fi
    \noindent
    \rlap{\copy0}%
    \ifx\CenterInSpace Y%
      \rlap{\hbox to \linewidth{\kern\wd0\hss\copy2\hss\kern\wd4}}%
    \else
      \rlap{\hbox to \linewidth{\hfill\copy2\hfill}}%
    \fi
    \hbox to \linewidth{\hfill\copy4}%
    \hspace{0pt}% allow linebreak
  \endgroup
  \ignorespaces
}
\makeatother

\begin{document}

\begin{itemize}
\item Equation environment in next line for comparison:
  \begin{equation}2+2=4\end{equation}
\itemequation[eq:second]{}{2+2=4}
\itemequation{}{2+2=4}
  with text in the following line.
\itemequation{Same as eq. (\ref{eq:second}): }{2+2=4}
\itemequation{A very long text before the equation: }{2+2=4}
\end{itemize}
\end{document}

公式前有长文本的结果

答案2

这是一个手动的、不太复杂的方法:

在此处输入图片描述

\documentclass{article}
\begin{document}

\begin{itemize}
\item
  This item looks fine in terms of both number and bullet because 
  the bullet sensibly appears on a line with some text on it, 
  preceeding an equation like
  \begin{equation}
    2 + 2 = 4,
  \end{equation}
  but if there is no text in the item there is no way to get it right, for example

  \item
  \begin{equation}
    2 + 2 = 4;
  \end{equation}
  The bullet is on the wrong line.

  \item
  $\displaystyle 2+2=4;$ \\
  No equation number.
  \begin{equation}
    \bullet \quad 2 + 2 = 4.
  \end{equation}
  Bullet in wrong position. What about:

  \item \hfill%
    $2 + 2 = 4.$%
  \hfill\refstepcounter{equation}\textup{(\theequation)}%
\end{itemize}
\end{document}

相关内容