2

I would like to place a same image on the very top of every page belonging to the same section of the document. Is that possible?

See the example below, where the figure is a PNG one:

\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{graphicx}
\usepackage{babel}
\begin{document}

\section*{Section A}

\includegraphics{fig1}

A lot of contents spanning several pages. 

I would like to have the figure above repeated at the top of each page 
of Section A.

\section*{Section B}

\includegraphics{fig2}

A lot of contents spanning several pages. 

I would like to have the figure above repeated at the top of each page 
of Section B.

\end{document}

SUPPLEMENT

I have tried a different approach, by using fancyhdr package. (Please, see code below.) However, I am getting the problems that I show below. Any ideas?

PROBLEM 1

On the first page of the document.

PROBLEM 2

When returning to the plain style:

enter image description here

USED PICTURE

enter image description here

CODE I AM USING

\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{graphicx}

\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\usepackage{lipsum}

\fancypagestyle{logo}{
\fancyhf{}
\fancyhead[H]{\includegraphics[scale=0.5]{/tmp/x}}
\renewcommand{\headrulewidth}{0pt}
}

\makeatother

\usepackage{babel}
\begin{document}
\pagestyle{logo}

\lipsum[1-8]

\includegraphics[scale=0.5]{/tmp/x}

\pagestyle{plain}

\lipsum[1-7]
\end{document}
  • @KJO Thanks! Just added a minimal example. – Paul Smith May 31 at 21:43
  • @KJO Thanks! So let me ask the following: (1) Can your solution be adapted to emulate my second example, but without the problems I mentioned?; (2) Can one turn off inserting anything on the top of the page for certain and specified sections? – Paul Smith Jun 1 at 12:23
1

Ok have been playing with this and its just about a very minimal / basic solution. Version 1 (see later edits for V2 and V3 :-)

I had to borrow bits and pieces from several answers to get stable enough results however in Version 1 (based on section numbers) I broke one of your supplied requirements (the no numbers star in chapter/section definition)

I am working with each section having a number (which may not always be the case) and is contrary to your suppression to zero.

I am not allowing for right or left as such (I am assuming only right top corner) and if you want a section to be blank then you need a clear/blank image for the section. (However these points are addressed in version 2 later)

enter image description here

\documentclass[english,draft]{article}% use draft to observe numbering then remove for print run
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{graphicx}
\usepackage{babel}

\usepackage{calc}
\usepackage{everypage}
\renewcommand{\thesection}{\number\value{section}}%
\newlength\Hoffset \Hoffset 0.0cm
\newlength\Voffset \Voffset 0.5cm
\AddEverypageHook{%
    \smash{\hspace{\oddsidemargin}\hspace{\textwidth}\hspace{\Hoffset}%
    \raisebox{\Voffset-\headsep-\headheight-\topmargin}%
    {%
    \includegraphics[height=3cm,width=4cm]{example\thesection}
    }         }             }

\usepackage{lipsum} %remove after demo

\begin{document}

\section{Section A}% NOTe the star version will zero chapter counter thus blocking an image number

\includegraphics[width=12cm,height=9cm]{example\thesection}

A lot of contents spanning several pages. 
\newline
I would like to have the figure above repeated at the top of each page 
of Section A.
\lipsum[1-7]

\newpage % newpage is needed to split count from old section to new section
\section{Section B}
\includegraphics[width=12cm,height=9cm]{example\thesection}

A lot of contents spanning several pages. 

I would like to have the figure above repeated at the top of each page 
of Section B.
\lipsum[1-6]
\end{document}

Version 2

The question was expanded to include some on/off control of headers and I was not happy with initial tying into section numbers (that might be suppressed). For version 2, I used fancy header based on the amended Question. However do note there are still some weaknesses in this method.

I have forced the normal fancy and plain header to be identical but the system will still treat chapter pages (and some others) as different so with this approach I can not assign logos to the first page of the chapter (not a problem if that has the full image and later pages just echo it.) There are many more ways we could expand our use of fancyhdr however since we are distorting the normal usage, the next level of customisation would best be achieved by say switching to a more dedicated overlay per page using dedicated on off markers.

enter image description here

\documentclass[english]{book} % I suspect LyX may be adding to and shuffling this preamble I set to book to show dual sided  abilities
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{graphicx}

%--- just for the examples
\usepackage{mwe}
\usepackage{lipsum}
%---

