Scrlttr2 自定义 firsthead

Scrlttr2 自定义 firsthead

我想在默认布局的基础上测试两种页眉布局。第一个页眉右上角没有回信地址,标题居中。 标题1

在第二个标题中,返回地址应该从与带下划线的返回地址相同的垂直空间级别开始。 在此处输入图片描述

我读到这\firsthead是创建自定义标题的正确命令,但我不知道在哪里可以找到默认标题骨架。所以我不知道从哪里开始获取对象之间的所有垂直和水平空间或边距。

\documentclass[a4paper,
    pagenumber=false,
    parskip=full,
    fontsize=11pt,
    firstfoot=false,
    fromalign=right,
    fromphone=true,
    fromemail=true,
    fromrule=false,
    foldmarks=false,
    enlargefirstpage,
]{scrlttr2}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc} 
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage{marvosym}   
\usepackage{blindtext}

\newcommand{\myFirstname}{John}
\newcommand{\myFamilyname}{Doe}
\newcommand{\myStreet}{3500 West Olive Avenue}
\newcommand{\myTown}{Burbank, CA 91505-5512}


\setkomavar{date}{\today} 
\setkomavar{fromname}{\myFirstname\ \myFamilyname}
\setkomavar{signature}{\myFirstname\ \myFamilyname}
\setkomavar{fromaddress}{\myStreet\\\myTown}
\setkomavar{backaddress}{\myFirstname\ \myFamilyname, \myStreet , \myTown}
\setkomavar{place}{Burbank}
\setkomavar{fromphone}[\Mobilefone\,]{(01\,23)\,45\,67\,89\,10}
\setkomavar{fromemail}[\Letter\,]{[email protected]}

\renewcommand*\familydefault{\sfdefault}



\setkomavar{subject}{Dies hier ist ein Blindtext zum Testen von Textausgaben.
}
\begin{document}
%
\begin{letter}{Richard M Winsor\\
2192 Lawman Avenue\\ 
Arlington\\
22204 Virginia
}
%
\opening{Dear Mr Winsor,}
%
\blindtext[1]
\noindent \blindtext[4]


\closing{\raggedright Yours sincerely,}
\end{letter}

\end{document}

答案1

可以使用 将您的地址放置在收件人地址旁边fromalign=location。遗憾的是,在这种情况下,您不能使用变量firsthead来设置标题。但您可以使用 或scrlayerscrlayer-scrpage生成所需的页眉。这里有一个简单的解决方案scrlayer-scrpage

\documentclass[a4paper,
    pagenumber=false,
    parskip=full,
    fontsize=11pt,
    fromalign=location,
    firstfoot=false,
    fromphone=true,
    fromemail=true,
    fromrule=false,
    foldmarks=false,
    enlargefirstpage,
]{scrlttr2}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc} 
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage{marvosym}   
\usepackage{blindtext}

\newcommand{\myFirstname}{John}
\newcommand{\myFamilyname}{Doe}
\newcommand{\myStreet}{3500 West Olive Avenue}
\newcommand{\myTown}{Burbank, CA 91505-5512}


\setkomavar{date}{\today} 
\setkomavar{fromname}{\myFirstname\ \myFamilyname}
\setkomavar{signature}{\myFirstname\ \myFamilyname}
\setkomavar{fromaddress}{\myStreet\\\myTown}
\setkomavar{backaddress}{\myFirstname\ \myFamilyname, \myStreet , \myTown}
\setkomavar{place}{Burbank}
\setkomavar{fromphone}[\Mobilefone\,]{(01\,23)\,45\,67\,89\,10}
\setkomavar{fromemail}[\Letter\,]{[email protected]}

\renewcommand*\familydefault{\sfdefault}

\let\raggedsignature\raggedright

\usepackage{xcolor}
\usepackage{scrlayer-scrpage}
\clearmainofpairofpagestyles
\chead{\normalfont\Huge\color{red}Headline}
\RedeclarePageStyleAlias{empty}{scrheadings}


\setkomavar{subject}{Dies hier ist ein Blindtext zum Testen von Textausgaben.
}
\begin{document}
%
\begin{letter}{Richard M Winsor\\
2192 Lawman Avenue\\ 
Arlington\\
22204 Virginia
}
%
\opening{Dear Mr Winsor,}
%
\blindtext[1]
\noindent \blindtext[4]


\closing{Yours sincerely,}
\end{letter}

\end{document}

在此处输入图片描述

如果你想要更多的影响,例如,对页面头部的位置,你应该看看scrlayer第二部分中的章节KOMA-Script 手册

德语 KOMA-Script 书附录中展示了一种完全不同的解决方案,用于firsthead扩展边注。您可以采用这种方法来设置标题,并且只在收件人旁边设置一些文本。

或者您可以使用变量firsthead作为页面标题,并使用变量location来自行放置地址:

\documentclass[a4paper,
    pagenumber=false,
    parskip=full,
    fontsize=11pt,
    firstfoot=false,
    foldmarks=false,
    enlargefirstpage,
]{scrlttr2}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc} 
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage{marvosym}   
\usepackage{blindtext}

