0

I'm writing a document template as a .tex file, that can simply be included at the beginning of any new document and loads all packages, defines headers, footers etc. called my_template.tex.

Inside my_template.tex, I use KOMA-Script to style the header like:

\documentclass[
    11pt,
    a4paper,
]{scrarticle}

\usepackage[page]{totalcount}
\usepackage{scrlayer-scrpage}
\setkomafont{pagehead}{\normalfont}
\ohead{Template Name \\ Document Name\\ \small Page \thepage~of \totalpages}
\cfoot{}
\setlength{\headheight}{14pt}

I want the user to be able to set the title somewhere inside the document, but use this definition inside the template. Something like:

\input{my_template.tex}
...
\begin{document}
...
\title{My Document Title}
...
\end{document}

How can I set the Document Name inside the header to be My Document Title? I would also like the same title for a \maketitle command.

1 Answer 1

1

One possibility:

\documentclass[
    11pt,
    a4paper,
    head lines=3
]{scrartcl}

\usepackage[page]{totalcount}
\usepackage{scrlayer-scrpage}
\setkomafont{pagehead}{\normalfont}
\clearmainofpairofpagestyles
\ohead{%
  Template Name\\%
  \Ifstr{\documentname}{}{}{\documentname\\}%
  \small Page \thepage~of \totalpages
}
\newcommand*\documentname{}

\let\originaltitle\title
\renewcommand*\title[1]{\def\documentname{#1}\originaltitle{#1}}

\usepackage{blindtext}% only for dummy text
\begin{document}
\title{My title}
\author{Author}
\maketitle
\blinddocument
\end{document}

enter image description here

2
  • What's the difference between scrarticle and scrartcl?
    – Aradnix
    Commented Apr 26, 2022 at 1:24
  • 1
    @Aradnix scrartcl is the original class name. scrarticle is wrapper class that loads scrartcl.
    – esdd
    Commented Apr 26, 2022 at 14:57

You must log in to answer this question.

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