[Tex/LaTex] Showing unnumbered sections in header using two different layouts in fancyhdr

fancyhdrheader-footersectioning

I use two header layouts – first of introductions and second for dictionary. I want ot set the unnumbered sections headings into header in the first header together with page number. Minimal example follows:

\documentclass[twocolumn]{book}
\usepackage[top=2cm, bottom=2cm, left=2cm, right=2cm]{geometry}
\usepackage{fancyhdr}
\usepackage[icelandic, czech, english]{babel}
\usepackage[utf8x, utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{blindtext}
\usepackage{hanging}
\usepackage{tipa}
\newcommand{\entry}[2]{\hangpara{2em}{1}\textsf{\textbf{#1}}\ #2\markboth{#1}{#1}\par}\nopagebreak[4]
\newcommand*{\dictchar}[1]{\centerline{\LARGE\textbf{#1}}\par}
\fancypagestyle{basicstyle}{%
\fancyhf{}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0pt}}
\fancypagestyle{dictstyle}{%
\fancyhf{}
\fancyhead[LE,RO]{\textsf{\textbf{\rightmark\ -- \leftmark}}}
\fancyhead[LO,RE]{\textsf{\textbf{\thepage}}}}
\begin{document}

\pagestyle{basicstyle}
\chapter*{1. Průvodce po slovníku}
\clearpage
\section*{1. Heslové slovo}
\subsection*{1.1 Řazení slov }
\blindtext

\pagestyle{dictstyle}
\chapter*{3. Islandsko-český studijní slovník}
\clearpage
\entry{{a.n.}}{{\small{ zkr}}{\textsl{\textbf{að eðan}}}\foreignlanguage{czech}{{ pod, dole}}}
\entry{{afl··vak|i}}{{\textipa{[{a}{\textsubring{b}}{\textsubring{l}}{v}{a}{\r{\textObardotlessj}}{\textsci}]}}{\small{ m}}{\small{ (-a, -ar)}}\foreignlanguage{czech}{{ hnací síla, motiv}}}
\entry{{af··|segja}}{{\textipa{[{a}{f}{s}{ei}{j}{a}]}}{\small{ v}}{\small{ (-sagði, -sagt)}}{\small{ acc}}{\textit{ (neita)}}\foreignlanguage{czech}{{ odmítnout}}}
\end{document}

How can I change the basicstyle so that it shows unnumbered sections with page numbers?

Best Answer

This manual numbering looks a bit odd:

\chapter*{1. Průvodce po slovníku}
\section*{1. Heslové slovo}
\subsection*{1.1 Řazení slov}

You typeset a book, a dictionary, which could contain many sections and subsections. If you insert or remove a section or subsection, you would have to modify all following numbers manually. Also, it could easily lead to numbering mistakes. LaTeX could do it for you automatically. Just use the unstarred commands, let LaTeX do the numbering.

\chapter{Průvodce po slovníku}
\section{Heslové slovo}
\subsection{Řazení slov}

This also solves the problem of header markers: \chapter and \section produce entries for the header automatically, by \markboth or \markright, respectively, the starred versions don't. However, if you insist on starred versions, you could call \markboth or \markright yourself.

Furthermore, if basicstyle pages should show sections and page numbers, use such \fancyhead commands within \fancypagestyle{basicstyle}{...}, with \rightmark and \leftmark which contain the title values.

As discussed in the comments,here's a full example with your own heading marks.

\documentclass{book}
\usepackage{fancyhdr}
\fancypagestyle{basicstyle}{%
  \fancyhf{}
  \fancyfoot[C]{\thepage}
  \renewcommand{\headrulewidth}{0.4pt}
  \renewcommand{\footrulewidth}{0pt}
  \fancyhead[LE,RO]{\textsf{\textbf{\chaptitle\ -- \sectitle}}}
  \fancyhead[LO,RE]{\textsf{\textbf{\thepage}}}}
\pagestyle{basicstyle}
\newcommand*{\sectitle}{}
\renewcommand*{\sectionmark}[1]{%
    \renewcommand*{\sectitle}{#1}}
\newcommand*{\chaptitle}{}
\renewcommand*{\chaptermark}[1]{%
    \renewcommand*{\chaptitle}{#1}}
\begin{document}
\chapter{Průvodce po slovníku}
\clearpage
\section{Heslové slovo}
\subsection{Řazení slov }
text
\end{document}
Related Question