[Tex/LaTex] Custom footer in Lyx

fancyhdrheader-footerlyx

I am using report class in Lyx for my thesis. I want centered footer and no header for the pages before Chapter 1 ie. on pages which include abstract, acknowledgements, table of contents, list of tables and list of figures. I currently use fancy header package to write headers/footers but this writes same footer and header starting from the title page. I have the following code in the preamble of my Lyx document.

\AtBeginDocument{\newgeometry{hmargin=4cm}}
\raggedbottom
\pagenumbering{roman}
\geometry{textheight=245mm, textwidth=160mm, footskip=10mm}
\usepackage{tocloft}
\renewcommand{\cfttoctitlefont}{\hspace*{\fill}\Huge\bfseries}
\renewcommand{\cftaftertoctitle}{\hspace*{\fill}}
\renewcommand{\cftlottitlefont}{\hspace*{\fill}\Huge\bfseries}
\renewcommand{\cftafterlottitle}{\hspace*{\fill}}
\renewcommand{\cftloftitlefont}{\hspace*{\fill}\Huge\bfseries}
\renewcommand{\cftafterloftitle}{\hspace*{\fill}}

\setlength\cftbeforetoctitleskip{-7mm}
\setlength\cftbeforeloftitleskip{-25mm}
\setlength\cftbeforelottitleskip{-4mm}

\setlength\cftaftertoctitleskip{0mm}
\setlength\cftafterloftitleskip{0mm}
\setlength\cftafterlottitleskip{0mm}

\renewcommand\nomname{List of Abbreviations}
\renewcommand{\nomname}{\makebox[\linewidth]{List of Abbreviations}}

\renewcommand\cftchapfont{\fontsize{16}{18}\selectfont}
\setlength{\cftbeforechapskip}{-8pt}
\setlength{\cftbeforesecskip}{-12pt}
\renewcommand\cftsecfont{\fontsize{14}{16}\selectfont}
\setlength{\cftbeforesecskip}{-12pt}
\renewcommand\cftsubsecfont{\fontsize{8}{12}\selectfont}
\setlength{\cftbeforesubsecskip}{-12pt}
\renewcommand\cftsubsubsecfont{\fontsize{8}{12}\selectfont}
\setlength{\cftbeforesubsubsecskip}{-12pt}

\renewcommand{\cftsecfont}{\fontseries{md}\fontsize{14}{16}\selectfont}
\renewcommand{\cftsubsecfont}{\fontseries{md}\fontsize{12}{14}\selectfont}
\renewcommand{\cftsubsubsecfont}{\fontseries{md}\fontsize{10}{12}\selectfont}

\renewcommand{\cftsecpagefont}{\fontseries{md}\fontsize{14}{16}\selectfont}
\renewcommand{\cftsubsecpagefont}{\fontseries{md}\fontsize{12}{14}\selectfont}
\renewcommand{\cftsubsubsecpagefont}{\fontseries{md}\fontsize{10}{12}\selectfont}

\usepackage{titlesec}
\titleformat{\chapter}[display]{\normalfont\LARGE\bfseries}{\chaptertitlename\ \thechapter}{15mm}{\LARGE}

\titlespacing*{\chapter}{0mm}{50mm}{15mm}
\titlespacing*{\section}{0pt}{15mm}{15mm}
\titlespacing*{\subsection}{0pt}{15mm}{15mm}
\titlespacing*{\subsubsection}{0pt}{10mm}{10mm}


