4

Ok, I'm trying to create this type of formatting for each of my pages:

enter image description here

Now, I want to have this on every single page, in the header on the right hand side. I currently have the following:

\usepackage{fancyhdr}
\fancyhead{}
\fancyhead[RO, LE]{
    
    \begin{table}[ht!]

    \begin{tabular}{c}
    safasf
    \end{tabular}
\label{lable:nonlin}
\end{table}

}
\fancyfoot{}
\fancyfoot[LE, RO]{\thepage}
\fancyfoot[LO, CE]{Chapter \thechapter}

\begin{document}
  \input{title}

  \chapter{Introduction}
  ...
  
  \chapter{Background}
  ...
  
  \chapter{Conclusion}
  ...

\end{document}
 

I want to have this header, on every page even on the chapter pages. Before, using normal text.. The header does not appear to be on the chapter page.

Could anyone offer any solutions or suggestions please?

7
  • Your example is not compilable because missing statements and documentclass. And the table is a floating one, I am not sure whether fancyheader will do with floats.
    – user31729
    Apr 16, 2014 at 22:48
  • The reason is that \chapter{} makes use of \thispagestyle{empty}.
    – Sigur
    Apr 16, 2014 at 22:48
  • Please complete your code to make it compile.
    – cfr
    Apr 16, 2014 at 22:52
  • @Sigur Chapter uses plain pagestyle.
    – user11232
    Apr 16, 2014 at 22:53
  • @HarishKumar, but with the option that the first page has no header. Am I right?
    – Sigur
    Apr 16, 2014 at 23:00

3 Answers 3

6

You can put tabular material inside the header. But if you use table (which is a float) it won't work. Also the chapter page is given plain page style by default. Hence you have to redefine the plain pagestyle to be fancy.

\documentclass[twoside]{book}
\usepackage{fancyhdr}
\fancyhead{}
\fancyhead[RO, LE]{
    \begin{tabular}[b]{c}
    safasf
    \end{tabular}
}
\fancyfoot{}
\fancyfoot[LE, RO]{\thepage}
\fancyfoot[LO, CE]{Chapter \thechapter}

\makeatletter
\let \ps@plain\ps@fancy
\makeatother

\pagestyle{fancy}

\begin{document}
%  \input{title}

  \chapter{Introduction}
  ...

  \chapter{Background}
  ...

  \chapter{Conclusion}
  ...

\end{document}

enter image description here

With colored line:

\documentclass[twoside,table]{book}
\usepackage{fancyhdr,xcolor}
\usepackage{xcolor}
\usepackage[margin=1in,headheight=0.5in]{geometry}

\fancyhead{}
\fancyhead[RO, LE]{%
    \begin{tabular}[b]{@{}l@{}}
    \arrayrulecolor{blue!75}
    safasf \\
           \\\hline
    \end{tabular}%
}
\fancyfoot{}
\fancyfoot[LE, RO]{\thepage}
\fancyfoot[LO, CE]{Chapter \thechapter}

\makeatletter
\let \ps@plain\ps@fancy
\makeatother

\pagestyle{fancy}

\begin{document}
%  \input{title}

  \chapter{Introduction}
  ...

  \chapter{Background}
  ...

  \chapter{Conclusion}
  ...

\end{document}

enter image description here

With \includegraphics:

\documentclass[twoside,table]{book}
\usepackage{fancyhdr,xcolor}
\usepackage{graphicx}
\usepackage[margin=1in,headheight=0.75in]{geometry}

\fancyhead{}
\fancyhead[RO, LE]{%
    \includegraphics[width=2in]{capture}%
}
\fancyfoot{}
\fancyfoot[LE, RO]{\thepage}
\fancyfoot[LO, CE]{Chapter \thechapter}

\makeatletter
\let \ps@plain\ps@fancy
\makeatother

\pagestyle{fancy}

\begin{document}
%  \input{title}

  \chapter{Introduction}
  ...

  \chapter{Background}
  ...

  \chapter{Conclusion}
  ...

\end{document}

enter image description here

You may also use a minpage wrapping around the \includegraphics for vertical position adjustment if needed.

8
  • Do you not get complaints about multiply defined labels?
    – cfr
    Apr 16, 2014 at 22:54
  • @cfr No. But that label I forgot Thanks.:)
    – user11232
    Apr 16, 2014 at 22:56
  • @Harish Kumar Thanks for the reply. But, how would I therefore put a boarder around the "sfsfsf" and make it right aligned even on the first page? It's kinda confusing
    – Phorce
    Apr 16, 2014 at 22:57
  • @user1326876 You want borders on all sides or only below as in your picture in the OP?
    – user11232
    Apr 16, 2014 at 22:58
  • @HarishKumar - Hey, as my graphic suggests, the idea is that it will look just like this but will be in the same location on everypage (i.e top right).. But, I could just use an image, let me try this.. Thanks
    – Phorce
    Apr 16, 2014 at 23:00
4

Since this is for all the pages, you could use the background package:

\documentclass{book}
\usepackage[scale=1,opacity=1,angle=0,color=black]{background}
\usepackage{tikzpagenodes}
\usepackage{fancyhdr}

\backgroundsetup{
contents={
  \tikz\node[draw,text width=4cm,anchor=south east,inner sep=10pt,outer sep=0pt] 
    {For office use only  \\[10pt] \rule{4cm}{0.4pt}};
  },
position={current page header area.south east} ,
nodeanchor=south east,
vshift=-\pgflinewidth 
}
\fancyhf{}
\fancyfoot{}
\fancyfoot[LE, RO]{\thepage}
\fancyfoot[LO, CE]{Chapter \thechapter}

\pagestyle{fancy}

\begin{document}

\chapter{Test chapter}
some text\clearpage some text

\end{document}

enter image description here

The tikzpagenodes package was used to have easy access to the header area.

1

An alternative to Harish Kumar's approach, a third option is to define a new environment called tablehere that won't float as displayed below.

\makeatletter
\newenvironment{tablehere}
{\def\@captype{table}}
{}
\makeatother

Same idea for images

\makeatletter
\newenvironment{figuehere}
{\def\@captype{figure}}
{}
\makeatother

enter image description here enter image description here enter image description here

Code

\documentclass[twoside]{book}
\usepackage{fancyhdr}

\makeatletter
\newenvironment{tablehere}
{\def\@captype{table}}
{}
\makeatother


\fancyhead{}
\fancyhead[RO, LE]{
    \begin{tablehere}
    \begin{tabular}[b]{|c|}\hline
    For office use only  \\[10pt] \rule{4cm}{0.4pt}
    \end{tabular}
    \end{tablehere}
}
\fancyfoot{}
\fancyfoot[LE, RO]{\thepage}
\fancyfoot[LO, CE]{Chapter \thechapter}

\makeatletter
\let \ps@plain\ps@fancy
\makeatother

\pagestyle{fancy}

\begin{document}
%  \input{title}

  \chapter{Introduction}
  ...

  \chapter{Background}
  ...

  \chapter{Conclusion}
  ...

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .