%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%% define chapter style
\usepackage{etoolbox}
\setkomafont{chapter}{\Huge\bfseries}
\addtokomafont{chapterprefix}{\raggedleft}
\renewcommand*{\raggedsection}{\raggedright}
\renewcommand*{\chapterformat}{%                                                                                                                            
    \hrulefill\enskip\mbox{\scalebox{3}{\thechapter\autodot}}\vspace{-0.6\baselineskip}}
		
\newcommand{\chap}[1]{\chapter{#1}\vspace{-0.8\baselineskip}\hrule\vspace{1.5\baselineskip}}
\newcommand\chapst[1]{\chapter*{#1}\vspace{-0.8\baselineskip}\hrule\vspace{1.5\baselineskip}}


%\titleformat
%{\chapter} % command: \part, \chapter, \section, \subsection, \subsubsection, \paragraph or \subparagraph
%[display] % shape: block, display, hang, runin, wrap, drop
%{\bfseries} % format
%{\filleft\colorbox{TUMgray3}{\makebox(45,45)[cc]{\resizebox{!}{22pt}{\textcolor{TUMblue}{\thechapter}}}}} % label
%{-20pt} % sep
%{
	%\textcolor{TUMblue}{\rule{\textwidth}{2pt}}
	%\LARGE \textcolor{black}{#1}
%} % before-code
%[] % after-code

%%% define section style
%\titleformat
%{\section} % command: \part, \chapter, \section, \subsection, \subsubsection, \paragraph or \subparagraph
%[hang] % shape: block, display, hang, runin, wrap, drop
%{\bfseries \Large} % format
%{\thesection} % label
%{10pt} % sep
%{#1} % before-code
%[] % after-code

%%% define subsection style
%\titleformat
%{\subsection} % command: \part, \chapter, \section, \subsection, \subsubsection, \paragraph or \subparagraph
%[hang] % shape: block, display, hang, runin, wrap, drop
%{\bfseries \large} % format
%{\thesubsection} % label
%{10pt} % sep
%{#1} % before-code
%[] % after-code





%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% define header and footer with fancyhdr
%% E: even, O: odd, L: left, C: center, R: right, H: header, F: footer
%%	\thepage => \pagenumbering{xxx}
%
%
%% the normal pages will use pagestyle fancy:
%% \fancypagestyle{fancy} { ... } % this breaks the build. who knows why...
%\pagestyle{fancy}
	%\fancyhf{} %alle Kopf- und Fußzeilenfelder bereinigen
  %\renewcommand{\headrulewidth}{.5pt}
  %%\renewcommand{\footrulewidth}{0.5pt}
  %%\renewcommand{\chaptermark}[1]{\markboth{\thechapter\ #1}{}}
  %%\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
	%
  %\fancyhead{} % clear all header fields
  %\fancyhead[ER]{\leftmark}
  %\fancyhead[EL,OR]{\thepage}
  %\fancyhead[OL]{\rightmark}
  %\fancyfoot{} % clear all footer fields
%
%% the chapter-starting pages automatically use pagestyle plain (def. of documentclass):
%% uncomment this whole block to switch to simple chapter-starting pages
%\fancypagestyle{plain}
%{
  %%\renewcommand{\headrulewidth}{0.0pt}
	%%\renewcommand{\headrule}{\vbox to 0pt{\hbox to \headwidth{\dotfill}\vss}}
	%
%%https://tex.stackexchange.com/questions/311599/double-line-in-header
%\def\headrule{{\if@fancyplain\let\headrulewidth\plainheadrulewidth\fi
%\hrule\@height\headrulewidth\@width\headwidth
%\vskip 2pt% 2pt between lines
%\hrule\@height.5pt\@width\headwidth% lower line with .5pt line width
%\vskip-\headrulewidth
%\vskip-1.5pt}}
	%
	%
  %%\renewcommand{\footrulewidth}{0.5pt}
  %%\renewcommand{\chaptermark}[1]{\markboth{\thechapter\ #1}{}}
  %%\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
  %
  %%\fancyhead{} % clear all header fields
  %%\fancyhead[RE]{\leftmark}
  %%\fancyhead[LE,RO]{\thepage}
  %%\fancyhead[LO]{\rightmark}
  %%\fancyfoot{} % clear all footer fields
%}
%
%% note: the pagestyle "empty" seems to be pre-defined















%Kopf-und Fußzeile aktivieren
%\usepackage[]{scrpage2}
\usepackage[manualmark,headsepline=0.4pt,footsepline=0.4pt]{scrlayer-scrpage}
%\usepackage{scrhack}
\automark[section]{chapter}
%\setlength{\headheight}{1.1\baselineskip}

% Kopf/Fuß-zeile: ============================================
%\usepackage[pagestyles]{titlesec}
\usepackage{titletoc}

%%% Start %%%
\newcommand{\packagesHeadFootStart}{
%\pagestyle{empty}
\ihead[]{}															% obeninnen
\chead[]{}															% obenmitte
\ohead[]{\scshape \headmark}						% obenaußen
\ofoot[]{}															% untenaußen
\cfoot[ \pagemark \ ]	{ \pagemark \ }		% untenmitte
\ifoot[]{}															% unteninnen
%\setheadsepline{0.4pt} \setfootsepline{0.4pt}
}
%%% Main %%%
\newcommand{\packagesHeadFootMain}{
\pagestyle{scrheadings}
\renewcommand*{\chaptermarkformat}{}
\lehead{\scshape{\chaptername \ \thechapter: \headmark}} 	% even pages Chapter
\rohead{\scshape \headmark}
\ofoot[ \pagemark \ ]{ \pagemark \ } 		% untenaußen
\cfoot[]{}															% untenmitte
\ifoot[]{}															% unteninnen
%\setheadsepline{0.4pt} \setfootsepline{0.4pt}
\addtokomafont{headsepline}{\color{black}}
\addtokomafont{footsepline}{\color{black}}
}
%%% Ende %%%
\newcommand{\packagesHeadFootEnde}{
% Änderung für den Anhang
\pagestyle{scrheadings}
\renewcommand*{\chaptermarkformat}{}
\lehead{\scshape{Appendix}} 						% even pages Chapter
\rohead{\scshape \headmark}
\ofoot[ \pagemark \ ]{ \pagemark \ } 		% untenaußen
\cfoot[]{}															% untenmitte
\ifoot[]{}															% unteninnen
%\setheadsepline{0.4pt} \setfootsepline{0.4pt}
}
%%% Literatur %%%
\newcommand{\packagesHeadFootBib}{
% Änderung für den Anhang
\pagestyle{scrheadings}
\ihead[]{}															% obeninnen
\chead[]{}															% obenmitte
\ohead[]{\scshape \headmark}						% obenaußen
\ofoot[]{}															% untenaußen
\cfoot[ \pagemark \ ]	{ \pagemark \ }		% untenmitte
\ifoot[]{}															% unteninnen
%\setheadsepline{0.4pt} \setfootsepline{0.4pt}
}
% Kopf/Fuß-zeile: ============================================