\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[LE]{\thepage}
\fancyhead[RE]{Chapter\space{\thechapter,\space\space}Section\space{\thesection}}
\fancyhead[RO]{\thepage}
\fancyhead[LO]{\nouppercase\rightmark}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{#1}}

Best Answer

I did something similar recently. I didn't define the headers and footers in the preamble, but instead went to Document settings > Modules and enabled "Custom Header/Footerlines". This adds 6 new layouts in the drowdown menu (see picture).

enter image description here

With this and a few TeX boxes, you can achieve what you want. I'm not sure how to best show it here - maybe just copy this code to an editor, save it as a .lyx file, and open it in LyX. I tried to explain everything in there:

#LyX 2.2 created this file. For more info see http://www.lyx.org/
\lyxformat 508
\begin_document
\begin_header
\save_transient_properties true
\origin unavailable
\textclass extarticle
\begin_preamble
\pagestyle{fancy}
\end_preamble
\use_default_options false
\begin_modules
customHeadersFooters
\end_modules
\maintain_unincluded_children false
\language american
\language_package default
\inputencoding auto
\fontencoding global
\font_roman "times" "Times New Roman"
\font_sans "helvet" "Arial"
\font_typewriter "courier" "Courier New"
\font_math "auto" "default"
\font_default_family default
\use_non_tex_fonts true
\font_sc false
\font_osf false
\font_sf_scale 100 100
\font_tt_scale 100 100
\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\paperfontsize 12
\spacing onehalf
\use_hyperref true
\pdf_title "Blah"
\pdf_author "Ginchen"
\pdf_keywords "blah, blah, blah"
\pdf_bookmarks true
\pdf_bookmarksnumbered true
\pdf_bookmarksopen true
\pdf_bookmarksopenlevel 2
\pdf_breaklinks false
\pdf_pdfborder false
\pdf_colorlinks true
\pdf_backref page
\pdf_pdfusetitle false
\pdf_quoted_options "linkcolor=black, citecolor=black, urlcolor=blue, filecolor=blue, pdfpagelayout=OneColumn, pdfnewwindow=true, pdfstartview=XYZ, plainpages=false"
\papersize a4paper
\use_geometry true
\use_package amsmath 1
\use_package amssymb 1
\use_package cancel 0
\use_package esint 0
\use_package mathdots 1
\use_package mathtools 0
\use_package mhchem 1
\use_package stackrel 0
\use_package stmaryrd 0
\use_package undertilde 0
\cite_engine basic
\cite_engine_type default
\biblio_style plain
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\justification true
\use_refstyle 0
\index Stichwortverzeichnis
\shortcut idx
\color #008000
\end_index
\leftmargin 2.5cm
\topmargin 2.5cm
\rightmargin 2.5cm
\bottommargin 2cm
\secnumdepth 3
\tocdepth 3
\paragraph_separation skip
\defskip bigskip
\quotes_language english
\papercolumns 1
\papersides 1
\paperpagestyle fancy
\bullet 1 0 9 -1
\bullet 2 1 35 -1
\bullet 3 1 29 -1
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\end_header

\begin_body

\begin_layout Center Footer
This is my footer that appears on all pages starting from page 1!
\end_layout

\begin_layout Standard
\begin_inset Note Note
status open

\begin_layout Plain Layout
The following headers are set to empty, because otherwise the table of contents
 gets an ugly 
\begin_inset Quotes eld
\end_inset

CONTENTS - CONTENTS
\begin_inset Quotes erd
\end_inset

 header.
\end_layout

\end_inset


\end_layout

\begin_layout Left Header

\end_layout

\begin_layout Center Header

\end_layout

\begin_layout Right Header

\end_layout

\begin_layout Title
Title
\end_layout

\begin_layout Author
Author
\end_layout

\begin_layout Standard
\begin_inset Note Note
status open

\begin_layout Plain Layout
The title page usually uses the plain layout, which includes a page number
 in the footer instead of the footer defined above.
 So we set the page style to fancy for this page.
\end_layout

\end_inset


\end_layout

\begin_layout Standard
\begin_inset ERT
status open

\begin_layout Plain Layout


\backslash
thispagestyle{fancy}
\end_layout

\end_inset


\end_layout

\begin_layout Standard
\begin_inset Note Note
status open

\begin_layout Plain Layout
Although the header is empty, the line beneath it will still display.
\begin_inset Newline newline
\end_inset

So we remove it by making it 0pt high.
\end_layout

\end_inset


\end_layout

\begin_layout Standard
\begin_inset ERT
status open

\begin_layout Plain Layout


\backslash
renewcommand{
\backslash
headrulewidth}{0pt}
\end_layout

\end_inset


\end_layout

\begin_layout Standard
\begin_inset Newpage newpage
\end_inset


\end_layout

\begin_layout Abstract
blah blah blah
\end_layout

\begin_layout Standard
\begin_inset Newpage newpage
\end_inset


\end_layout

\begin_layout Standard
\begin_inset CommandInset toc
LatexCommand tableofcontents

\end_inset


\end_layout

\begin_layout Standard
\begin_inset Newpage newpage
\end_inset


\end_layout

\begin_layout Standard
\begin_inset Note Note
status open

\begin_layout Plain Layout
The following headers will be shown starting from this point.
\end_layout

\end_inset


\end_layout

\begin_layout Left Header
\noindent
This is the header that will only begin to appear after all the front matter
\end_layout

\begin_layout Right Header
Page 
\begin_inset ERT
status open

\begin_layout Plain Layout


\backslash
thepage
\end_layout

\end_inset


\end_layout

\begin_layout Standard
\begin_inset Note Note
status open

\begin_layout Plain Layout
If you want the line beneath the header back, you can set it back to 1pt:
\end_layout

\end_inset


\end_layout

\begin_layout Standard
\begin_inset ERT
status open

\begin_layout Plain Layout


\backslash
renewcommand{
\backslash
headrulewidth}{1pt}
\end_layout

\end_inset


\end_layout

\begin_layout Part
Once upon a time...
\end_layout

\begin_layout Standard
...
 there was a question in the TeX StackExchange, and the princess of LyX
 wrote a meaningless text just for the sake of an example.
\end_layout

\end_body
\end_document

The result looks like this:

enter image description here

Related Question