Watermark over Images & Portait to Landscape in LaTex
Here is a suggestion using a combination of package typearea
from the KOMA-Script bundle and package geometry
. Note that you can not use \newgeometry
to change the margins of the resulting landscape page. Its bottom margin will be about twice as large as its top margin.
To get the correct head and foot width on the landscape page I would use scrlayer-scrpage
instead fancyhdr
for header and footer.
Then an additional foreground layer can be defined and added to all layer page styles (@everystyle@
) or to a selected one (eg. scrheadings
). I presume that the text below the watermark should be still readable, so I use a tikz
node with opacity=.3
.
\documentclass[10pt]{article}
\usepackage[
headheight=24pt,footheight=24pt,% as suggested by scrlayer-scrpage
areasetadvanced
]{typearea}% load this before geometry!!
\usepackage[top=2.5cm, bottom=3cm, hmargin=2cm]{geometry}
\AtBeginDocument{\savegeometry{default}}
\newcommand\switchtolandscape{%
\clearpage
\KOMAoptions{paper=landscape}\recalctypearea
\areaset{\dimexpr\paperwidth-4cm\relax}{\dimexpr\paperheight-7cm\relax}%
}
\newcommand\switchtoportrait{%
\clearpage
\KOMAoptions{paper=portrait}\recalctypearea
\loadgeometry{default}%
}
\usepackage{tikz}%loads graphicx and xcolor
\usepackage[headsepline]{scrlayer-scrpage}
\clearpairofpagestyles
\ohead{Header\\Date}
\cfoot{Footer}
\ofoot{•\\\pagemark}
\addtokomafont{pageheadfoot}{\normalfont}
\addtokomafont{pagefoot}{\bfseries}
\DeclareNewLayer[
foreground,
textarea,
contents={\tikz\node
[minimum width=\layerwidth,minimum height=\layerheight,text=red,opacity=.3]
{\rotatebox{45}{\scalebox{8}{\textsc{Draft}}}};%
}
]{watermark.fg}
\AddLayersToPageStyle{@everystyle@}{watermark.fg}% comment this to remove the watermark
\usepackage{blindtext}% only for dummy text
\begin{document}
\Blindtext
\switchtolandscape
\begin{figure}[htb]
\begin{center}
\fbox{\textcolor{yellow!20}{\rule{.9\textwidth}{.9\textheight}}}
\caption{Caption rotates with image as wanted}
\end{center}
\end{figure}
\switchtoportrait
\Blindtext
\end{document}
Result:
Related videos on Youtube
Kypraiou Theodora
Updated on August 01, 2022Comments
-
Kypraiou Theodora over 1 year
I'm having problem with two separate things.
- The first is, that I can't put a watermark over the images. As you can see in the comments, I have tried many different ways, but none of them works correctly or do what I want. And I can't understand why (this is my first document in LaTeX).
- The second thing I need to do, is to change a certain page in my document, from Portrait to Landscape. But the thing is, that I want the whole page to change into Landscape. Meaning the Header and Footer too, and thus I don't want to rotate the page. I have also tried different ways but none of them works as wanted.
I have simplified my code so you can only see one page and not the whole document. Can anyone please help me?
\documentclass[10]{article} \usepackage{graphicx} %Pictures \usepackage{fancyhdr} %Header-Footer \usepackage{pdflscape} %Landscape \usepackage{lscape} %Landscape \usepackage[top=2.5cm, bottom=3cm, left=2cm, right=2cm]{geometry} %Page Margins \usepackage{draftwatermark} %Works but does not set watermarks over image %\usepackage[printwatermark]{xwatermark} %Doesn't work \usepackage{xcolor} %Color Manipulation %\newsavebox\mybox %Doesn't work %\savebox\mybox{\tikz[color=red,opacity=0.3]\node{DRAFT};} %Doesn't work %\newwatermark*[ allpages, angle=45, scale=6, xpos=-20, ypos=15]{\usebox\mybox} %https://tex.stackexchange.com/questions/132582/transparent-foreground-watermark %\SetWatermarkText{\includegraphics{draft.png}} %Doesn't work %https://tex.stackexchange.com/questions/61137/watermark-image \graphicspath{{C:\Path...}} %path for pictures \pagestyle{fancy} \fancyhf{} \fancyfoot[R]{} \newpage \pagestyle{fancy} \fancyhf{} \fancyhead[R]{Header \\ Date} \fancyfoot[C]{\textbf{Footer}} \fancyfoot[R] {\textbf{•}\\ \thepage} % \textbf{•} is empty, therefore No. of page is in 2nd line \begin{document} %\newwatermark*[page=2-\lastdocpage,color=red!50,angle=45,scale=3,xpos=0,ypos=0]{\textsc{draft}} %Doesn't work %https://tex.stackexchange.com/questions/118939/add-watermark-that-overlays-the-images \SetWatermarkText{\textsc{draft}} %Works but does not set watermarks over image as wanted \SetWatermarkScale{3} %Works but does not set watermarks over image as wanted \SetWatermarkColor[gray]{0.75} %Works but does not set watermarks over image as wanted \begin{landscape} \begin{figure}[h!] \begin{center} \fbox{\includegraphics[scale=0.80]{11.png}} \caption{Caption rotates with image as wanted} \end{center} \end{figure} \end{landscape} \end{document}
-
Huang_d over 6 yearsFor the portrait to landscape change, have a look at the
geometry
package. It allows to create a new page layout and resetting it. -
Kypraiou Theodora over 6 years@Huang_d from (ftp.cc.uoc.gr/mirrors/CTAN/macros/latex/contrib/geometry/…), I read that papersize-related options and paper size options can’t be changed with geometry package (I also tried it to be sure). But thank's anyway!!
-
Huang_d over 6 yearsI see. I just remembered it allowed
\newgeometry
andrestoregeometry
. Sorry for the misinformation. -
Kypraiou Theodora over 6 years@Huang_d thank you very much for your time!!
-
Kypraiou Theodora over 6 yearsthank you very much!! It works perfect!! But I have one more question. How can I remove the blank page that was created before the landscaped page? (Of course I didn't create that page and I can't find a way to do that).
-
esdd over 6 yearsProbably the picture is too high to fit on the page. Shrink its height a bit.
-
Kypraiou Theodora over 6 yearsI tried, but the blank page still exists. I also tried \nopagebreak but as you can image, nothing changed. I have found something about the \afterpage package and I'm trying to find more about it.
-
Kypraiou Theodora over 6 yearsI removed the blank page, by deleting \clearpage from \newcommand\switchtolandscape{}. Thank's again!!