在 LaTex 中将图像上的水印和肖像转换为风景

在 LaTex 中将图像上的水印和肖像转换为风景

我遇到了两件不同的事情的问题。

  1. 首先,我无法在图像上添加水印。正如您在评论中看到的,我尝试了许多不同的方法,但没有一种能正常工作或满足我的要求。我不明白为什么(这是我的第一份 LaTeX 文档)。
  2. 我需要做的第二件事是将文档中的某一页从纵向更改为横向。但问题是,我希望整个页面都变成横向。这意味着页眉和页脚也是如此,因此我不想旋转页面。我也尝试了不同的方法,但都没有达到预期的效果。

我已经简化了代码,所以您只能看到一页,而不是整个文档。有人能帮帮我吗?

\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}

答案1

这里建议使用typeareaKOMA-Script 包中的包和包的组合geometry。请注意,您不能使用\newgeometry来更改生成的横向页面的边距。其底部边距将大约是其顶部边距的两倍。

为了在横向页面上获得正确的头部和脚部宽度,我将使用scrlayer-scrpage页眉fancyhdr和页脚。

然后可以定义一个额外的前景层并将其添加到所有图层页面样式(@everystyle@)或选定的图层页面样式(例如scrheadings)。我推测水印下方的文本应该仍然可读,所以我使用tikz带有的节点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}

结果:

在此处输入图片描述

相关内容