3

I use this code to display an image in the upper right corner. It is displayed on all pages, including the title page.

The important thing is to know how to show only in the content pages, that is, not to show it in the title pages (front, back cover, acknowledgments), nor in the table of contents, nor in the list of tables, nor in the list of figures.

I would also like to know how I can use LaTex to find out the height and width of the image in points. And use those height and width values to adjust the position, 0.5\valuewidth, 0.5\valueheight, and not like now that I do it manually.

The image I use is 6cm in height and width. And I use \put() to adjust it.

\documentclass{article}
\usepackage{eso-pic,xcolor}
\usepackage{graphicx}
\usepackage{transparent}

\newcommand\AtPageUpperRight[1]{\AtPageUpperLeft{ \makebox[\paperwidth][r]{#1}}} \AddToShipoutPictureBG{ \put(80,85){%Desplazamos la imagen \AtPageUpperRight{ \raisebox{-\height}{ \transparent{0.10}\includegraphics{images/logo/molino6.0cm.png} } } } }

2 Answers2

4

You can build a condition into the \AddToShipoutPictureBG, which allows you control over when to publish the image and when not to. Below I define \ifPicture that you can set to true - \Picturetrue - if you want a picture on that page or false - \Picturefalse - if you don't. Using \clearpage ensures you're closing off the current page and separating the document elements similar to \frontmatter, \mainmatter and \backmatter would in larger document classes (like book and report).

enter image description here

\documentclass{article}
\usepackage{eso-pic,xcolor}
\usepackage{graphicx,lipsum}
\usepackage{transparent}

\newcommand\AtPageUpperRight[1]{% \AtPageUpperLeft{% \makebox[\paperwidth][r]{#1}% }% }

\AddToShipoutPictureBG{ \ifPicture \AtPageUpperRight{% \raisebox{-\height}{% \transparent{0.10}\includegraphics[width=6cm]{example-image}% }% }% \fi }

\newif\ifPicture

\begin{document}

\Picturefalse

\tableofcontents

\listoffigures

\listoftables

\clearpage \Picturetrue

\section{First section}\lipsum[1-10] \begin{figure}\caption{A figure}\end{figure} \subsection{First subsection}\lipsum[11-20] \begin{table}\caption{A table}\end{table} \subsection{Second subsection}\lipsum[21-30] \begin{figure}\caption{Another figure}\end{figure} \subsection{Last subsection}\lipsum[31-40] \begin{table}\caption{Another table}\end{table}

\clearpage \Picturefalse

\section{Last section}\lipsum[1-10] \begin{figure}\caption{A figure}\end{figure} \subsection{First subsection}\lipsum[11-20] \begin{table}\caption{A table}\end{table} \subsection{Second subsection}\lipsum[21-30] \begin{figure}\caption{Another figure}\end{figure} \subsection{Last subsection}\lipsum[31-40] \begin{table}\caption{Another table}\end{table}

\end{document}

There's no real need to know the width/height of the image, since it's lowered into place (via \raisebox{-\height}) without knowing the actual height. Additionally, you had some spurious spaces in your definitions which caused the image placement to not be flush with the right page boundary.

Werner
  • 603,163
  • Good input. I do need to know the width and height of the image because I am cropping the image for aesthetic reasons. How could I use LaTex to find out the dimensions, height and width, of the image? – José Carlos Nov 22 '21 at 12:52
  • @JoséCarlos: You can use the trim and clip options of \includegraphics to crop the image. Alternatively, use adjustbox. See Trim, crop, and resize picture; there you have access to \Width and \Height. The other answer sets the image in a box \sbox{\mybox}{\includegraphics[.]{..}} after which the width/height is available as \wd\mybox/\ht\mybox. – Werner Nov 22 '21 at 17:03
1

Try using fancyhdr instead of esopic

\documentclass{article}
\usepackage{mwe} % for sample image
\usepackage[head=1cm]{geometry}
\usepackage{lipsum} % for sample text
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\rhead{\includegraphics[height=1cm]{example-image-a}}
\renewcommand{\headrulewidth}{0pt} 
\begin{document}
\lipsum
\end{document}

enter image description here

You can manually remove the header from a page with \pagestyle{empty} or changing the documentclass to something like book would help you only put it on content pages.

Dan
  • 3,699