I'm using fancyhead and I wanted to include in headers number of section, which 1st word on the page belongs to:
\documentclass[leqno]{book}
\usepackage[utf8]{inputenc}
\usepackage{polski}
\usepackage{fancyhdr}
\usepackage{lipsum}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\chaptermark}[1]{ \markboth{#1}{} }
\renewcommand{\sectionmark}[1]{ \markright{#1}{} }
\pagestyle{fancy}
\fancyhead[LE]{\thepage}
\fancyhead[CE]{\thepart. \parttitle}
\fancyhead[RE]{[\thesubsection}
\fancyhead[LO]{\thesubsection]}
\fancyhead[CO]{\nouppercase{\rightmark}}
\fancyhead[RO]{\thepage}
\begin{document}
\setcounter{page}{5}
\setcounter{part}{1}
\setcounter{chapter}{3}
\setcounter{section}{4}
\section{first section}
\subsection{first subsection}
\lipsum[1]
\lipsum[1]
\lipsum[1]
\lipsum[1]\
\
that text comes from section 1 and should make header to [3.5.1
\subsection{second subsection}
that text comes from subsection 2 and changes header in the top right to [3.5.2 (supposed to be [3.5.1)
\end{document}

0.2 second sectioninstead of just0.2. – Werner Dec 01 '20 at 19:39