我想为班级撰写一个标题scrlttr2
,我的徽标横跨顶部,但我需要能够写入该徽标。这是我目前得到的结果:
\documentclass{scrlttr2}
\usepackage{graphicx}
\usepackage{lipsum}
% header picture on first page
\usepackage{eso-pic}
\AddToShipoutPictureBG*{%
\AtPageUpperLeft{%
\raisebox{-\height}{%
\hspace*{1in}%
\includegraphics[width=\textwidth,height=1in]{example-image-a}
}%
}
}
\setkomavar{firsthead}{%
\hspace*{3cm}%
\raisebox{5.5cm}{
\parbox{3cm}{
\scriptsize
\textbf{THIS}\\[.2em]
\textbf{IS}\\[.2em]
\textbf{MY}\\[.2em]
\textbf{LOGO}
}}
\hspace*{\fill}%
\raisebox{3cm}{
\parbox{0.2\hsize}{%
\scriptsize
\usekomavar*{fromphone}\usekomavar{fromphone}\\
\usekomavar*{fromfax}\usekomavar{fromfax}\\
\usekomavar*{fromemail}\usekomavar{fromemail}\\[1em]
}}%
}
% sender
\setkomavar{fromname}{Aaron Berentsen}
\setkomavar{fromaddress}{Ceestreet 1\\Deetown}
\setkomavar{fromphone}{+12345678}
\setkomavar{fromfax}{+12345679}
\setkomavar{fromemail}{[email protected]}
% date
\setkomavar{date}{\today}
% subject
\setkomavar{subject}{Subject}
\begin{document}
\begin{letter}{Addressee}
\opening{Dear Addresse,}
\lipsum[1]
\closing{Best wishes,}
\end{letter}
\end{document}
但是我想对齐(居中)徽标,使得它的左边缘与地址框对齐,并且我想将其降低,使得它从顶部离开默认标题空间(大致由红色注释表示)。
根据 Koma 指南,顶部空间似乎为firstheadvpos
,左缩进应为firstheadhpos
,覆盖头部的图像宽度应为fromrulewidth
。但我不知道如何使用这些长度。
我使用该类eso-pic
是为了能够在徽标图像本身上写入内容,这也是一项要求。我可能需要替换
\raisebox{-\height-\useplength{firstheadvpos}}
和\hspace*{\useplength{firstheadhpos}}
和\includegraphics[width=\useplength{fromrulewidth},...
但看起来并不是这样。有什么建议吗?
编辑:只是为了澄清一下:我使用了eso-pic
以便能够在徽标上书写,所以这已经起作用了。我的问题只是如何使用伪长度来告诉 iso-pic 如何定位它,以便它正好适合标题区域(相同位置,相同大小),即它具有相同的顶部和左侧边距以及相同的宽度。
答案1
我将使用包scrlayer
并定义一个新的页面样式,使用伪长度将图片定位到所需的位置:
\usepackage{scrlayer}
\DeclareNewLayer[
background,
voffset=\useplength{firstheadvpos},
hoffset=\useplength{toaddrhpos},
width=\useplength{firstheadwidth},
contents={\includegraphics[width=\layerwidth,height=1in]{example-image-a}}
]{firstheadpicture}
\DeclareNewPageStyleByLayers{firstpage}{firstheadpicture}
第一个字母页面empty
默认使用页面样式。我将修补\opening
以覆盖此默认页面样式:
\usepackage{xpatch}
\xapptocmd\opening{\thispagestyle{firstpage}}{}{\PatchFailed}
fromemail
等应该转到位置字段:
\setkomavar{location}{\scriptsize
\usekomavar*{fromphone}\usekomavar{fromphone}\\
\usekomavar*{fromfax}\usekomavar{fromfax}\\
\usekomavar*{fromemail}\usekomavar{fromemail}
}
\setplength[.2]{locwidth}{\useplength{firstheadwidth}}% <- change the width of location to the desired value
例子:
\documentclass{scrlttr2}
%% to show the position of first head and location:
%\LoadLetterOption{visualize}
%\showfields{head,location}
\usepackage{graphicx}
\usepackage{lipsum}% only for dummy text
% picture in the background of first head
\usepackage{scrlayer}
\DeclareNewLayer[
background,
voffset=\useplength{firstheadvpos},
hoffset=\useplength{toaddrhpos},
width=\useplength{firstheadwidth},
contents={\includegraphics[width=\layerwidth,height=1in]{example-image-a}}
]{firstheadpicture}
\DeclareNewPageStyleByLayers{firstpage}{firstheadpicture}
\usepackage{xpatch}
\xapptocmd\opening{\thispagestyle{firstpage}}{}{\PatchFailed}
% first head
\setkomavar{firsthead}{%
\vskip .5cm%
\noindent\hspace*{3cm}%
\parbox{3cm}{\scriptsize\bfseries
THIS\\[.2em]
IS\\[.2em]
MY\\[.2em]
LOGO
}
}
% location
\setkomavar{location}{\scriptsize
\usekomavar*{fromphone}\usekomavar{fromphone}\\
\usekomavar*{fromfax}\usekomavar{fromfax}\\
\usekomavar*{fromemail}\usekomavar{fromemail}
}
\setplength[.2]{locwidth}{\useplength{firstheadwidth}}% <- change the width of location to the desired value
% sender
\setkomavar{fromname}{Aaron Berentsen}
\setkomavar{fromaddress}{Ceestreet 1\\Deetown}
\setkomavar{fromphone}{+12345678}
\setkomavar{fromfax}{+12345679}
\setkomavar{fromemail}{[email protected]}
% date
%\setkomavar{date}{\today}% default
\begin{document}
\begin{letter}{Addressee}
\setkomavar{subject}{Subject}% maybe you write more than one letter with different subjects in this document
\opening{Dear Addresse,}
\lipsum
\closing{Best wishes,}
\end{letter}
\end{document}
你可以使用
\LoadLetterOption{visualize}
\showfields{head,location}% address, foot and refline are also possible
在序言中表明head
和的位置location
。
答案2
我不确定我是否理解了你的问题。编写新的信头并不那么容易。也许我们可以忽略“firsthead”(firsthead=off
)的想法,并手动将元素放在页面上。
\documentclass[firsthead=off]{scrlttr2}
\usepackage{graphicx}
\usepackage{lipsum, picture, calc, booktabs}
% header picture on first page
\newlength{\xlength}
\newlength{\ylength}
\setlength{\xlength}{20mm}
\setlength{\ylength}{-40mm}
\usepackage{eso-pic}
\AddToShipoutPictureBG*{%
\AtPageUpperLeft{%
\put(\xlength, \ylength){
\includegraphics[width=\textwidth + 20mm,height=1in]{example-image-a}}
\put(\xlength,.5\ylength){
\scriptsize\textbf{~This is my logo}
}
\put(\xlength,\ylength+2\baselineskip){%
\begin{tabular}{ll}\toprule
Even a & tabular\\
may & follow!\\\bottomrule
\end{tabular}
}
}
}
\addtoplength{firstheadvpos}{-.3\ylength}
\addtoplength{locvpos}{5cm}
\setkomavar{fromname}{Aaron Berentsen}
\setkomavar{fromaddress}{Ceestreet 1\\Deetown}
\setkomavar{fromphone}{+12345678}
\setkomavar{fromfax}{+12345679}
\setkomavar{fromemail}{[email protected]}
\setkomavar{location}{%
\scriptsize
\begin{tabular}{ll}
\usekomavar*{fromphone}&\usekomavar{fromphone}\\
\usekomavar*{fromfax}&\usekomavar{fromfax}\\
\usekomavar*{fromemail}&\usekomavar{fromemail}\\[1em]
\end{tabular}
}
% sender
% date
\setkomavar{date}{\today}
% subject
\setkomavar{subject}{Subject}
\begin{document}
\begin{letter}{Addressee}
\opening{Dear Addresse,}
\lipsum[1]
\closing{Best wishes,}
\end{letter}
\end{document}
答案3
不确定我是否完全理解这个问题,但您可以使用\stackinset
它在图像上叠加文本。
\documentclass{scrlttr2}
\usepackage{graphicx}
\usepackage{lipsum,stackengine}
% header picture on first page
\usepackage{eso-pic}
\AddToShipoutPictureBG*{%
\AtPageUpperLeft{%
\raisebox{-\height}{%
\hspace*{1in}%
\stackinset{r}{.8in}{c}{0in}{\parbox{1in}{\scriptsize
\usekomavar*{fromphone}\usekomavar{fromphone}\\
\usekomavar*{fromfax}\usekomavar{fromfax}\\
\usekomavar*{fromemail}\usekomavar{fromemail}}}{%
\stackinset{l}{1in}{c}{0in}{\parbox{1in}{\scriptsize\bfseries
THIS\\IS\\MY\\LOGO}}{%
\includegraphics[width=\textwidth,height=1in]{example-image-a}%
}}%
}%
}%
}
\setkomavar{firsthead}{}
% sender
\setkomavar{fromname}{Aaron Berentsen}
\setkomavar{fromaddress}{Ceestreet 1\\Deetown}
\setkomavar{fromphone}{+12345678}
\setkomavar{fromfax}{+12345679}
\setkomavar{fromemail}{[email protected]}
% date
\setkomavar{date}{\today}
% subject
\setkomavar{subject}{Subject}
\begin{document}
\begin{letter}{Addressee}
\opening{Dear Addresse,}
\lipsum[1]
\closing{Best wishes,}
\end{letter}
\end{document}