# How to set counter for paragraphs in sections?

I want to counter paragraphs, always like x.y where x is section number and y is paragraph number in that section.

\documentclass[11pt, twocolumn, a4paper]{article}
\usepackage[left=1.5cm, text={18cm, 25cm}, top=2.5cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[IL2]{fontenc}
\usepackage[czech]{babel}
\usepackage{times}

\begin{document}
\section{A}
foo
\paragraph{Definition % 1.1 %}
here is definition 1.1 and i need to reference it later as 1.1
\section{B}
bar
\paragraph{Definition % 2.1 %}
\end{document}


Can anyone help please?

• Do you have \subsections? What about \subsubsections? What \documentclass are you using? Please provide the community with a minimal working example (MWE). – Werner Mar 26 '14 at 23:47
• \paragraph is defined to be the section level below \subsubsection It is possible to redefine things to lose subsection and subsection but it's a lot simpler to simply use them. – David Carlisle Mar 26 '14 at 23:52
• Consider using amsthm, and welcome to TeX.SX :) – Sean Allred Mar 27 '14 at 0:06
• @SeanAllred: ty! That was exactly what i needed. – Krab Mar 27 '14 at 0:31

## 2 Answers

Here are some options:

1. You can make \paragraph act in exactly the same way as \subsection by adding

\let\paragraph\subsection


to your document preamble. Or, simply use \subsection directly.

\documentclass{article}
\let\paragraph\subsection% Make \paragraph act just like \subsection
\begin{document}
\section{A}
foo
\paragraph{Definition}
Here is definition 1.1 and i need to reference it later as 1.1

\section{B}
bar
\subsection{Definition}

\end{document}

2. Adjust the way \paragraphs are number by adding

\renewcommand{\theparagraph}{\thesection.\arabic{paragraph}}% How paragraphs are numbered
\setcounter{secnumdepth}{4}% Number up to paragraphs


to your document preamble. The first command adjusts paragraphs to by numbered "like section"."paragraph". The second actually allows paragraphs to be numbered using the traditional sectional unit numbering condition.

\documentclass{article}
\renewcommand{\theparagraph}{\thesection.\arabic{paragraph}}% How paragraphs are numbered
\setcounter{secnumdepth}{4}% Number up to paragraphs
\begin{document}
\section{A}
foo
\paragraph{Definition}
Here is definition 1.1 and i need to reference it later as 1.1

\section{B}
bar
\subsection{C}
foo bar
\paragraph{Definition}
foo bar foo

\section{D}
foo bar foo bar
\subsection{E}
bar foo bar foo
\subsubsection{F}
foo bar foo bar foo
\paragraph{Definition}

\end{document}


The problem here is that you may confuse your readers if you mix \subsections and \paragraphs, since they are numbered similarly. Moreover, their numbering doesn't adjust with each section (for example, restarting). If you want them to restart, then consult Continuous v. per-chapter/section numbering of figures, tables, and other document elements. The suggestion there is to use

\usepackage{chngcntr}% http://ctan.org/pkg/chngcntr
\counterwithout{paragraph}{section}


Do this before redefining \theparagraph.

• this is not why i need, because if paragraph is in subsection, the counting is wrong. If the paragraph is anywhere, it must always have number section.paragraphNumberInThatSection – Krab Mar 27 '14 at 0:08
• @Krab: I've added something to that effect. However, I also mention why it seems problematic. – Werner Mar 27 '14 at 1:49

This is how to do it with the chngcntr package.

Note that you need a combination of two commands: \counterwithout*{paragraph}{subsubsection} tells LaTeX that you no longer want to reset the paragraph number when you start a new subsubsection (or any division greater than a subsubsection); \counterwithin*{paragraph}{section} tells it that you want to reset it at the beginning of a new section (or anything above it, such as a chapter in a book).

\documentclass{article}
\setcounter{secnumdepth}{4}
\renewcommand{\theparagraph}{\arabic{section}.\arabic{paragraph}}

\usepackage{chngcntr}
\counterwithout*{paragraph}{subsubsection}  %% stop resetting paragraph number with each new subsubsection
%\counterwithin*{paragraph}{section}        %% reset paragraph number for each section; only works with the preceding line!

\begin{document}
\section{Section}
\paragraph{Definition 1}\label{par:1.1}
\subsection{Subsection}
\paragraph{Definition 2}\label{par:1.2}
\subsubsection{Subsubsection}
\paragraph{Definition 3}\label{par:1.3}

\section{Section}
\paragraph{Definition 4}\label{par:2.1}
\subsection{Subsection}
\paragraph{Definition 5}\label{par:2.2}
\subsubsection{Subsubsection}
\paragraph{Definition 6}\label{par:2.3}~

Reference to 1.1: \ref{par:1.1}

Reference to 1.2: \ref{par:1.2}

Reference to 1.3: \ref{par:1.3}

Reference to 2.1: \ref{par:2.1}

Reference to 2.2: \ref{par:2.2}

Reference to 2.3: \ref{par:2.3}
\end{document}