3

How to make a numeration of the rows in the table(tabularx) automatically?

I have a table, and in the first column I have numbers of the rows, right now I just type this numbers manually, but is there is any command which can do it automatically?

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[russian]{babel}  % Включаем пакет для поддержки русского
\usepackage{multirow,tabularx}
\usepackage[a4paper,margin=1in,landscape]{geometry}

\begin{tabularx}{\textwidth}{ |X|X|X| }
\hline
№  & Характер работ & Ответственные лица \\ \hline
1.  & Покрасить стену & Иванов И.И. \\ \hline
2.  & Покрасить стену & Петров И.И. \\ \hline
3.  & Сидоров & Сидоров А.О. \\ \hline
\end{tabularx}

\end{document}

enter image description here

Lucky_girl
  • 1,365

1 Answers1

2

Here is a solution, with the etoolbox package. You can reference the rows.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T2A]{fontenc}
\usepackage[russian]{babel} % Включаем пакет для поддержки русского
\usepackage{multirow,tabularx}
\usepackage[a4paper,margin=1in,landscape]{geometry}
\usepackage{etoolbox}
\newcounter{rowcnt}
\newcommand\rownum{\ifnumequal{\value{rowcnt}}{0}{№}{\therowcnt.}\refstepcounter{rowcnt}}
\AtEndEnvironment{tabularx}{\setcounter{rowcnt}{0}}

\begin{document}
\renewcommand\arraystretch{1.333}
\begin{tabularx}{\textwidth}{ | >{\rownum}r|X|X| }
  \hline
    & Характер работ & Ответственные лица \\ \hline
    & Покрасить стену & Иванов И.И. \\ \hline
    & Покрасить стену & Петров И.И. \\ \hline
    & Сидоров & Сидоров А.О. \\ \hline
\end{tabularx}

\end{document} 

enter image description here

Bernard
  • 271,350