16

I think the following sample says it all. I need to get the item bullet in the right place on the same line as the equation, and have this followed by an normal equation number. Someone asked the same question but the answers all give one of the undesired results exhibited below. This problem crops up a lot if you are writing lists of conditions and some need a text Preamble while some are just equations. Thanks for any help anyone can offer.

\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}

enter image description here

11

The following example defines \itemequation that sets an \item with a simulated equation. The equation is centered in the same way as it would be done by environment equation. Also text can be added in front of the 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}

Result

With long text before equation

The following variation centers the equation in the remaining space, if the text before the equation is too long:

\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}

Result with long text before equation

| improve this answer | |
  • Is it possible to make the last itemequation, \itemequation{Same as eq. (\ref{eq:second}): }{2+2=4}, push the equation to the right in case the text to the left is too long? When you put a long text, the text overlaps the equation. – Saud Jun 9 '16 at 8:47
  • 1
    @Saud See updated answer. – Heiko Oberdiek Jun 9 '16 at 17:39
6

Here's a manual not-too-hacky way:

enter image description here

\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}
| improve this answer | |
  • Many thanks for your quick help! Both of these excellent answers solve my problem. I'll try this. – confused physicist Aug 21 '13 at 17:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.