4

I'm trying to write my own class file for subsequent documents based on my template.

What I did is simply copy everthing from \documentclass to (but not including) \begin{document} and paste it into a new file called myclass.cls. Then I went on and replaced every \usepackage with \RequirePackage and \documentclass with \LoadClass. The document actually compiles but I'm missing lines in my header and footer.

This is my MWE which doesn't display any lines:

myclass.cls

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{myclass}[2016/02/21 My Class]

\LoadClass[
  a4paper, 
  headsepline, 
  footsepline, 
  numbers=noenddot, 
  captions=tableheading, 
  listof=totoc, 
  bibliography=totoc, 
  fontsize=10.5pt,
  toc=flat
]{scrartcl}

\RequirePackage{scrlayer-scrpage}

mydoc.tex

\documentclass{myclass}

\begin{document}
    \clearscrheadfoot
    \pagestyle{scrheadings}
    \ihead{header}

    Text
\end{document}

Without the separated class and everything in one file it works:

\documentclass[
  a4paper, 
  headsepline, 
  footsepline, 
  numbers=noenddot, 
  captions=tableheading, 
  listof=totoc, 
  bibliography=totoc, 
  fontsize=10.5pt,
  toc=flat
]{scrartcl}

\usepackage{scrlayer-scrpage}

\begin{document}
    \clearscrheadfoot
    \pagestyle{scrheadings}
    \ihead{header}

    Text
\end{document}

What am I missing? I think somehow the headsepline options isn't loaded with \LoadClass

5

With class option headsepline there will be a line below of the header when page style headings is used. With class option footsepline the line above the footer is printed with both page style headings and page style plain. Note that these class options set also the typearea options headinclude and footinclude.

But you are loading package scrlayer-scrpage and this package has its own options headsepline and footsepline. They also have a different syntax: Using them you can also set a width and a length to the lines. But without any values they simple activate the lines with .4pt width and the same length as header/footer.

While \documentclass passes the options to the packages options set with \LoadClass are not seen by the packages. So scrlayer-scrpage does not know that there should be lines below header and above footer. So you have to set the options explicitly for scrlayer-scrpage.

\begin{filecontents*}{myclass.cls}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{myclass}[2016/02/21 My Class]
\RequirePackage{fix-cm}
\LoadClass[
  numbers=noenddot,
  captions=tableheading,
  listof=totoc,
  bibliography=totoc,
  fontsize=10.5pt,
  toc=flat,
  DIV=calc
]{scrartcl}

\KOMAoptions{
  headinclude,
  footinclude
}
\recalctypearea

\RequirePackage[headsepline,footsepline]{scrlayer-scrpage}
\end{filecontents*}

\documentclass{myclass}
\usepackage{blindtext}% dummy text
\clearpairofpagestyles
\ihead{Header Text}

\begin{document}
\tableofcontents
\blinddocument
\end{document}

or

\begin{filecontents*}{myclass.cls}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{myclass}[2016/02/21 My Class]
\RequirePackage{fix-cm}
\LoadClass[
  numbers=noenddot,
  captions=tableheading,
  listof=totoc,
  bibliography=totoc,
  fontsize=10.5pt,
  toc=flat,
  DIV=calc
]{scrartcl}
\RequirePackage{scrlayer-scrpage}
\KOMAoptions{
  headsepline,
  footsepline
}
\recalctypearea
\end{filecontents*}

\documentclass{myclass}
\usepackage{blindtext}% dummy text
\clearpairofpagestyles
\ihead{Header Text}

\begin{document}
\tableofcontents
\blinddocument
\end{document}

Some remarks:

I have replaced the old command \clearscrheadfoot by \clearpairofpagestyles. Loading scrlayer-scrpage already activates pagestyle scrheadings. Note that this package also redefines headings and plain as aliases of scrheadings and plain.scrheadings.

Note that there is no DIV value predefined for fontsize=10.5pt and the default paper size a4. So you will get a warning that DIV=1 is used. That means a good DIV value will be calculated. To avoid this warning I set DIV=calc explicitly.

In the first example I have used

\KOMAoptions{
  headinclude,
  footinclude
}
\recalctypearea

because the class options headsepline and footsepline sets the typearea options headinclude and footinclude. But if I use headsepline and footsepline as package options for scrlayer-scrpage I have to set the options headinclude and footinclude for typearea explicitly. The command \recalctypearea recalculates the page layout taking these options into account.

In the second example with

\usepackage{scrlayer-scrpage}
\KOMAoptions{
  headsepline,
  footsepline
}
\recalctypearea

headsepline and footsepline are used for both the package scrlayer-scrpage and the KOMA-Script class. So headinclude and footinclude are set automatically. But I have to use \recalctypearea too to recalculate the page layout.

If you do not want to set the typearea options headinclude and footinclude use headsepline and footsepline only as package options for scrlayer-scrpage.

  • Thank you very much. Would you mind explaining the following lines briefly? DIV=calc and \KOMAoptions{ headinclude, footinclude } \recalctypearea – user3105453 Feb 22 '16 at 12:32
  • See my updated answer. – esdd Feb 22 '16 at 13:43

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.