# number equations according to subsections but do not display subsections without numbers

I wish to number my equations according to their (sub)section so when I reference them it shows for example (1.1) but my sections and subsections should not display their number so the section should look like "SECTION" and not "1 SECTION" as well as the subsections that should look like "SUBSECTION" and not "1.1 SUBSECTION" this is my current code that does not show the numbers but does not number the equations as wished:

\documentclass[pdftex,10pt,a4paper]{article}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]
{geometry}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{dcolumn}
\usepackage[english]{babel}
\usepackage{siunitx}
\usepackage{mhchem}

%Command to not display numbers of sections and subsections...
\makeatletter
\renewcommand\thesection{}
\renewcommand\thesubsection{}
\renewcommand\thesubsubsection{}
\makeatother
% command to number equations according to the their sections
\numberwithin{equation}{section}

\begin{document}

\section{Introduction}
\subsubsection{Theoretical principles}
here comes some text and the first reference \eqref{eq:lnpp0} the text goes on
then the first eqation is implemented.

$$\label{eq:lnpp0} \mathrm{ln} \dfrac{p}{p_0} \, = \, \dfrac{\Delta_\mathrm{v}H}{R}\left( \dfrac{1}{T_0}-\dfrac{1}{T}\right)$$

Rearranging the equation the formula gives you $\Delta_\mathrm{v}H$
for the enthalpy of vaporization which can be used to
determine the entropy of vaporization:

$$\label{eq:deltaS} \Delta_\mathrm{v}S\,=\, \dfrac{\Delta_\mathrm{v}H}{T}$$

\section{The second section}

This is the equation i want to reference to \eqref{eq:lnpp0}

\end{document}


This code does not display the numbers of the sections and subsections (as wished) but does not properly number the equations, numbers them (.1) instead of (1.1)

PS: this is my first question so I'm happy about comments for further improvement of my "asking-style"

• Hi and welcome, if you refer to equation 5.4, how is the reader supposed to know where section five is? – Johannes_B Dec 10 '14 at 14:01
• The counting you want is standard for classes with chapters (report and book) that means for longer works like different thesis or whole books. Articles are usually for stuff of a few pages. – Johannes_B Dec 10 '14 at 14:03
• I am very well aware of the confusion this can cause but since my tutor wishes that the sections and subsections are not numbered but my equations should be... – daveid Dec 10 '14 at 14:19
• Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – user11232 Dec 10 '14 at 15:06
• Welcome to TeX.SX! Usually, we don't put a greeting or a “thank you” in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Accepting and upvoting answers is the preferred way here to say “thank you” to users who helped you. – Martin Schröder Dec 10 '14 at 19:08

You should not redefine thesection etc in to nothing. But redefine the sectional levels using titlesec

\usepackage{titlesec}
\titleformat{\section}
{\normalfont\Large\bfseries}{}{0em}{}
\titleformat{\subsection}
{\normalfont\large\bfseries}{}{0em}{}
\titleformat{\subsubsection}
{\normalfont\normalsize\bfseries}{}{0em}{}
\titleformat{\paragraph}[runin]
{\normalfont\normalsize\bfseries}{}{0em}{}
\titleformat{\subparagraph}[runin]
{\normalfont\normalsize\bfseries}{}{0em}{}


I have re-defined all levels for your reference so that no level shows the number.

With this in preamble we get

Full code:

\documentclass[10pt,a4paper]{article}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]
{geometry}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{dcolumn}
\usepackage[english]{babel}
\usepackage{siunitx}
\usepackage{mhchem}

%Command to not display numbers of sections and subsections...
\usepackage{titlesec}
\titleformat{\section}
{\normalfont\Large\bfseries}{}{0em}{}
\titleformat{\subsection}
{\normalfont\large\bfseries}{}{0em}{}
\titleformat{\subsubsection}
{\normalfont\normalsize\bfseries}{}{0em}{}
\titleformat{\paragraph}[runin]
{\normalfont\normalsize\bfseries}{}{0em}{}
\titleformat{\subparagraph}[runin]
{\normalfont\normalsize\bfseries}{}{0em}{}
% command to number equations according to the their sections
\numberwithin{equation}{section}

\begin{document}

\section{Introduction}
\subsubsection{Theoretical principles}
here comes some text and the first reference \eqref{eq:lnpp0} the text goes on
then the first eqation is implemented.

$$\label{eq:lnpp0} \mathrm{ln} \dfrac{p}{p_0} \, = \, \dfrac{\Delta_\mathrm{v}H}{R}\left( \dfrac{1}{T_0}-\dfrac{1}{T}\right)$$

Rearranging the equation the formula gives you $\Delta_\mathrm{v}H$
for the enthalpy of vaporization which can be used to
determine the entropy of vaporization:

$$\label{eq:deltaS} \Delta_\mathrm{v}S\,=\, \dfrac{\Delta_\mathrm{v}H}{T}$$

\section{The second section}

This is the equation i want to reference to \eqref{eq:lnpp0}

\end{document}

• Thanks a lot for the quick answer I know this is not ideal but I'm not making it because I want to but because I have to because of my tutor/ practicumsleader – daveid Dec 10 '14 at 14:20
• @daveid I can understand. :-) – user11232 Dec 10 '14 at 14:28
• Too complicated. ;-) – egreg Dec 10 '14 at 15:34
• @egreg For TeX users :-) Some day some mentor will need to number only the subsection, then this may be handy ;). World is strange with odd requirements! – user11232 Dec 10 '14 at 23:00

No need for extra packages. The printing of section numbers is performed by the internal command \@seccntformat. If we redefine it to do nothing, the number will not appear.

\documentclass[10pt,a4paper]{article}

\usepackage{amsmath}

%Command to not display numbers of sections and subsections...
\makeatletter
\renewcommand{\@seccntformat}[1]{}
\makeatother
% command to number equations according to the their sections
\numberwithin{equation}{section}

\begin{document}

\section{Introduction}
\subsubsection{Theoretical principles}
here comes some text and the first reference \eqref{eq:lnpp0} the text goes on
then the first equation is implemented.
$$\label{eq:lnpp0} \ln\frac{p}{p_0} =\frac{\Delta_{\mathrm{v}}H}{R}\left( \frac{1}{T_0}-\frac{1}{T}\right)$$
Rearranging the equation the formula gives you $\Delta_\mathrm{v}H$
for the enthalpy of vaporization which can be used to
determine the entropy of vaporization:
$$\label{eq:deltaS} \Delta_{\mathrm{v}}S=\frac{\Delta_{\mathrm{v}}H}{T}$$

\section{The second section}

This is the equation I want to reference to \eqref{eq:lnpp0}

\end{document}


I left only amsmath, as the other packages aren't needed for the example (but you can of course add them for your document).

Some points to note.

1. \mathrm{ln} is wrong and it should be \ln.

2. Use braces around subscripts: \Delta_{\mathrm{v}}.

3. The command \dfrac is seldom needed, prefer \frac unless you really need the big version in places where it would be printed smaller.

4. Never leave a blank line before equation. A blank line after it is allowed, provided the text after the equation is a new paragraph.

5. Never use the pdftex option: only a few packages, not in common usage, need it.