# Maintain a consistent style in a multi-file document

I am trying to set up a multi-file document where I use \input to add different .tex files to my main document. Each .tex file is in its own directory/folder. I have also created a .sty file which contains the preamble packages and code to set the style. When I compile the document, the style is inconsistent - the header and footer appears on some pages but not all.

When I compile with all of the code in a single document, the result is fine.

Can someone tell me how to fix this so that all my pages have the same header and footer format?

I attach the following MWE and images:

Main document

\documentclass[12pt,a4paper]{report}
\usepackage{graphicx}
% put all the other packages here:

\usepackage{My_style_package}
\usepackage{hyperref}
\begin{document}
%TITLE PAGE AND ABSTRACT
\input{./Title_and_abstract/Title_and_abstract.tex}
%\tableofcontents
%\listoffigures
%\listoftables
%\input{./Intro/Introduction_v0.1.tex}
\input{./Methods/Methods.tex}
%\maketitle

%\input{./tex/intro.tex}
%\input{./tex/main_part.tex}
%\input{./tex/conclusions.tex}

%\appendix
%\input{./tex/myappendix.tex}

% Bibliography:
%\clearpage
%\input{./tex/mybibliography.tex}

\end{document}


My style file

    \ProvidesPackage{My_style_package}
\usepackage{color}
\usepackage{graphicx, epstopdf}
\usepackage{etoolbox}%This package combined with the \pathcmd rewrites the standard style for 'Chapter' to allow the fancy horizontal and vertical lines.
\patchcmd{\chapter}{\thispagestyle{plain}}{\thispagestyle{mystyle}}{}{}
\usepackage{gensymb}
\usepackage{times}
\usepackage{tabulary}
\usepackage{tabularx}
\usepackage{longtable}
\usepackage{booktabs,caption, makecell}
\usepackage{pdflscape,afterpage,caption}
\usepackage[british]{babel}
\usepackage[backend=bibtex, citestyle=ieee, bibstyle=ieee]{biblatex}
\usepackage[section]{placeins}%Allows you to permanently fix figures.
\usepackage{titleps}%fancy page borders?
\usepackage[left=2.8cm, right=2.8cm, top=3.5cm, bottom=3.5cm]{geometry}
%\usepackage{caption}
\captionsetup[figure]{font=scriptsize,labelfont=scriptsize}
\usepackage{microtype}
\usepackage{setspace}
\usepackage{amsmath}
\usepackage{datetime}
\newdate{date}{28}{02}{2018}
\date{\displaydate{date}}
\onehalfspacing

\sloppy%Makes sure that none of the text exceeds text width. Useful if have long chemical words.

\newpagestyle{mystyle}{%
\setfoot[{\makebox[\marginparwidth][r]{\thepage~}\smash{\rule[-20ex]{0.6pt}{22ex}}}][][]{}{}{\smash{\rule[-20ex]{0.6pt}{22ex}}\makebox[\marginparwidth][l]{~\thepage}
}
}%This part creates the fancy top (horizontal) and bottom (verticle) lines that you see from the 'Abstrct' page onwards.

\renewcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi
\thispagestyle{mystyle}
\global\@topnum\z@
\@afterindentfalse
\secdef\@chapter\@schapter}


Example of linked input file - 1

%----------------------------------------------------------------------------------------
%   TITLE PAGE
%----------------------------------------------------------------------------------------

\begin{titlepage} % Suppresses displaying the page number on the title page and the subsequent page counts as page 1
\newcommand{\HRule}{\rule{\linewidth}{0.5mm}} % Defines a new command for horizontal lines, change thickness here

\center % Centre everything on the page

%------------------------------------------------
%------------------------------------------------

\textsc{\LARGE TEST TITLE}\\[1.5cm] % Main heading such as the name of your university/college

\textsc{\Large TEST NAME}\\[0.5cm] % Major heading such as course name

%------------------------------------------------
%   Title
%------------------------------------------------

\HRule\\[0.4cm]

{\huge\bfseries TITLE OF WORK}\\[0.4cm] % Title of your document

\HRule\\[1.5cm]

%------------------------------------------------
%   Author(s)
%------------------------------------------------

%\begin{minipage}{0.4\textwidth}
%\begin{flushleft}
%\large
%\textit{Author}\\
%\end{flushleft}
%\end{minipage}
~
%\begin{minipage}{0.4\textwidth}
%\begin{flushright}
%\large
%\textit{Supervisor}\\
%Supervisor name \textsc{Surname} % Supervisor's name
%\end{flushright}
%\end{minipage}

% If you don't want a supervisor, uncomment the two lines below and comment the code above
{\large{NAME}}\\

%------------------------------------------------
%   Date
%------------------------------------------------

\vfill\vfill\vfill % Position the date 3/4 down the remaining page

{\large\today} % Date, change the \today to a set date if you want to be precise

%------------------------------------------------
%   Logo
%------------------------------------------------

%\vfill\vfill
%\includegraphics[width=0.2\textwidth]{placeholder.jpg}\\[1cm] % Include a department/university logo - this will require the graphicx package

%----------------------------------------------------------------------------------------

\vfill % Push the date up 1/4 of the remaining page

\end{titlepage}
\pagenumbering{roman}
\subsection*{\hfil Abstract\hfil}

\newpage
\tableofcontents
\newpage
\listoffigures
\newpage
\listoftables
\newpage

