[Tex/LaTex] how to add section number and name to the page header

fancyhdrheader-footer

I'm trying to modify the page layout of my thesis. I'd like to have at the top-right corner the section number and section title and at the top left corner the page number.

Using the following:

\usepackage{fancyhdr}

\begin{document}

\pagestyle{fancy}
\lhead{\thesection}
\chead{}
\rhead{\thepage}
\lfoot{}
\cfoot{}
\rfoot{}

I get what expected. However I'd like to add the section name. I've tried:

\pagestyle{fancy}
\lhead{\thesection}{thesectiontitle}
\chead{}
\rhead{\thepage}
\lfoot{}
\cfoot{}
\rfoot{}

but of course it didn't work. I think it requires a bit more of programming but I only have a basic Latex tutorial so far where I can't find useful information. Thank you in advance for any advice

Best Answer

(Based on an earlier comment.)

Adding this to the preamble

\renewcommand{\sectionmark}[1]{\markright{\thesection.\ #1}} 

and then changing \lhead in the following way

\lhead{\rightmark}

seems to have solved this problem.