Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
Example is now compilable, sorry for delay. Can you show me how can I achieve that unnumbered section appears there? –  chejnik Oct 28 '11 at 11:41
add comment

1 Answer 1

up vote 3 down vote accepted

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}
share|improve this answer
    
I have tried to use \chapter and \section numbered but there is problem. The heading appears only on first page and later there appears headwords instead of chapter - because I use also examples of \entry in the first section. –  chejnik Oct 28 '11 at 12:08
    
You could set an use your own macros then, in \fancypagestyle{basicstyle}{...}. Such as \fancyhead[LE,RO]{\textsf{\textbf{\chaptitle -- \sectitle}}} and set those title macros by \renewcommand when needed, i.e. after \chapter or \section. –  Stefan Kottwitz Oct 28 '11 at 12:13
    
Can you set an example of \renewcommand for \section and should I place that renewcommand after each \section? –  chejnik Oct 28 '11 at 12:35
    
You could redefine \sectionmark, however it could also be done manually after each \section if desired. I added an example. –  Stefan Kottwitz Oct 28 '11 at 12:48
    
Thank you very much. It works. And I will study the example to understand how to use \renewcommand. –  chejnik Oct 28 '11 at 12:55
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.