![调整图像大小,使其跨越纸张高度,同时修剪宽度以适合纸张宽度](https://linux22.com/image/428586/%E8%B0%83%E6%95%B4%E5%9B%BE%E5%83%8F%E5%A4%A7%E5%B0%8F%EF%BC%8C%E4%BD%BF%E5%85%B6%E8%B7%A8%E8%B6%8A%E7%BA%B8%E5%BC%A0%E9%AB%98%E5%BA%A6%EF%BC%8C%E5%90%8C%E6%97%B6%E4%BF%AE%E5%89%AA%E5%AE%BD%E5%BA%A6%E4%BB%A5%E9%80%82%E5%90%88%E7%BA%B8%E5%BC%A0%E5%AE%BD%E5%BA%A6.png)
标题可能说明了一切;我想要一个图形,首先将图像居中并调整其大小以适合纸张高度,然后修剪图像以适合纸张宽度。
到目前为止,我都是手动进行修剪,但这很繁琐,而且需要很长时间。纸张宽度和高度的原因是,它是我们项目的首页,打印在纸上和 pdf 格式中时看起来都很漂亮。
这是我迄今为止使用的代码(手动方式):
\usepackage{geometry}
\usepackage[percent]{overpic}
\usepackage[table]{xcolor} % for the custom frontpage color
\usepackage[breakable,most,skins,listings]{tcolorbox}
\begin{document}
\newgeometry{
top = 0 cm,
bottom = 0 cm,
right = 0 cm,
left = 0 cm
}
\begin{overpic}[trim=120pt 0pt 120pt 0pt, % <--- this is where the manual work is, the "problem"
height=\paperheight]
{frontpage.jpg} % <--- oversize image
\put(0,0){\begin{tcolorbox}[
enhanced,
width=\paperwidth,
arc=0mm,
boxsep=25pt,
toprule=0pt,
leftrule=0pt,
bottomrule=0pt,
rightrule=0pt,
colframe=frontpagecolor,
colback=frontpagecolor,
opacityframe=.6,
opacityback=.6,
fontupper=\raggedright]
{\color{white}
\Huge{\textbf{project title}}
\Large{\textit{project subtitle}}\\
\Large{\textit{project second line of subtitle}}
\vspace{0.5cm}
\large{
Semester project \\\vspace{5pt}
Group \\\vspace{5pt}
2\textsuperscript{nd} Semester \\\vspace{5pt}
University \\\vspace{5pt}
date 2021
}
}
\end{tcolorbox}
}
\put(60,85){\includegraphics[height=3.5cm]{institution_logo.png}}
\end{overpic}
\end{document}
因此,澄清一下,我想要的是一张“自行裁剪”的图像后正在缩放以适合纸张高度。
不要犹豫提出问题或者要求我澄清一些事情,找到解决方案符合我的利益:)
答案1
您已在加载 tikz,为什么不使用它?图像将自动裁剪以适合页面。
\documentclass{article}
\usepackage[table]{xcolor} % for the custom frontpage color
\usepackage[breakable,most,skins,listings]{tcolorbox}
\newsavebox\tempbox
\begin{document}
\savebox\tempbox{\begin{tcolorbox}[% for tikzpicture inside another tikzpicture
enhanced,
width=\paperwidth,
arc=0mm,
boxsep=25pt,
toprule=0pt,
leftrule=0pt,
bottomrule=0pt,
rightrule=0pt,
%colframe=frontpagecolor,% from overpic?
%colback=frontpagecolor,
opacityframe=.6,
opacityback=.6,
fontupper=\raggedright]
{\color{white}
\Huge{\textbf{project title}}
\Large{\textit{project subtitle}}\\
\Large{\textit{project second line of subtitle}}
\vspace{0.5cm}
\large{
Semester project \\\vspace{5pt}
Group \\\vspace{5pt}
2\textsuperscript{nd} Semester \\\vspace{5pt}
University \\\vspace{5pt}
date 2021
}
}%
\end{tcolorbox}}%
\begin{tikzpicture}[overlay,remember picture]
\node[opacity=1] at (current page.center) {\includegraphics[height=\paperheight]{example-image-a}};
\node[below] at (current page.north) {\usebox\tempbox};
\end{tikzpicture}%
\newpage
\end{document}
答案2
\documentclass{article}
\usepackage{lipsum} %% gives dummy text for this file
\usepackage{eso-pic,graphicx}
\AddToShipoutPictureBG{%
\AtPageLowerLeft{\includegraphics[width=\paperwidth,height=\paperheight]{example-image-a}}
}
\begin{document}
\lipsum
\end{document}