2

I like to have in the headings the chapter name on the inner upper section on almost all pages but not on those which start with the new chapter, on the tableofcontens and the index.

The page number should be written on every page on the top outer position except on titlepage, blank pages, table of contents.

Therefore I searched many hours to find an optimal solution. In my document I've encountered these problems with page numberings:

  • I don't like a page number in the TOC next to the entry "Anhang"
  • When I click to "Anhang" and "Stichwortverzeichnis" it opens correctly the specific pages. However when I click to "Glossar" I'm redirected to the wrong page.

  • I don't prefer the chapter reference "Inhaltsverzeichnis" and "Einleitung" on the headings of the pages from "Inhaltsverzeichnis", "Einleitung", "Anhang", "Glossar", "Stichwortverzeichnis" because it's already written in these pages once.

  • The page numbering is missing on the last two pages.

I use a combination of LyX and Texmaker under Windows 8, but probably want finally to change to Texmaker.

My used and shortened code:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
% LyX 2.1.0 created this file.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

\documentclass[twoside,ngerman,fontsize=10pt]{scrreprt}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage[a4paper]{geometry}
\geometry{verbose,tmargin=2.5cm,bmargin=2.5cm,lmargin=2.5cm,rmargin=2.5cm}
\pagestyle{empty}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\setlength{\parskip}{1em}
\setlength{\parindent}{0pt}
\synctex=-1
\usepackage{fancybox}
\usepackage{calc}
\PassOptionsToPackage{normalem}{ulem}
\usepackage{ulem}
\usepackage{nomencl}
\providecommand{\printnomenclature}{\printglossary}
\providecommand{\makenomenclature}{\makeglossary}
\makenomenclature
\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
% User specified LaTeX commands.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

%%%% Heading lines
\usepackage[headsepline, ilines,automark]{scrpage2}
\pagestyle{scrheadings}
\clearscrheadings 
\clearscrplain 
\ihead[\headmark]{\headmark}
\ohead{\pagemark}
\chead{}
\cfoot{}

%%%% Inhaltsverzeichnis!
\usepackage[colorlinks,pdfpagelabels,pdfstartview = FitH,bookmarksopen = true,bookmarksnumbered = true,linkcolor = black,plainpages = false,hypertexnames = false,citecolor = black] {hyperref}

