标题可能说明了一切;我想要一个图形,首先将图像居中并调整其大小以适合纸张高度,然后修剪图像以适合纸张宽度。
到目前为止,我都是手动进行修剪,但这很繁琐,而且需要很长时间。纸张宽度和高度的原因是,它是我们项目的首页,打印在纸上和 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}