8

I'm currently writing some math stuff in LaTeX and I've encountered the following problem: I'd like to have "shared" counters in equations and specific lists, s.t. for example

\begin{equation}
    a + b = c
\end{equation}
and additionally
\begin{mycoolenum}
    \item $c + d = e$
    \item $c - f = e$
\end{mycoolenum}

results in

(1.1)      a + b = c

and additionally
    (1.2) c + d = e
    (1.3) c + f = e

The reason why I want to do this is to have consistent reference names throughout my work. I've tried playing around with [resume] and the list enviornment but to no avail.

What it should kinda look like:

\documentclass{scrartcl}
\usepackage{amsmath}

\numberwithin{equation}{section}

\begin{document}
    \section{Section 1}
    \begin{equation}
        a + b = c
    \end{equation}
    \begin{list}{\theequation}{}
        \addtocounter{equation}{1}
        \item $c + d = e$
        \addtocounter{equation}{1}
        \item $c - f = e$
    \end{list}
    \begin{equation}
        1 + 1 = 2
    \end{equation}
\end{document}

EDIT: To clarify: I'm currently using flalign to somewhat imitate the desired behavior, but this has some disadvantages regarding both code and the final result.

  • why not just use an align for the list which isn't actually a list. – daleif Jun 25 '13 at 14:59
  • Sorry I forgot to add that: I am currently using flalign to somewhat imitate a list environment, the problem there is that there are quite a few differences in the "look" (e.g. the position of the labels, text-rich items look very funky in the code due to many \text commands) and it feels very hack-ish ;) – incaseoftrouble Jun 25 '13 at 15:02
  • Welcome to TeX.SX! Please add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – Marco Daniel Jun 25 '13 at 15:06
  • @Megge, perhaps you should structure your source better. If it is formulas, then treat them at formulas. Don't use homemade approximations just because it feels easier. E.g. don't write \text{ for all } x>0 \text{ and } y\pm 1. Write \qquad\text{for all $x>0$ and $y\pm1$}, then the structure is better and the entire for part is marked as extra information. Lots of users could benefit from structuring their source more appropriately. – daleif Jun 25 '13 at 15:15
  • Maybe I should give you an example use case, sorry! Lets say I have a theorem that says "Operator A has following properties under following assumptions", and I list them inside this enumeration. Later in the proof I want to write "with assumption (1.2) and equation (1.4) this and this follows". – incaseoftrouble Jun 25 '13 at 15:18
7

Use the equation counter for the enumerated list, just take care of not resetting it or, better, to set it at the correct value.

\documentclass{scrartcl}
\usepackage[leqno]{amsmath}

\numberwithin{equation}{section}
\newcounter{keepeqno}
\newenvironment{mycoolenum}
 {\setcounter{keepeqno}{\value{equation}}%
  \begin{list}{(\theequation)}{\usecounter{equation}}%
  \setcounter{equation}{\value{keepeqno}}}
 {\end{list}}

\begin{document}
\section{Section 1}
\begin{equation}
a + b = c
\end{equation}
\begin{mycoolenum}
\item $c + d = e$
\item $c - f = e$
\end{mycoolenum}
\begin{equation}
1 + 1 = 2
\end{equation}
\end{document}

enter image description here

0

After thinking about it again the solution was kinda obvious:

\documentclass{scrartcl}
\usepackage{amsmath}

\numberwithin{equation}{section}

\let\Item\item
\newenvironment{mlist}{\renewcommand{\item}{\refstepcounter{equation} \Item} \begin{list}{\theequation}{}}{\end{list}}

\begin{document}
    \section{Section 1}
    \begin{equation}
        a + b = c
    \end{equation}
    \begin{mlist}
        \item $c + d = e$
        \item $c - f = e$
    \end{mlist}
    \begin{equation}
        1 + 1 = 2
    \end{equation}
\end{document}

This gives the desired result.

  • 1
    With your current solution you can't nest list environments. I think the redefinition of item can be avoided if you use: \begin{list}{\refstepcounter{equation}\theequation}} – Marco Daniel Jun 25 '13 at 15:25
  • (I changed soemthing since you commented) The problem is that apparently the "\ref value" gets overridden by \item in your example, so references to "(2.1), (2.2), (2.3)" change to "(2.1), (2.1), (2.1)". \usecounter doesn't work either, as this resets the counter every call. With the current code it works, but I'm not sure how "clean" this is – incaseoftrouble Jun 25 '13 at 15:38
  • The issue is that the optional argument of item overwrites the behaviour of \refstepcounter. – Marco Daniel Jun 25 '13 at 16:20

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.