Page LayoutIssues with fancyhdr & newcommand for chapters

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
rocket2008
Posts: 2
Joined: Tue Feb 28, 2023 1:13 pm

Issues with fancyhdr & newcommand for chapters

Post by rocket2008 »

Hi, everyone!

I am using a newcommand to define how the chapters show up on the manuscript and ToC. That worked fine. Then, I wanted to place an image (logo) next to the page number in each page. It works, but I get the Missing $ inserted error for the lines where I make use of the newcommand (\mychapter) and for \end{document}.

Additionally, I want to align vertically the image with the page number. I tried with parbox but it didn't change anything.

Here is my MWE. In the original document (on Overleaf) I use input files and the error is the same.

Thanks for any tips.

Code: Select all

\documentclass[11pt]{report}
\usepackage[utf8]{inputenc}
\usepackage[a4paper, total={170mm,257mm},
 left=20mm,
 top=20mm,]{geometry}
\usepackage{graphicx}

\usepackage{fancyhdr} 

\fancyhf{} 
\renewcommand{\headrulewidth}{0pt}

\fancypagestyle{plain}
{
    \cfoot{ Page \thepage \ \vert \ \includegraphics[scale=0.1] {example-image-a}}

}    


%%% change font %%%
\renewcommand{\sfdefault}{phv}
\renewcommand{\familydefault}{\sfdefault}

%%% set path of figures folder
\graphicspath{ {figures/} }

%%% packages %%%


\usepackage{enumitem}
\usepackage{float}
\usepackage{xcolor}
\usepackage{cancel}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{parskip}
\usepackage{svg}
\usepackage{accents}
\usepackage{mwe} % For dummy images
\usepackage{subcaption}
\usepackage{wrapfig}
\usepackage[hidelinks]{hyperref} % disable hidelinks to show boxes 
\usepackage{cleveref}
\usepackage{wrapfig}
\usepackage{comment}
\usepackage{cancel}
\usepackage{rotating}
\usepackage{pdflscape}
\usepackage{csquotes}
\usepackage[version=4]{mhchem} %chemical
\usepackage[acronym]{glossaries} % acronyms page
\usepackage{blindtext}

%%% define colors and change %%%
\definecolor{blue1}{HTML}{045474}
\definecolor{green1}{HTML}{34b434}
\definecolor{darkblue1}{HTML}{042464}


\usepackage{sectsty}
\chapterfont{\color{blue1}}  % sets colour of chapters
\sectionfont{\color{green1}}  % sets colour of sections

%%% displaystyle for math mode %%%
\everymath{\displaystyle}

%% change name of Contents (ToC) %%%
\renewcommand{\contentsname}{Table of Contents}

%%% new command to hide chapter numbers %%%
\newcommand{\mychapter}[2]{
    \setcounter{chapter}{#1}
    \setcounter{section}{0}
    \chapter*{#2}
    \addcontentsline{toc}{chapter}{#2}
}


\begin{document}

\begin{titlepage}

%\raggedright
%\includegraphics[width = 7cm]{figures/wurlogo.png}\\[8ex]
   \begin{center}
       \vspace*{2cm}

       
       \textbf{\large title}
       
        
        \vspace{1cm} 

        
        
        \vspace{0.2cm} 
       
       \vfill
            
            
       Department \\
        Place\\
       \today
            
            
   \end{center}
\end{titlepage}


\chapter*{Executive Summary}
\blindtext
\thispagestyle{empty}

\tableofcontents
\thispagestyle{empty}

\listoffigures
\thispagestyle{empty}

\listoftables
\thispagestyle{empty}
\clearpage

\mychapter{1}{Introduction}
\blindtext

\appendix
\mychapter{2}{Appendix}



\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
MjK
Posts: 89
Joined: Fri Jan 28, 2022 6:09 pm

Issues with fancyhdr & newcommand for chapters

Post by MjK »

\vert is a mathmode command. But instead of using $\vert$, I would suggest to use a \rule[<vertical shift>]{<width>}{<height>}.
My main topics are KOMA-Script and other questions related to my packages. If I reply to any other topic or if you've not yet added a minimal working example, please do not expect any further response. And please don't forget to tag examples as code.
rocket2008
Posts: 2
Joined: Tue Feb 28, 2023 1:13 pm

Issues with fancyhdr & newcommand for chapters

Post by rocket2008 »

Thank you very much, MjK. I hadn't thought of that. And your solution works perfectly. As for aligning the text and the image, I finally figured it out with \raisebox:

Code: Select all

{
    \cfoot{ Page \thepage \ \ \rule[-0.2cm]{.05cm}{.8cm} \ \raisebox{-.2\height}{\includegraphics[scale=0.1]{example-image-a}}}

}    
This is my first post asking for help on a forum, be it LaTex or some programming language. I am always amazed by how helpful people are, and receiving such a prompt response is shocking. Thank you.
Post Reply