scrlttr2 定位 - 签名业务标题和姓名在同一行

scrlttr2 定位 - 签名业务标题和姓名在同一行

我正在使用scrlttr2KOMA-Script 包的类,并希望将业务标题和名称放在同一行,标题左对齐,名称右对齐,如图所示。

图片

\hspace我对长度命令集做了一些技巧(请参阅下面的 MWE):

\usepackage{calc}
\newcommand{\signedby}{John Dow}
\newcommand{\signedtitle}{CEO}
\newlength{\signedbylength}
\setlength{\signedbylength}{\textwidth-\widthof{\signedtitle}-\widthof{\signedby}}
\setkomavar{signature}{\signedtitle\hspace{\signedbylength}\signedby}

它可以起作用,但我担心这是一种解决方法,可以用更优雅的方式来完成吗?

梅威瑟:

\documentclass[paper=a4, backaddress=off, 14pt, refline=nodate]{scrlttr2}
\usepackage{mweletter}
\usepackage[english]{babel}
\usepackage{calc}
\usepackage{lipsum}

% some trick
\newcommand{\signedby}{John Dow}
\newcommand{\signedtitle}{CEO}
\newlength{\signedbylength}
\setlength{\signedbylength}{%
    \textwidth-\widthof{\signedtitle}-\widthof{\signedby}}
\setkomavar{fromname}{Temporary Solutions, Inc.}
\setkomavar{fromaddress}{%
\textsf{\href{mailto:[email protected]}{[email protected]}}}
\setkomavar{signature}{\signedtitle\hspace{\signedbylength}\signedby}

\begin{document}
\begin{letter}{Ministry of Health\\
05000 Somewhere, Baker St., 7\\
\textsf{\href{mailto:[email protected]}{[email protected]}}}

\opening{}
\begin{center}
\normalfont\bfseries REQUEST\\
for information \normalfont
\end{center}\bigskip

\lipsum[1]

\noindent\closing{Sincerely,}
\noindent\today
\end{letter}
\end{document}

mweletter源:

% mweletter.sty
\ProvidesFile{mweletter.lco}
                        [2017/08/25 letter class option]
\RequirePackage[utf8]{inputenc}
\RequirePackage[%
    a4paper,pdftex,left=30mm,right=15mm,top=20mm,bottom=20mm%
    ]{geometry}
\RequirePackage{graphicx}
\RequirePackage{amsmath}
\RequirePackage{cmap}
\RequirePackage{color}
\RequirePackage{indentfirst}
\RequirePackage[T2A]{fontenc}
\RequirePackage[protrusion=true]{microtype} % Висячая пунктуация
\RequirePackage{enumitem}
\RequirePackage[unicode, colorlinks, pdfstartview=FitH, pdflang=UK]{hyperref}
\@setplength{toaddrvpos}{10mm}
\@setplength{toaddrhpos}{120mm}
\@setplength{toaddrheight}{0mm}
\@setplength{backaddrheight}{0pt}
\@setplength{firstheadvpos}{30mm}
\@setplength{firstheadhpos}{120mm}
\@setplength{refvpos}{70mm} % 110
\@setplength{subjectaftervskip}{\baselineskip}
\@setplength{backaddrheight}{10mm}
\setkomavar{date}{\flushleft\vspace{-\baselineskip}\today\par}
\@setplength{sigbeforevskip}{8mm}
\newcommand{\rom}[1]{%
  \textup{\uppercase\expandafter{\romannumeral#1}}%
}
\renewcommand\raggedsignature{}
\setlength{\parindent}{4ex}
\setlength{\itemsep}{0mm}

任何帮助都将受到赞赏。

答案1

您可以修补\closing以添加新变量的使用:

\RequirePackage{filecontents}
\begin{filecontents*}{mweletter.sty}
\ProvidesFile{mweletter.lco}
                        [2017/08/25 letter class option]
\RequirePackage[utf8]{inputenc}
\RequirePackage[%
    a4paper,pdftex,left=30mm,right=15mm,top=20mm,bottom=20mm%
    ]{geometry}
\RequirePackage{graphicx}
\RequirePackage{amsmath}
\RequirePackage{cmap}
\RequirePackage{color}
\RequirePackage{indentfirst}
\RequirePackage[T2A]{fontenc}
\RequirePackage[protrusion=true]{microtype} % Висячая пунктуация
\RequirePackage{enumitem}
\RequirePackage[unicode, colorlinks, pdfstartview=FitH, pdflang=UK]{hyperref}
\@setplength{toaddrvpos}{10mm}
\@setplength{toaddrhpos}{120mm}
\@setplength{toaddrheight}{0mm}
\@setplength{backaddrheight}{0pt}
\@setplength{firstheadvpos}{30mm}
\@setplength{firstheadhpos}{120mm}
\@setplength{refvpos}{70mm} % 110
\@setplength{subjectaftervskip}{\baselineskip}
\@setplength{backaddrheight}{10mm}
\setkomavar{date}{\flushleft\vspace{-\baselineskip}\today\par}
\@setplength{sigbeforevskip}{8mm}
\newcommand{\rom}[1]{%
  \textup{\uppercase\expandafter{\romannumeral#1}}%
}
\renewcommand\raggedsignature{}
\setlength{\parindent}{4ex}
\setlength{\itemsep}{0mm}
\newkomavar{position}
\RequirePackage{xpatch}
\xpatchcmd\closing{\usekomavar{signature}}{\usekomavar{position}}{}{\failure}
\xpatchcmd\closing{\usekomavar{signature}}{\usekomavar{position}}{}{\failure}
\xpatchcmd\closing{\parbox}{\parbox[b]}{}{\failure}
\xpatchcmd\closing{\par}{\xpar}{}{\failure}
\xpatchcmd\closing{\par}{\hfill\strut\usekomavar{signature}\par}{}{\failure}
\xpatchcmd\closing{\xpar}{\par}{}{\failure}
\end{filecontents*}

\documentclass[paper=a4, backaddress=off, 14pt, refline=nodate]{scrlttr2}
\usepackage{mweletter}
\usepackage[english]{babel}
\usepackage{calc}
\usepackage{lipsum}

% some trick
\setkomavar{fromname}{Temporary Solutions, Inc.}
\setkomavar{fromaddress}{%
\textsf{\href{mailto:[email protected]}{[email protected]}}}
\setkomavar{signature}{John Dow}
\setkomavar{position}{CEO}

\begin{document}
\begin{letter}{Ministry of Health\\
05000 Somewhere, Baker St., 7\\
\textsf{\href{mailto:[email protected]}{[email protected]}}}

\opening{}
\begin{center}
\normalfont\bfseries REQUEST\\
for information \normalfont
\end{center}\bigskip

\lipsum[1]

\noindent\closing{Sincerely,}
\noindent\today
\end{letter}
\end{document}

在此处输入图片描述

但如果签名有多行,这种方法就行不通了。在这种情况下,你必须封装\usekomavar{signature}tabular,varwidth或者\parbox

相关内容