\newcommand{\myFirstname}{John}
\newcommand{\myFamilyname}{Doe}
\newcommand{\myStreet}{3500 West Olive Avenue}
\newcommand{\myTown}{Burbank, CA 91505-5512}


\setkomavar{date}{\today} 
\setkomavar{fromname}{\myFirstname\ \myFamilyname}
\setkomavar{signature}{\myFirstname\ \myFamilyname}
\setkomavar{fromaddress}{\myStreet\\\myTown}
\setkomavar{backaddress}{\myFirstname\ \myFamilyname, \myStreet , \myTown}
\setkomavar{place}{Burbank}
\setkomavar{fromphone}[\Mobilefone\,]{(01\,23)\,45\,67\,89\,10}
\setkomavar{fromemail}[\Letter\,]{[email protected]}

\renewcommand*\familydefault{\sfdefault}

\let\raggedsignature\raggedright

\usepackage{xcolor}
\setkomavar{firsthead}{%
  \centering\Huge\color{red}Headline
}

\setkomavar{location}{%
  \raggedleft
  \usekomavar{fromname}\\
  \usekomavar{fromaddress}\\
  \usekomavar*{fromphone}\usekomavar{fromphone}\\
  \usekomavar*{fromemail}\usekomavar{fromemail}
}

\setkomavar{subject}{Dies hier ist ein Blindtext zum Testen von Textausgaben.
}
\begin{document}
%
\begin{letter}{Richard M Winsor\\
2192 Lawman Avenue\\ 
Arlington\\
22204 Virginia
}
%
\opening{Dear Mr Winsor,}
%
\blindtext[1]
\noindent \blindtext[4]


\closing{Yours sincerely,}
\end{letter}

\end{document}

在此处输入图片描述

如果您不想让您的地址出现在地址旁边,只需使用这个不带的第二个示例\setkomavar{location}{…}

答案2

如果你添加

\LoadLetterOption{visualize}
\showfields{address,location}

在您的序言中,您可以看到地址字段的顶部和位置字段的顶部是对齐的:

在此处输入图片描述

地址字段顶部到反向地址基线的距离为伪长度backaddrheight。要将位置字段中的基线fromname与反向地址的基线对齐,可以使用

\setkomavar{location}{
  \raggedleft
  \raisebox{0pt}[\useplength{backaddrheight}][\depth]{\usekomavar{fromname}}\\
  \usekomavar{fromaddress}\\
  \usekomavar*{fromphone}\usekomavar{fromphone}\\
  \usekomavar*{fromemail}\usekomavar{fromemail}
}

在此处输入图片描述

不带visualize和带标题:

在此处输入图片描述

 \documentclass[a4paper,
    pagenumber=false,
    parskip=full,
    fontsize=11pt,
    firstfoot=false,
    fromalign=right,
    fromphone=true,
    fromemail=true,
    fromrule=false,
    foldmarks=false,
    enlargefirstpage
]{scrlttr2}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc} 
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage{marvosym}
\usepackage{blindtext}
\usepackage{xcolor}

\newcommand{\myFirstname}{John}
\newcommand{\myFamilyname}{Doe}
\newcommand{\myStreet}{3500 West Olive Avenue}
\newcommand{\myTown}{Burbank, CA 91505-5512}

\setkomavar{date}{\today} 
\setkomavar{fromname}{\myFirstname\ \myFamilyname}
\setkomavar{signature}{\myFirstname\ \myFamilyname}
\setkomavar{fromaddress}{\myStreet\\\myTown}
\setkomavar{backaddress}{\myFirstname\ \myFamilyname, \myStreet , \myTown}
\setkomavar{place}{Burbank}
\setkomavar{fromphone}[\Mobilefone\,]{(01\,23)\,45\,67\,89\,10}
\setkomavar{fromemail}[\Letter\,]{[email protected]}

\renewcommand*\familydefault{\sfdefault}
\setkomavar{subject}{Dies hier ist ein Blindtext zum Testen von Textausgaben.}

\setkomavar{firsthead}{\centering\Huge \textcolor{red}{HEADLINE}}
\setkomavar{location}{
  \raggedleft
  \raisebox{0pt}[\useplength{backaddrheight}][\depth]{\usekomavar{fromname}}\\
  \usekomavar{fromaddress}\\
  \usekomavar*{fromphone}\usekomavar{fromphone}\\
  \usekomavar*{fromemail}\usekomavar{fromemail}
}

% to visualize the position and the size of address and location:
%\LoadLetterOption{visualize}
%\showfields{address,location}
\begin{document}
\begin{letter}{Richard M Winsor\\
2192 Lawman Avenue\\ 
Arlington\\
22204 Virginia
}
\opening{Dear Mr Winsor,}
\blindtext[1]
\noindent \blindtext[4]
\closing{\raggedright Yours sincerely,}
\end{letter}
\end{document}

相关内容