TransWikia.com

How to align an image to the top of page/paper using tikz?

TeX - LaTeX Asked on July 26, 2021

I have an image which spans the paperwidth. I have added the image by setting its width = paperwidth and anchoring it at (current page.north) or at (current page.center) using tikz. Now to align the top edge of the image I had to manually add a yshift with trial and error to make it work. Is there any way in which the image can be made to align to the top of the page automatically? I have several images of varying heights and hence doing this manually would mean to adjust yshift for each image separately. I tried to use shift={(current page.north) along the line suggested here, but somehow it leaves a small gap between the top and the image. How do I achieve this without a manual adjustment?

MWE

documentclass{article}

usepackage{tikz}

begin{document}
begin{tikzpicture}[remember picture,overlay] 
 node  [yshift=-9.45cm] at (current page.north) {includegraphics[width=paperwidth]{Rose.jpg}};
end{tikzpicture}


end{document}

Source for the image: https://upload.wikimedia.org/wikipedia/commons/a/ac/Rose_hip_02_ies.jpg

One Answer

Using the options anchor=north, inner sep=0pt seems to place it at the correct spot:

enter image description here

I have included the showframe package so that it is clear where the normal text would go.

Note:

  • The small gray border is an artifact of the image capture process.

Code:

documentclass{article}

usepackage{tikz}
usepackage{showframe}

begin{document}
begin{tikzpicture}[remember picture,overlay] 
 node  [anchor=north, inner sep=0pt] at (current page.north) 
     {includegraphics[width=paperwidth]{../images/Rose.jpg}};
end{tikzpicture}%

end{document}

Correct answer by Peter Grill on July 26, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP