latexoverleaf

How to set logo on each page with tikz?


I want to set my logo on each page except the front page. Right now I am able to do it on one page with the following:

\begin{tikzpicture}[remember picture,overlay] \node[anchor=north east,inner sep=15pt] at (current page.north east){\includegraphics[scale=0.2]{Figures/logo.png}}; \end{tikzpicture}

This sets the logo at the right place but just at one page. How do I repeat this for every page?


Solution

  • On semi up-to-date LaTeX, you can use hooks:

    \documentclass{report}
    \usepackage{graphicx}
    \usepackage{tikz}
    \usepackage{blindtext}
    
    \title{The Title}
    \author{First Last}
    \date{}
    
    
    \begin{document}
    \maketitle
    
    \clearpage
    \AddToHook{shipout/background}{%
      \begin{tikzpicture}[remember picture,overlay]
        \node[anchor=north east,inner sep=15pt]
        at (current page.north east){\includegraphics[scale=0.2]{example-image-duck}};
      \end{tikzpicture}}
    \Blinddocument
    \end{document}
    

    If for some reason you keep an old version of LaTeX, you might need to use one of the packages, e.g. eso-pic or background etc.

    EDIT. On the second thought, you might actually try eso-pic as it gives you more flexibility. Note with eso-pic, you could also use saveboxes to create one instance of a logo upfront and only use its copy per each page--if you do so, remove remember picture or you will get warnings with redefined labels.

    Consider one example below where you expect:

    and here's the code for the example

    \documentclass{report}
    \usepackage{graphicx}
    \usepackage{tikz}
    \usepackage{eso-pic}
    \usepackage{blindtext}
    
    \title{The Title}
    \author{First Last}
    \date{}
    
    \newsavebox\logoone
    \newsavebox\logotwo
    \sbox\logoone{%
      \tikz[overlay]
      \node[anchor=north east, inner sep=15pt] at (current page.north east){%
        \includegraphics[scale=0.2]{example-image}};}
    
    \sbox\logotwo{%
      \tikz[overlay]
      \node[anchor=north east, inner sep=15pt] at (current page.north east){%
        \includegraphics[scale=0.2]{example-image-duck}};}
    
    
    \begin{document}
    \maketitle
    
    \chapter{Chapter with the logo one}
    \AddToShipoutPictureBG{\usebox\logoone}
    \Blindtext
    
    \chapter{Clear chapter}
    \ClearShipoutPictureBG
    \Blindtext
    
    \chapter{Chapter with the logo two}
    \AddToShipoutPictureBG{\usebox\logotwo}
    \Blindtext
    \end{document}