I don't know the error message, so I cannot say, why \leftmark
does not work in your code. As usual a minimal working example would have been useful, to see what you've tried and why it does not work.
Usually it does work:
\documentclass{article}
\usepackage{fancyhdr}
\fancyhead[L]{\bfseries\leftmark}
\fancyhead[R]{\thepage}
\fancyfoot[C]{}
\renewcommand*{\headrulewidth}{0pt}
\renewcommand*{\sectionmark}[1]{\markboth{Section~\thesection.~#1}{}}
\pagestyle{fancy}
\usepackage{mwe}
\begin{document}
\blinddocument
\end{document}
But as an alternative, using scrlayer-scrpage
you don't need it in this case:
\documentclass{article}
\usepackage[automark,markcase=used]{scrlayer-scrpage}
\renewcommand*{\sectionmarkformat}{Section~\thesection.~}% Format of the number
\setkomafont{pageheadfoot}{\bfseries}% Don't use slant, but bold
\usepackage{mwe}
\begin{document}
\blinddocument
\end{document}
In other cases, you could simply use \headmark
with scrlayer-scrpage
.
Both examples with the same result:
With fancyhdr
also \rightmark
could be correct:
\documentclass{article}
\usepackage{fancyhdr}
\fancyhead[L]{\bfseries\rightmark}
\fancyhead[R]{\thepage}
\fancyfoot[C]{}
\renewcommand*{\headrulewidth}{0pt}
\renewcommand*{\sectionmark}[1]{\markright{Section~\thesection.~#1}}
\pagestyle{fancy}
\usepackage{mwe}
\begin{document}
\blinddocument
\end{document}
Whether \leftmark
or \rightmark
should be used, depends on the expected result with more than one \section
on the same page.