1

To be more consistent in the personal/internal documents I write, I'd like to modify my class to allow me to pass an option that will automatically select an image to put in the footer on the first page so what group I did the work for is readily seen at a glance. I'm not sure how to do it from here.

I have tried this:

    \DeclareOption{groupA}{\def\@affiliation{Group A}}
    \ProcessOptions \relax

In the footer definition, I added:

    \@ifundefined{\@affiliation}{\def\@affiliation{none}}{}
    \ifthenelse{\equal{\@affiliation}{\string groupA}}
        {\includegraphics[height=2cm]{groupA_logo.png}}
        {\@affiliation}

This was just to start trying it out, so it would include an image if I passed the groupA option through \documentclass[groupA]{myreports}, and just type out the affiliation if I use groupB or pass nothing.

This doesn't work out, though--my footer only gets the word none printed. Any ideas on how I could get something like this to work?

As requested, here's an MWE. myreports.cls:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{myreports}[2015/07/28]
% - Declaration of options
\DeclareOption{letterpaper}{\PassOptionsToPackage{\CurrentOption}{geometry}}
\DeclareOption{groupA}{\def\@affiliation{Group A}}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
% ----- Execution of options
\ExecuteOptions{letterpaper}
\ProcessOptions \relax
\LoadClass{article}
% - Page Layout
\RequirePackage[left=2.5cm,right=2.5cm,top=2.5cm,bottom=2.5cm]{geometry}
\RequirePackage{graphicx}
\RequirePackage{fancyhdr}
\RequirePackage{ifthen}
% - Header and Footer Definitions
\fancypagestyle{firstpage}{
    \fancyhf{}
    \setlength\headheight{48pt}
    \setlength\headsep{-7pt}
    \fancyhead[C]{\begin{center}
        First Page Header
    \end{center}}
    \fancyfoot[C]{
        \@ifundefined{\@affiliation}{\def\@affiliation{none}}{}
        \ifthenelse{\equal{\@affiliation}{Group A}}
            {I'm in \@affiliation}
            {Don't recognize \@affiliation}
   }
}
\pagestyle{fancy}
\fancyhf{}
\setlength\headheight{48pt}
\setlength\headsep{-7pt}
\fancyhead[CE,CO]{\begin{center}
    Subsequent Pages Header
\end{center}}
\fancyfoot[CE,CO]{\thepage}
% - maketitle Definition
\makeatletter
\def\maketitle{
    \thispagestyle{firstpage}
    \par\textsc{\huge\@title}
    \par\vspace{7pt}{\large\@author}
    \vspace{21pt}
    \par
}
\makeatother
\endinput

And test.tex:

\documentclass[groupA]{myreports}
\usepackage{lipsum}
\title{A Titled Report}
\author{It's Me!}
\begin{document}
\maketitle
\lipsum[1-14]
\end{document}
  • Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – user31729 Jul 28 '15 at 18:25
1

Well, I was able to come up with a solution, though it changes track from what I was trying before. I do like this idea better, though, as it directly allows having more than one affiliation on a document.

I solved it by using \newif\if@groupA and then just simple \if@groupA {} \fi statements. I'll attach the resulting class below.

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{myreports}[2015/07/28]
\newif\if@groupA
\@groupAfalse
% - Declaration of options
\DeclareOption{letterpaper}{\PassOptionsToPackage{\CurrentOption}{geometry}}
\DeclareOption{groupA}{\@groupAtrue}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
% ----- Execution of options
\ExecuteOptions{letterpaper}
\ProcessOptions \relax
\LoadClass{article}
% - Page Layout
\RequirePackage[left=2.5cm,right=2.5cm,top=2.5cm,bottom=2.5cm]{geometry}
\RequirePackage{graphicx}
\RequirePackage{fancyhdr}
\RequirePackage{ifthen}
% - Header and Footer Definitions
\fancypagestyle{firstpage}{
    \fancyhf{}
    \setlength\headheight{48pt}
    \setlength\headsep{-7pt}
    \fancyhead[C]{\begin{center}
        First Page Header
    \end{center}}
    \fancyfoot[C]{
        \if@groupA
            I'm in group A
        \else
            I'm not in group A
        \fi
   }
}
\pagestyle{fancy}
\fancyhf{}
\setlength\headheight{48pt}
\setlength\headsep{-7pt}
\fancyhead[CE,CO]{\begin{center}
    Subsequent Pages Header
\end{center}}
\fancyfoot[CE,CO]{\thepage}
% - maketitle Definition
\makeatletter
\def\maketitle{
    \thispagestyle{firstpage}
    \par\textsc{\huge\@title}
    \par\vspace{7pt}{\large\@author}
    \vspace{21pt}
    \par
} 
\makeatother
\endinput
  • You have plenty of spurious spaces. – egreg Jul 28 '15 at 22:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.