\section*{Abbreviations}
%\begin{table}
% \setlength\tabcolsep{60pt}
% \centering
%\small
%\hspace*{-18mm}%
%\vspace{-5.5mm}%
\begin{longtable}{l l}
\toprule
{Abbreviation}&{Explanation}\\[0.5 ex]
\midrule
Acronym & Explanation \\
Acronym & Explanation \\
Acronym & Explanation \\
Acronym & Explanation \\
Acronym & Explanation \\
Acronym & Explanation \\
Acronym & Explanation \\
Acronym & Explanation \\
Acronym & Explanation \\
Acronym & Explanation \\
Acronym & Explanation \\
Acronym & Explanation \\
Acronym & Explanation \\
Acronym & Explanation \\
Acronym & Explanation \\
Acronym & Explanation \\
Acronym & Explanation \\
Acronym & Explanation \\
Acronym & Explanation \\
Acronym & Explanation \\
Acronym & Explanation \\
Acronym & Explanation \\
Acronym & Explanation \\
Acronym & Explanation \\
Acronym & Explanation \\
Acronym & Explanation \\
Acronym & Explanation \\
Acronym & Explanation \\
Acronym & Explanation \\
Acronym & Explanation \\
Acronym & Explanation \\
Acronym & Explanation \\
Acronym & Explanation \\
Acronym & Explanation \\
Acronym & Explanation \\
Acronym & Explanation \\
\bottomrule
\end{longtable}%
\hspace*{-12mm}%
\vspace{50mm}

\label{table:abbreviations}
%\end{table}
\newpage


Example of linked input file - 2

Save time in Word with new buttons that show up where you need them. To change the way a picture fits in your document, click it and a button for layout options appears next to it. When you work on a table, click where you want to add a row or a column, and then click the plus sign.
Reading is easier, too, in the new Reading view. You can collapse parts of the document and focus on the text you want. If you need to stop reading before you reach the end, Word remembers where you left off - even on another device.

\begin{figure}[h!]
\centering
\includegraphics[width=0.5\textwidth]{Testimage}%Since we have identified the graohic location we just need the file name.
\caption{Test image}
\end{figure}


Output image (inconsistencies circled in red)

Output image (another example - same problem in red)

Note that in the report document class, the command \chapter sets the pagestyle to "plain". If you want to change this behaviour, you need to look up the definition of \chapter in report.cls and amend it in your own style file. So copy this piece of code from report.cls

\newcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi
\thispagestyle{plain}%
\global\@topnum\z@
\@afterindentfalse
\secdef\@chapter\@schapter}


and insert the follwing modied form into your own My_style_package.sty:

\renewcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi
%                \thispagestyle{plain}%
\global\@topnum\z@
\@afterindentfalse
\secdef\@chapter\@schapter}



• Thanks @jknappen. I inserted the modified code \renewcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi \thispagestyle{mystyle} \global\@topnum\z@ \@afterindentfalse \secdef\@chapter\@schapter} but the problem remains. Replacing \section*{Abbreviations} with \chapter*{Abbreviations} fixes the first page of the table but not the second one. Does the \chapter pagestyle need to be completely rewritten? What I want to do is use the default page style seen in the article document class and put it in my report document class. Thanks. – Kevin May 17 '18 at 13:59

It appears that certain packages and styles behave differently when they are stored in a .sty file compared with a .tex even if both are linked to the same document.

My solution was to move all the code in the .sty file into my main document. The result is a more simplified directory; I now have one document containing all the preamble and styles and which I use the \input command to add files. This maintains the freedom to work on the other input files.

Here's the updated main document:

Main document

%all packages and styles
\documentclass[12pt,a4paper]{report}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{color}
\usepackage{graphicx, epstopdf}
\usepackage{etoolbox}%This package combined with the \pathcmd rewrites the standard style for 'Chapter' to allow the fancy horizontal and vertical lines.
\patchcmd{\chapter}{\thispagestyle{plain}}{\thispagestyle{mystyle}}{}{}
\usepackage{gensymb}
\usepackage{times}
\usepackage{tabulary}
\usepackage{tabularx}
\usepackage{longtable}
\usepackage{booktabs,caption, makecell}
\usepackage{pdflscape,afterpage,caption}
\usepackage[british]{babel}
\usepackage[backend=bibtex, citestyle=ieee, bibstyle=ieee]{biblatex}
\usepackage[section]{placeins}%Allows you to permanently fix figures.
\usepackage{titleps}%fancy page borders?
\usepackage[left=2.8cm, right=2.8cm, top=3.5cm, bottom=3.5cm]{geometry}
%\usepackage{caption}
\captionsetup[figure]{font=scriptsize,labelfont=scriptsize}
\usepackage{microtype}
\usepackage{setspace}
\usepackage{amsmath}
\usepackage{datetime}
\newdate{date}{28}{02}{2018}
\date{\displaydate{date}}
\onehalfspacing

\sloppy%Makes sure that none of the text exceeds text width. Useful if have long chemical words.

\newpagestyle{mystyle}{%
\setfoot[{\makebox[\marginparwidth][r]{\thepage~}\smash{\rule[-20ex]{0.6pt}{22ex}}}][][]{}{}{\smash{\rule[-20ex]{0.6pt}{22ex}}\makebox[\marginparwidth][l]{~\thepage}
}
}%This part creates the fancy top (horizontal) and bottom (verticle) lines that you see from the 'Abstrct' page onwards.

\renewcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi
\thispagestyle{mystyle}
\global\@topnum\z@
\@afterindentfalse
\secdef\@chapter\@schapter}

%use \input to add files to document
\begin{document}
%TITLE PAGE AND ABSTRACT
\input{./Title_and_abstract/Title_and_abstract.tex}
%\tableofcontents
%\listoffigures
%\listoftables
%\input{./Intro/Introduction_v0.1.tex}
\input{./Methods/Methods.tex}
%\maketitle

%\input{./tex/intro.tex}
%\input{./tex/main_part.tex}
%\input{./tex/conclusions.tex}

%\appendix
%\input{./tex/myappendix.tex}

% Bibliography:
%\clearpage
%\input{./tex/mybibliography.tex}

\end{document}