\usepackage{fancybox}
\newcommand{\nobreakword}[1]{\mbox{#1}}
\usepackage{etoolbox}
\usepackage{makeidx}\makeindex
\makeatletter
\def\@idxitem{\par\addvspace{10\p@ \@plus 5\p@ \@minus 3\p@}\hangindent 40\p@}
\def\subitem{\par\hangindent 40\p@ \hspace*{20\p@}}
\def\subsubitem{\par\hangindent 40\p@ \hspace*{30\p@}}
\def\indexspace{}
\patchcmd\theindex{\indexname}{\indexname\vspace{12pt}}{}{}
\makeatother

%text before glossar!
\renewcommand{\nompreamble}{%
This text should be written for the entry Schokolade:

Lorem ipsum dolor sit amet,\\...consetetur sadipscing elitr,\\...sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,\\...no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, \\...no sea takimata sanctus est Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata\\...sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero \\...eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
\par}

\usepackage{babel}
\makenomenclature

\begin{document}

\newpage
\setcounter{page}{1}
\thispagestyle{empty} 
\begin{center}
\vspace*{10cm}
titlepage
\end{center}

\pagestyle{scrheadings}
\clearpage\pdfbookmark{\contentsname}{toc}\tableofcontents

\chapter{Einleitung}
In diesem Dokument geht es um Haustiere.
\chapter{Tiere}
Heute ass meine \index{Katze}Katze \nomenclature{Katze}{Haustier} Schokolade und musste daher zum \index{Tierarzt}Tierarzt. \nomenclature{Tiger}{Raubtier}
\nomenclature{Schokolade}{Lorem ipsum dolor sit amet,\\...consetetur sadipscing elitr,\\...sed diam}
%
\newpage
neue Seite
\newpage
neue Seite
\addpart{Anhang}
\pagestyle{empty} %ohne Seitenzahlen und Kolumnentitel
\addcontentsline{toc}{chapter}{Glossar}
\renewcommand{\nomname}{Glossar}
\printnomenclature[2.5 cm]
%
\clearpage 
\phantomsection 
\addcontentsline{toc}{chapter}{Stichwortverzeichnis} 
\renewcommand{\indexname}{Stichwortverzeichnis}
\printindex
%
\end{document}

I would be very glad if there is a solution, the headings with inner and outer is not obligatory if there is no exact solution I'm happy with a compromise.

3 Answers 3

3

This does most, but not quite all, of what you want. I hesitate to hack KOMA Script's code for the table of contents. Hence, this does not remove the page number from the ToC entry of parts. As far as I've understood them, it implements all the other desiderata stated in the question.

Insofar as is possible, I've used KOMA's facilities to implement your design. This includes ensuring that the index is included in the ToC, that paragraphs are distinguished by vertical space, and that the page layout is more-or-less as requested. This is done using a combination of package options, a command from typearea (for the layout dimensions) and commands from scrlayer-scrpage (for headers and footers). Note that your code contained a good number of obsolete and deprecated commands from old versions of KOMA Script. These have been replaced with current versions where necessary.

If you cannot use \maketitle for your title page, you should at least use the titlepage environment.

If you really need specified margins, you will have to use geometry. But doing so is not compatible with getting the most out of KOMA Script which specialises in laying out the page nicely. The code I give is not very good either, although it is better than using geometry with specified margins. The code below forces KOMA to use a type block of specified dimensions. This is not at all good because it breaks most of KOMA's attempts to make the layout look nice. However, it is not quite as bad as forcibly setting the margins because it still allows KOMA to use some of its facilities, albeit in a relatively small way.

You should definitely not set \parskip and \parindent manually. This will further screw up KOMA's calculations. Here, I've used an example setting as a class option. For other possibilities, see KOMA's documentation.

It would be better to leave the formatting of the index to KOMA, too. Again, unless you absolutely cannot do so. See the documentation for the ways in which this may be customised and for comments on the kinds of changes which are, and are not, consonant with the class.

Note that the upshot of my changes is that the code of your actual document is far cleaner than it was because much less explicit formatting is required. It is almost always best to change things at the document level. Fiddling with particular bits within the document is a recipe not only for inconsistency, but also for unexpected chaos when you least expect it! Mark-up within the document should be semantic whenever possible, and you should think twice about using non-semantic mark-up even when semantic mark-up is not possible.

\synctex=-1
\documentclass[twoside=semi,a4paper,latin,fontsize=10pt,headsepline,parskip=half-,index=totoc]{scrreprt}
% if you are required to have set margins because you are producing the document for a typographical ignoramus, then you will have to load geometry to force the margins (but leave a4paper as a class option). Pretty much all institutions qualify as typographical ignoramuses, unfortunately.
% The next line is far from ideal. It would be better to specify DIV=<integer> as a class option. But if you must have a type area of a specified size, this will work.
\areaset[0pt]{160mm}{247mm}% no binding correction, text width is 160mm, text height is 247mm; with twoside=semi, the margins will be set with a single-sided layout i.e. for symmetry, even though the document is double-sided.
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\usepackage[normalem]{ulem}
\usepackage{fancybox,calc,etoolbox,lipsum}
\usepackage[intoc]{nomencl}
\renewcommand{\nomname}{Glossar}
\makenomenclature
\usepackage{scrlayer-scrpage}% scrpage2 is obsolete
  \pagestyle{scrheadings}
  \clearpairofpagestyles% \clearscrheadings, \clearscrplain are deprecated
  \automark[chapter]{chapter}
%   \renewcommand*\chaptermarkformat{}% uncomment if you don't want chapter numbers in the headers
  \ihead[]{\headmark}
  \ohead[\pagemark]{\pagemark}
\usepackage[colorlinks,pdfpagelabels,pdfstartview = FitH,bookmarksopen = true,bookmarksnumbered = true,linkcolor = black,plainpages = false,hypertexnames = false,citecolor = black] {hyperref}

\newcommand{\nobreakword}[1]{\mbox{#1}}
\usepackage{makeidx}
\makeindex
\makeatletter
  \def\@idxitem{\par\addvspace{10\p@ \@plus 5\p@ \@minus 3\p@}\hangindent 40\p@}
  \def\subitem{\par\hangindent 40\p@ \hspace*{20\p@}}
  \def\subsubitem{\par\hangindent 40\p@ \hspace*{30\p@}}
  \def\indexspace{}
  \patchcmd\theindex{\indexname}{\indexname\vspace{12pt}}{}{}
\makeatother

%text before glossar!
\renewcommand{\nompreamble}{%
This text should be written for the entry Schokolade:

Lorem ipsum dolor sit amet,\\...consetetur sadipscing elitr,\\...sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,\\...no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, \\...no sea takimata sanctus est Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata\\...sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero \\...eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
\par}

\makenomenclature

\begin{document}
\begin{titlepage}% if you need a custom layout - otherwise, use \maketitle
  \centering
  \vspace*{10cm}
  titlepage
\end{titlepage}

\clearpage\pdfbookmark{\contentsname}{toc}
\tableofcontents\thispagestyle{empty}

\chapter{Einleitung}
\lipsum[1-20]

\chapter{Tiere}
\lipsum[21-25]
\index{Katze}Katze \nomenclature{Katze}{Haustier}
\lipsum[26]
\index{Tierarzt}Tierarzt
\nomenclature{Tiger}{Raubtier}
\nomenclature{Schokolade}{Lorem ipsum dolor sit amet,\\...consetetur sadipscing elitr,\\...sed diam}

\newpage
\lipsum[27]
\newpage
\lipsum[28-37]

\addpart{Anhang}

\printnomenclature[2.5 cm]

\renewcommand{\indexname}{Stichwortverzeichnis}
\printindex

\end{document}

KOMA layout

EDIT

To use the DIV=<integer> configuration, change the line loading the class to

\documentclass[twoside=semi,a4paper,latin,fontsize=10pt,headsepline,parskip=half-,index=totoc,DIV=15]{scrreprt}

and remove the \areaset line.

To change the page style for parts, add

\renewcommand*\partpagestyle{empty}

to the preamble. (I added it after setting \ohead.)

7
  • This looks very much better as my old code! I don't need the areaset. How can I apply DIV=<integer> in the code?
    – laminin
    Apr 7, 2015 at 11:40
  • The problem with the page numbering can be solved by exchanging \addpart{Anhang} with \newpage{} \thispagestyle{empty} \vspace*{\fill}\begin{center} \begin{Huge} Anhang \end{Huge} \vspace*{\fill}\end{center} \addtocontents{toc}{\textbf{\sffamily \textcolor{white}{empty line}}\protect\par} \addtocontents{toc}{\textbf{\sffamily \textcolor{white}{empty line}}\protect\par} \addtocontents{toc}{\textbf{\sffamily Anhang}\protect\par}
    – laminin
    Apr 7, 2015 at 11:41
  • @laminin See edit for answers to 2 of your questions. You can just change the page style for parts to empty in the preamble to get rid of page numbers on part pages. I'm not currently sure what the best way to manipulate the ToC is.
    – cfr
    Apr 7, 2015 at 11:48
  • @laminin You're welcome. You should look at the documentation. It is really very good and I believe the German is even better than the English. (I don't read German so I've only used the English.)
    – cfr
    Apr 7, 2015 at 12:32
  • 1
    @laminin I think that is best addressed in your other question since imakeidx is not in your MWE here and this question is probably best kept focused on the page numbering issues. Generally questions are more generally useful that way because it is easier to find information.
    – cfr
    Apr 7, 2015 at 16:43
0

This is the code I tried from Tarun's answer:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
% LyX 2.1.0 created this file.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

\documentclass[twoside,ngerman,fontsize=10pt]{scrreprt}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage[a4paper]{geometry}
\geometry{verbose,tmargin=2.5cm,bmargin=2.5cm,lmargin=2.5cm,rmargin=2.5cm}
\pagestyle{empty}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\setlength{\parskip}{1em}
\setlength{\parindent}{0pt}
\synctex=-1
\usepackage{fancybox}
\usepackage{calc}
\PassOptionsToPackage{normalem}{ulem}
\usepackage{ulem}
\usepackage{nomencl}
\providecommand{\printnomenclature}{\printglossary}
\providecommand{\makenomenclature}{\makeglossary}
\makenomenclature
\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
% User specified LaTeX commands.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

%%%% Heading lines
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\chaptername}{}
\fancyhf{}
\fancyhead[RE,LO]{\textit{\nouppercase{\leftmark}}}
\fancyhead[LE,RO]{\textbf\thepage}

\fancypagestyle{anotherfancy}{ %define another style for first page of chapters.
\renewcommand{\chaptername}{}
\fancyhf{}
\fancyhead[LE,RO]{\textbf\thepage}
} 

%%%% Inhaltsverzeichnis!
\usepackage[colorlinks,pdfpagelabels,pdfstartview = FitH,bookmarksopen =  
true,bookmarksnumbered = true,linkcolor = black,plainpages = false,hypertexnames =     
false,citecolor = black] {hyperref}

\usepackage{fancybox}
\newcommand{\nobreakword}[1]{\mbox{#1}}
\usepackage{etoolbox}
\usepackage{makeidx}\makeindex
\makeatletter
\def\@idxitem{\par\addvspace{10\p@ \@plus 5\p@ \@minus 3\p@}\hangindent 40\p@}
\def\subitem{\par\hangindent 40\p@ \hspace*{20\p@}}
\def\subsubitem{\par\hangindent 40\p@ \hspace*{30\p@}}
\def\indexspace{}
\patchcmd\theindex{\indexname}{\indexname\vspace{12pt}}{}{}
\makeatother

\usepackage{babel}
\makenomenclature

\begin{document}

\newpage
\setcounter{page}{1}
\thispagestyle{empty} 
\begin{center}
\vspace*{10cm}
titlepage
\end{center}

{
\pagestyle{newfancy} %makes the page style the way we want (without page numbers)
\tableofcontents
} % curly braces ensure that the new page style is applicable only for the TOC

\chapter{Introduction} % for the chapter titled "Introduction"
\protect\thispagestyle{anotherfancy} % try this and see if it works. Note the 
In diesem Dokument geht es um Haustiere.
\chapter{Tiere}
Heute ass meine \index{Katze}Katze \nomenclature{Katze}{Haustier} Schokolade und 

musste daher zum \index{Tierarzt}Tierarzt. \nomenclature{Tiger}{Raubtier}
\nomenclature{Schokolade}{Lorem ipsum dolor sit amet,\\...consetetur sadipscing 

elitr,\\...sed diam}
%
\newpage
neue Seite
\newpage
neue Seite
\addpart{Anhang}
\pagestyle{empty} %ohne Seitenzahlen und Kolumnentitel
\addcontentsline{toc}{chapter}{Glossar}
\renewcommand{\nomname}{Glossar}
\printnomenclature[2.5 cm]
%
\clearpage 
\phantomsection 
\addcontentsline{toc}{chapter}{Stichwortverzeichnis} 
\renewcommand{\indexname}{Stichwortverzeichnis}
\printindex
%
\end{document}
6
  • I've edited your post to attribute the code correctly since it is not mine but Tarun's.
    – cfr
    Apr 6, 2015 at 20:27
  • 1
    I'm sorry for the confusion. I deleted my comment above.
    – laminin
    Apr 6, 2015 at 20:30
  • 2
    But it would be better not to use fancyhdr and, if possible, to avoid geometry. You will break KOMA Script functionality doing it this way.
    – cfr
    Apr 6, 2015 at 20:30
  • That means the complete code with fancy... from @Tarun is not the best solution? Any suggestion how to avoid fancyhydr?
    – laminin
    Apr 6, 2015 at 20:36
  • @laminin: I have updated and clarified my answer/response. Please have a look at it and let me know if it still doesn't work for you.
    – TRK
    Apr 13, 2015 at 17:17
0

I did the following and it worked for me:

\pagestyle{fancy}
\renewcommand{\chaptername}{}
\fancyhf{}
\fancyhead[RE,LO]{\textit{\nouppercase{\leftmark}}}
\fancyhead[LE,RO]{\textbf\thepage}

\fancypagestyle{newfancy}{ %define new style for TOC. Use this 'newfancy' page style just before the command for generating TOC:
\renewcommand{\chaptername}{}
\fancyhf{}
\fancyhead[LE,RO]{\textit{\nouppercase{\leftmark}}}
} 

When a new chapter is started, I used commands in the fashion:

\chapter{Introduction} % for the chapter titled "Introduction"
\thispagestyle{empty} % this helped in no page number or chapter name in the header or footer.
%the above two lines wold be followed by the other contents of the chapter.

For no page number in the table of contents, use following line before the command to generate the TOC :

{
\pagestyle{newfancy} %makes the page style the way we want (without page numbers)

\tableofcontents
} % curly braces ensure that the new page style is applicable only for the TOC

Update 1: If page number is needed on the first page of chapter, I think another page style can be defined in the preamble as follows:

\fancypagestyle{anotherfancy}{ %define another style for first page of chapters.
\renewcommand{\chaptername}{}
\fancyhf{}
\fancyhead[LE,RO]{\textbf\thepage}
} 

Next, at the start of a new chapter, use commands in the following fashion along with protect:

\chapter{Introduction} % for the chapter titled "Introduction"
\protect\thispagestyle{anotherfancy} % try this and see if it works. Note the '\protect'

Try this and see if it works. Do let me know. Following is how the page number appeared for me:

enter image description here

7
  • thispagestyle{empty} is useful for the front page the toc and empty pages. For all other pages like the page with the chapter introduction and all other chapter pages and also the nomenclature and index I like to have only no headmark but for this pages I'd like to have the pagenumber. Will this work?
    – laminin
    Apr 5, 2015 at 21:43
  • I have edited/updated my answer. Check with that and let me know if it works for you.
    – TRK
    Apr 6, 2015 at 3:37
  • 1
    It would be better to stick to the package @laminin is using for headers and footers since that will cooperate properly with the document class. Using fancyhdr will break some of that functionality. That said, the use of geometry is already breaking functionality so perhaps that won't bother the OP.
    – cfr
    Apr 6, 2015 at 3:56
  • @Tarun: Only the page number next to the title "Appendix" in the TOC should be avoided. All other page numbers should stay in the TOC. What I get with your code is a page number in the headings for normal text pages and a page number in the footer for pages starting with a new chapter. What I want is to have no page numbers in the footer. The page number should be only in the hedings. In My Answer below I put the changed code. May be we can edit this post to get a full working example.
    – laminin
    Apr 6, 2015 at 20:29
  • I hope you defined a new page style anotherfancy and used the protect command the way I suggested (in the Update 1). I don't have enough understanding to be able to counter @cfr. I trust @cfr for the remarks about fancyheader breaking the functionality. I just intend to inform you that I was able to get page number at the top (the way you desired) after using protect. But I was not able to remove the page number adjacent to index in the TOC. In case you try this out, please let me know if it works for you.
    – TRK
    Apr 7, 2015 at 16:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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