0

Hej,

Recently I had a problem with numbering chapters, sections and subsections (can be found here). Now it seems like everything works but there is still a problem with chapters. They do not appear in ToC and I cannot numbered them. Also, when I tried to remove \def\chapter my whole document crashes... Help

\documentclass[paper=a4,fontsize=11pt,twoside=semi,usegeometry]{scrreprt}   
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}    
\usepackage{microtype}    
\usepackage{amsmath,amsfonts,amsthm,amssymb}    
\usepackage{newtxtext,newtxmath}    
\usepackage{graphicx}

\setlength{\oddsidemargin}{5mm}             
\setlength{\evensidemargin}{5mm}    
\usepackage{blindtext}    
\usepackage{titlesec}    
\usepackage{fancyhdr}    
\usepackage{tocloft}    
\usepackage{ragged2e}

\setcounter{secnumdepth}{5}    
\setcounter{tocdepth}{5}

\addtokomafont{disposition}{\rmfamily}    
\RedeclareSectionCommand[    
  beforeskip=-1sp,    
  afterskip=.5cm,    
  font=\Huge    
]{chapter}

\newcommand{\HRule}[1]{\rule{\linewidth}{#1}}     
\makeatletter                               
\def\printtitle{}    
\makeatother            

\makeatletter                               
\def\printauthor{}              
\makeatother    

\def\afterpage{\null\newpage}    
**\def\chapter**    
\def\linestretch    

\begin{document}    
\printtitle                     
\printauthor                    
\include{Chapter}    
\end{document}
Joanna
  • 1
  • The contents of the included chapter is missing. – esdd May 30 '17 at 17:02
  • Oh pardon: https://tex.stackexchange.com/questions/372179/sections-numbers-do-not-appear-in-document-and-toc – Joanna May 30 '17 at 17:06
  • There should be no formatting commands inside the argument of \chapter. Simple use \chapter{Chapter 2}. The layout of the chapter title is defined using \RedeclareSectionCommand. – esdd May 30 '17 at 17:12
  • I removed all formatting, I just simply use \chapter{Chapter 1}. Also error appears that says "use of \chapter doesn't match its definition" – Joanna May 30 '17 at 18:08
  • your example above has **\def\chapter** and \def\linestretch ie the start of two definitions without the actual definition, was that intended or has it been corrupted as you were adding to this site. also what is the intention of the very odd definition \def\afterpage{\null\newpage} ? – David Carlisle May 30 '17 at 18:21
  • the code above defines \chapter so that it has to be followed by `**
    \def\linestretch

    \beginand then would expand to the textdocumentso any other use of\chapter` will give the error that you state.

    – David Carlisle May 30 '17 at 18:23
  • you should delete all the lines `\makeatletter
    \def\printtitle{}
    \makeatother

    \makeatletter
    \def\printauthor{}
    \makeatother

    \def\afterpage{\null\newpage}
    \def\chapter
    \def\linestretch` from your preamble.

    – David Carlisle May 30 '17 at 18:25
  • \def\afterpage{\null\newpage} is something I use to insert blank page. \makeatletter \def\printtitle{} etc. are commands that "print" title and author on my title page (it was already in template that I used). I removed \def\linestretch but I still cannot delete \def\chapter as the whole document crashes... – Joanna May 30 '17 at 18:33
  • @Joanna NO! trust me you should delete all those lines. \afterpage name comes from the package of that name (which I wrote) the definition here is just bizarre as it does not put anything after any page, the lines with \makeatletter to nothing at all. the line with \printauthor{} does not print anything anywhere it just defines \printauthor to do nothing. and the final two \def are syntax errors that will completely stop latex working at all, If you do not delete the \def\chapter** line then your document will not work and will not be fixable. – David Carlisle May 30 '17 at 20:19
  • latex does not "crash" if you get an error show the exact error from the log file in a {} code section so line endings are preserved, all the lines from ! to ? also you still have not provided a copy of a (short) Chapter.tex file that makes this "crash" so no one except you can run your example. – David Carlisle May 30 '17 at 20:54
  • I'm sorry, I'm quite new here, I don't know what do you exactly need from me. But after implementing all advises IT FINALLY WORKS! Thank you all so much! – Joanna May 30 '17 at 20:58

1 Answers1

1

I have commented the wrong and unneeded lines in your MWE. Please try if the following example works for you:

\documentclass[paper=a4,fontsize=11pt,twoside=semi]{scrreprt}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{microtype}
\usepackage{amsmath,amsfonts,amsthm,amssymb}
\usepackage{newtxtext,newtxmath}
\usepackage{graphicx}

%\setlength{\oddsidemargin}{5mm}% <- should be removed
%\setlength{\evensidemargin}{5mm}% <- should be removed
\usepackage{blindtext}% only for dummy text
%\usepackage{titlesec}% <- I suggest to remove this package
%\usepackage{fancyhdr}% <- I suggest to remove/replace this package
%\usepackage{tocloft}% <- I suggest to remove this package
\usepackage{ragged2e}

\setcounter{secnumdepth}{5}
\setcounter{tocdepth}{5}

\addtokomafont{disposition}{\rmfamily}
\RedeclareSectionCommand[
  beforeskip=-1sp,
  afterskip=.5cm,
  font=\Huge
]{chapter}

\newcommand{\HRule}[1]{\rule{\linewidth}{#1}}
\makeatletter
\def\printtitle{{\Huge\centering prints title\par}}% <-changed
\def\printauthor{{\Huge\centering prints author\par}}% <- changed
\makeatother

%\def\afterpage{\null\newpage}% <- should be removed, there are other possibilities
%**\def\chapter**% <- should be removed
%\def\linestretch% <- should be removed

\begin{document}
\printtitle
\printauthor
\tableofcontents
\chapter{Chapter 1}
\Blindtext
\chapter{Chapter 2}
\Blindtext
\end{document}

Regarding your \afterpage command: please show where you are using this command. I am sure there are other possibilities like \clearpage, \cleardoublepage, \cleardoubleoddpage, ...

esdd
  • 85,675
  • I use \usepackage{fancyhdr} for making header and footer, which seem to not work without it... I removed \afterpage and replaced it with \cleardoublepage - works fine :) If I remove \usepackage{tocloft} then my ToC looks weird ("Contents" is overwriting my first section's name). Removing \def\chapter still makes doc crash ;< – Joanna May 30 '17 at 19:53
  • Sorry, but then you are doing more strange things in your document. Please change your MWE so that it shows the issues. As you can see in my example the chapters are ok and nothing is overwritten in the ToC. – esdd May 30 '17 at 21:20