Page LayoutNo headrule after first page.

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
lvleph
Posts: 3
Joined: Thu Feb 03, 2011 1:21 am

No headrule after first page.

Post by lvleph »

So I am trying to figure out how to get rid of the line at the bottom of my header on pages after the first page. I have figure out how to have a different header on the first page, but I still can't seem to get rid of the headrule on subsequent pages. Below is the relevant code. I have tried placing the headrule in the if statement, but this didn't seem to work. Attached is the class file and an example.

Code: Select all

\RequirePackage{fancyhdr}
\pagestyle{fancy}
\fancyhead[L]{
	\if \thepage 1 
		\test@semester \hspace{15mm} \test@class\ \ --\ \ Test \test@test \\ Justify ALL work using complete sentences! Use only \underline{methods from class}.
	\else  
	\fi
}
\fancyhead[C]{
	\if \thepage 1 
		\test@testdate \linebreak
	\else
	\fi
}
\fancyhead[R]{
	\if \thepage 1 
		NAME:\ \line(1,0){140} \\
		CRN:\ \line(1,0){140} 
	\else
	\fi
}

\fancyfoot[L]{
	\if \thepage \getpagerefnumber{LastPage}
		\textbf{Honor Pledge:} I have neither given nor received help on this exam. Signed: \line(1,0){130}
	\else
	\fi
}
\fancyfoot[C]{
	\if \thepage 1
		\thepage/\pageref{LastPage}
	\else
	\fi
}
\fancyfoot[R]{}
\renewcommand\headrulewidth{0.5pt}
Attachments
test_example.tex
(364 Bytes) Downloaded 267 times
test.cls
(5.82 KiB) Downloaded 244 times
Last edited by lvleph on Sun Feb 06, 2011 5:31 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

No headrule after first page.

Post by frabjous »

The normal way of dealing with different headers and footers on different pages is to use "page styles". The fancyhdr package allows you to re-define page styles like "plain". See, e.g., page 7 of its documentation. Since you're putting this into the documentclass itself, you could use \AtBeginDocument to set the pagestyle to plain for the first page. This would eliminate the need for most of your conditionals as well. E.g., something like this:

Code: Select all

% Setup the header and footer
\RequirePackage{fancyhdr}

%make the first page plain style
\AtBeginDocument{\thispagestyle{plain}}
% redefine plain style
\fancypagestyle{plain}{
        \fancyhead[L]{%
        \test@semester \hspace{15mm} \test@class\ \ --\ \ Test \test@test \\ Justify ALL work using complete sentences! Use only \underline{methods from class}.% 
        }
\fancyhead[C]{%
		\test@testdate \linebreak%
    }
\fancyhead[R]{%
		NAME:\ \line(1,0){140} \\
		CRN:\ \line(1,0){140}%
    }
\fancyfoot[C]{%
		\thepage/\pageref{LastPage}
    }
\renewcommand\headrulewidth{0.5pt}
}

% other pages have fancy pagestyle
\pagestyle{fancy}
% define fancy style
\fancyhf{}
\fancyfoot[L]{
	\if \thepage \getpagerefnumber{LastPage}
		\textbf{Honor Pledge:} I have neither given nor received help on this exam. Signed: \line(1,0){130}
	\else
	\fi
}
\renewcommand\headrulewidth{0pt}
Actually you could probably get rid of the need for the last page conditional as well using another page style (...packages like titlesec allow you to define new ones...) and the \AtEndDocument command.

If for some reason you really want to use fancy page style on every page, I guess you could give \headrule itself a conditional definition:

Code: Select all

\let\oldheadrule=\headrule
\renewcommand{\headrule}{\if\thepage 1\oldheadrule\else\fi}
Somehow that feels like a kludge, however.
lvleph
Posts: 3
Joined: Thu Feb 03, 2011 1:21 am

Re: No headrule after first page.

Post by lvleph »

Much better way of doing things. I will try this when I get a change.
lvleph
Posts: 3
Joined: Thu Feb 03, 2011 1:21 am

Re: No headrule after first page.

Post by lvleph »

Thank you, the only thing I had to add was the page number for pages in between the first page and the last page.
Post Reply