\usepackage{fancyhdr,floatpag}
% globally remove fancy style rules since \pagestyle{plain} for chapters etc. = no header, and footer only contains page number centered
% set fancy to be similar default just have the page number
\fancyhf{}
\fancyfoot[C]{\textbf{\thepage}} % common method to use simple Bottom centre page numbers
\renewcommand{\headrulewidth}{0pt}% common method to blank (zero) the top header rule
\renewcommand{\footrulewidth}{0pt}

\fancypagestyle{plain}{%
\fancyhf{} % clear all header and footer fields
\fancyfoot[C]{\textbf{\thepage}} % except the center
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}}

\floatpagestyle{plain}% Page style for float-pages
%\usepackage[style=plain]{clrdblpg} this option will ensure verso pages are also plain

\fancypagestyle{logo}{%change LO,RE v RO,LE for opposite side or just C for centre
\fancyhf{}
\fancyhead[RO,LE]{\smash{\raisebox{0cm}{\includegraphics[scale=0.2]{x}}}}
\fancyfoot[C]{\textbf{\thepage}} % except the center
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}}

%the following is a lyx construct so although not used I am leaving in place
\makeatletter 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\makeatother

\begin{document}
\pagenumbering{arabic} % reset page number counter
\thispagestyle{logo}
\chapter{One}
\pagestyle{logo} %  If you want a fancy layout on a page containing \maketitle you must issue a \thispagestyle{fancy} after the \maketitle.
%\pagestyle{plain} % uncoment to reset
%
\lipsum[1-9]
\section{first still with logo}
\noindent\includegraphics[width=1.0\textwidth]{x.jpg}\newline\par\lipsum[10-12]
%
\newpage \pagestyle {plain} % if header style change is required it can usually be combined with \newpage at the same time
%\pagestyle{plain}
\section {without header image}
\noindent\begin{figure}[t]
  \centering
  \includegraphics[width=1.0\textwidth]{x.jpg}%
  \caption{Caption}
\end{figure}
Page style ``Plain'' default usually has only page number at bottom centre but no header.\newline\par
\lipsum[1-7]

\end{document}  

Version 3 - not related to sections (uses current page for start stop)

This is one of many ways a watermark can be applied based on a very basic Bg NoBg (More complex methods of selecting pages are possible) so for more specific control choices read the background manual.
In this example I exclude "logo" on first and last page and use 50% opacity on all others.

enter image description here

\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{fancyhdr}
\usepackage{graphicx}

\usepackage[ %<===== Add to preamble
placement=top,
opacity=0.5]{background}
\backgroundsetup{contents={\includegraphics[scale=0.04]{./tmp/x}}}

\makeatletter %<=====  Not needed here by TeX but as a LyX construct I am retaining for LyX users
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\makeatother %<=====  Not needed here by TeX but as a LyX construct I am retaining for LyX users

\usepackage{babel}

\pagestyle{fancy}% Change as you wish
\renewcommand{\headrulewidth}{0pt}
\fancypagestyle{plain}{ % Change as you wish
\fancyhf{}
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{0pt}
}

% for example use only
\usepackage{lipsum}

\begin{document}
\pagestyle{plain}
\NoBgThispage
Hello World my name is X

\noindent\includegraphics[scale=0.7]{./tmp/x}
\lipsum[1-8]
\BgThispage % we start logo on this page
\lipsum[1-7]
\NoBgThispage % we end logo this page
\end{document}
  • @K Thanks! Your solution works if one wants to have a picture for every section, and I would like to have a picture for only certain sections. Please, see the Supplement that I have added to my question. – Paul Smith Jun 1 at 9:38
  • @K Thanks! Your new solution seems to be what I need. Does it work with not numbered sections? My document does not have chapters, so that is OK. Will you share the LaTeX code? – Paul Smith Jun 2 at 0:24
  • @K Thanks! Your solution works almost fine! I find 2 problems: (1) With a different picture, a larger one, the whole picture is not shown on the header; (2) When a new section initiates in the middle of a page, its header overrides the header corresponding to the previous section (there is here a conflict, in which the previous section should have precedence over the current section). – Paul Smith Jun 2 at 11:25
  • @K Are you saying that it is possible to instruct LaTeX to put a picture on the top of specific pages? That is: Is it possible to tell LaTeX to put a picture on the top of pages 2 to 10, for instance? If that is possible, that would be a substitute solution to my problem! – Paul Smith Jun 2 at 11:58
  • @K That is it! Thanks for your help and patience! – Paul Smith Jun 2 at 21:56

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.