6

I would like to number equations in the following way:

Chapter 1

x^2 + y^2 = z^2 (1.1)

x^3 + y^3 \neq z^3 (1.2)

Section 1.1

a^2 + b^2 = c^2 (1.1.1)

\sqrt{-1} = - \sqrt{-1} (1.1.2)

etc.

Currently the best I can achieve is to have (1.0.1), (1.0.2), etc., before the first section in the chapter. Aesthetically I find the unnecessary 0's quite ugly. Is there a way to tidy it up?

MWE:

\documentclass{report}
\numberwithin{equation}{section}
\begin{document}

\chapter{First}
\begin{equation}
x^2 + y^2 = z^2
\end{equation}
\begin{equation}
x^3 + y^3 \neq z^3
\end{equation}

\section{Next}
\begin{equation}
a^2 + b^2 = c^2
\end{equation}
\begin{equation}
\sqrt{-1} = - \sqrt{-1}
\end{equation}

\end{document}
Mico
  • 506,678
Stromael
  • 185

1 Answers1

7

If the section counter is zero ... -> The additional level of chapter can be suppressed. Similar to https://tex.stackexchange.com/a/245988/124842 for sections.

You nedd \usepackage{amsmath} package for MWE.

So you can add to your preamble:

\numberwithin{equation}{section}
\renewcommand*{\theequation}{%
  \ifnum\value{section}=0 %
    \thechapter
  \else
    \thesection
  \fi
  .\arabic{equation}%
}

Solution:

enter image description here

MWE:

\documentclass{report}
\usepackage{amsmath}

\numberwithin{equation}{section}
\renewcommand*{\theequation}{%
  \ifnum\value{section}=0 %
    \thechapter
  \else
    \thesection
  \fi
  .\arabic{equation}%
}
\begin{document}

\chapter{First}
\begin{equation}
x^2 + y^2 = z^2
\end{equation}
\begin{equation}
x^3 + y^3 \neq z^3
\end{equation}

\section{Next}
\begin{equation}
a^2 + b^2 = c^2
\end{equation}
\begin{equation}
\sqrt{-1} = - \sqrt{-1}
\end{equation}

\end{document}
Bobyandbob
  • 4,899
  • Hi, How can you do the same, but in my case I want the numbering to be different in the appendix. for example I have in the chapter the equation (1.2.3), in the appendix I want (A.1), (A.2), etc independently on the section. – Oscar Feb 06 '18 at 22:39
  • 1
    @Oscar .My first guess is something like : \renewcommand{\thechapter}{A.\arabic{chapter}} after \appendix. Does it fit your problem? - General: If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. – Bobyandbob Feb 07 '18 at 15:32