0

I got the error "Missing number, treated as zero MWE.tex" with an emergency stop. I tried to remove the spaces from the first page of every chapter and set the header and footer on it, too.

MWE:

\documentclass[a4paper,12pt]{report}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\makeatletter
\renewcommand{\chapter}{
\if@openright
    \cleardoublepage\else\clearpage
\fi
    \thispagestyle{fancy}%
    \global\@topnum\z@
    \@afterindentfalse
    \secdef\@chapter\@schapter}
\def\@chapter[#1]#2{%\ifnum 
\c@secnumdepth >\m@ne
    \refstepcounter{chapter}
    \typeout{\@chapapp\thechapter.}
    \addcontentsline{toc}{chapter}{\protect\numberline{\thechapter}#1}
%\else
%   \addcontentsline{toc}{chapter}{\protect\numberline{\thechapter}#1}
%\fi
\chaptermark{#1}
\addtocontents{lof}{\protect\addvspace{10\p@}}
\addtocontents{lot}{\protect\addvspace{10\p@}}
\if@twocolumn
    \@topnewpage[\@makechapterhead{#2}]
\else
    \@makechapterhead{#2}
    \@afterheading
\fi}
\def\@makechapterhead#1{
    \vspace*{0\p@}
    {\parindent \z@ \raggedright \normalfont
        \ifnum \c@secnumdepth >\m@ne
            \huge\bfseries \@chapapp \space \thechapter
            \par\nobreak
            \vskip 20\p@
        \fi
        \interlinepenalty\@M
        \Huge \bfseries #1\par\nobreak
        \vskip 20\p@
    }}
\def\@schapter#1{\if@twocolumn
        \@topnewpage[\@makeschapterhead{#1}]
    \else
        \@makeschapterhead{#1}
        \@afterheading
    \fi}
\def\@makeschapterhead#1{
    \vspace*{-10\p@}
    {\parindent \z@ \raggedright
        \normalfont
        \interlinepenalty\@M
        \Huge \bfseries  #1\par\nobreak
        \vskip 20\p@
    }}
\makeatother
\begin{document}
    \chapter{Asdf}
        \lipsum[1]
\end{document}

1 Answer 1

1

There are two problems with your example. The first is that you are using the \thispagestyle command without loading fancyhdr. This will throw a undefined control sequence.

The second problem is that you (I suppose) commented an \ifnum but left the conditional (\c@secnumdepth >\m@ne). If you uncomment the \ifnum it works, but perhaps not as expected:

\documentclass[a4paper,12pt]{report}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\usepackage{fancyhdr}% <---- Included this package
\makeatletter
\renewcommand{\chapter}{\if@openright\cleardoublepage\else\clearpage\fi % Typ II
                                        \thispagestyle{fancy}%
                                        \global\@topnum\z@
                                        \@afterindentfalse
                                        \secdef\@chapter\@schapter}
\def\@chapter[#1]#2{\ifnum% <---- This was commented
\c@secnumdepth >\m@ne
                                                 \refstepcounter{chapter}%
                                                 \typeout{\@chapapp\thechapter.}
                                                 \addcontentsline{toc}{chapter}{\protect\numberline{\thechapter}#1}
%                                       \else
%                                           \addcontentsline{toc}{chapter}{\protect\numberline{\thechapter}#1}
%                                       \fi
                                        \chaptermark{#1}
                                        \addtocontents{lof}{\protect\addvspace{10\p@}}
                                        \addtocontents{lot}{\protect\addvspace{10\p@}}
                                        \if@twocolumn
                                            \@topnewpage[\@makechapterhead{#2}]%
                                        \else
                                            \@makechapterhead{#2}%
                                            \@afterheading
                                        \fi}
\def\@makechapterhead#1{
    \vspace*{0\p@}
    {\parindent \z@ \raggedright \normalfont
        \ifnum \c@secnumdepth >\m@ne
                \huge\bfseries \@chapapp \space \thechapter
                \par\nobreak
                \vskip 20\p@
        \fi
        \interlinepenalty\@M
        \Huge \bfseries #1\par\nobreak
        \vskip 20\p@
    }}
\def\@schapter#1{\if@twocolumn
                                     \@topnewpage[\@makeschapterhead{#1}]
                                 \else
                                     \@makeschapterhead{#1}
                                     \@afterheading
                                 \fi}
\def\@makeschapterhead#1{
    \vspace*{-10\p@}
    {\parindent \z@ \raggedright
        \normalfont
        \interlinepenalty\@M
        \Huge \bfseries  #1\par\nobreak
        \vskip 20\p@
    }}
\makeatother
\begin{document}
    \chapter{Asdf}
        \lipsum[1]
\end{document}

Or, if you don't want the conditional, you can comment the conditional test (\c@secnumdepth >\m@ne) altogether:

\documentclass[a4paper,12pt]{report}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\usepackage{fancyhdr}% <---- Included this package
\makeatletter
\renewcommand{\chapter}{\if@openright\cleardoublepage\else\clearpage\fi % Typ II
                                        \thispagestyle{fancy}%
                                        \global\@topnum\z@
                                        \@afterindentfalse
                                        \secdef\@chapter\@schapter}
\def\@chapter[#1]#2{%\ifnum
%\c@secnumdepth >\m@ne% <---- This was un-commented
                                                 \refstepcounter{chapter}%
                                                 \typeout{\@chapapp\thechapter.}
                                                 \addcontentsline{toc}{chapter}{\protect\numberline{\thechapter}#1}
%                                       \else
%                                           \addcontentsline{toc}{chapter}{\protect\numberline{\thechapter}#1}
%                                       \fi
                                        \chaptermark{#1}
                                        \addtocontents{lof}{\protect\addvspace{10\p@}}
                                        \addtocontents{lot}{\protect\addvspace{10\p@}}
                                        \if@twocolumn
                                            \@topnewpage[\@makechapterhead{#2}]%
                                        \else
                                            \@makechapterhead{#2}%
                                            \@afterheading
                                        \fi}
\def\@makechapterhead#1{
    \vspace*{0\p@}
    {\parindent \z@ \raggedright \normalfont
        \ifnum \c@secnumdepth >\m@ne
                \huge\bfseries \@chapapp \space \thechapter
                \par\nobreak
                \vskip 20\p@
        \fi
        \interlinepenalty\@M
        \Huge \bfseries #1\par\nobreak
        \vskip 20\p@
    }}
\def\@schapter#1{\if@twocolumn
                                     \@topnewpage[\@makeschapterhead{#1}]
                                 \else
                                     \@makeschapterhead{#1}
                                     \@afterheading
                                 \fi}
\def\@makeschapterhead#1{
    \vspace*{-10\p@}
    {\parindent \z@ \raggedright
        \normalfont
        \interlinepenalty\@M
        \Huge \bfseries  #1\par\nobreak
        \vskip 20\p@
    }}
\makeatother
\begin{document}
    \chapter{Asdf}
        \lipsum[1]
\end{document}
5
  • Now, '\chapter{Asdf}' is an undefined control sequence... Doesn't work for me.
    – Nepumuk
    Jan 12, 2018 at 13:37
  • ... I swear I made it work... Sorry, I'll take a look at it... Jan 12, 2018 at 13:39
  • Oh, yes. You are also missing the fancyhdr package. The undefined control sequence is because of the \thispagestyle command. Jan 12, 2018 at 13:43
  • OK, the first doesn't work, but the second did. Didn't see the second first.
    – Nepumuk
    Jan 12, 2018 at 13:45
  • @Nepumuk I updated my answer to include the \usepackage{fancyhdr}. Both versions should work now. Jan 12, 2018 at 13:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .