想要用文章类写一封信。使用expl3
命令显示姓名、职位和地址,而不需要缩进或中间有额外的空格。
当前的实现在姓名、角色和地址之间引入了额外的空格,这是我不想要的。
结果如下
Heime Borgia
Developer
Plateau de Moulon
3 rue Joliot-Curie
Gon Cholden
Developer
Plateau de Moulon
3 rue Joliot-Curie
Feodor Svertlov
Developer
Plateau de Moulon
3 rue Joliot-Curie
我还想处理与文档标题无关的信件标题。并能够在同一文档中撰写多封信件。
\documentclass[a4paper,12pt]{article}
\usepackage[english,italian]{babel}
\setlength {\parindent} {0pt} % Remove paragraph indent
\ExplSyntaxOn
\NewDocumentCommand {\WriteName} { O{left} m }
{
\str_case:nn { #1 }
{
{left} { \begin{flushleft} #2 \end{flushleft} }
{right} { \begin{flushright} #2 \end{flushright} }
}
}
\NewDocumentCommand {\WriteRole} { O{left} m }
{
\str_case:nn { #1 }
{
{left} { \begin{flushleft} #2 \end{flushleft} }
{right} { \begin{flushright} #2 \end{flushright} }
}
}
\NewDocumentCommand {\WriteAddress} { O{left} m }
{
\str_case:nn { #1 }
{
{left} { \begin{flushleft} #2 \end{flushleft} }
{right} { \begin{flushright} #2 \end{flushright} }
}
}
\ExplSyntaxOff
\begin{document}
%% ENGLISH
\selectlanguage{english}
\hspace*{0.5\linewidth}
\WriteName [right] {Heime Borgia}
\WriteRole {Developer}
\WriteAddress {Plateau de Moulon \\ 3 rue Joliot-Curie}
\WriteName {Gon Cholden}
\WriteRole {Developer}
\WriteAddress {Plateau de Moulon \\ 3 rue Joliot-Curie}
\WriteName {Feodor Svertlov}
\WriteRole {Developer}
\WriteAddress {Plateau de Moulon \\ 3 rue Joliot-Curie}
January 2023 (date)
The Deterioration of Health and safety (title)
GNU is an operating system that is free software—that is, it respects
users' freedom. The GNU operating system consists of GNU packages
(programs specifically released by the GNU Project) as well as free
software released by third parties. The development of GNU made it
possible to use a computer without software that would trample your
freedom.
%% ITALIAN
\newpage
\selectlanguage{italian}
\hspace*{0.5\linewidth}
\WriteName [right] {Heime Borgia}
\WriteRole {Developer}
\WriteAddress {Plateau de Moulon \\ 3 rue Joliot-Curie}
\WriteName {Gon Cholden}
\WriteRole {Developer}
\WriteAddress {Plateau de Moulon \\ 3 rue Joliot-Curie}
\WriteName {Feodor Svertlov}
\WriteRole {Developer}
\WriteAddress {Plateau de Moulon \\ 3 rue Joliot-Curie}
January 2023 (date)
Il Deterioramento della Salute e della Sicurezza (Title)
GNU è un sistema operativo che è software libero, ovvero rispetta
libertà degli utenti. Il sistema operativo GNU è costituito da pacchetti
GNU (programmi rilasciati appositamente dal Progetto GNU) e gratuiti
software rilasciato da terze parti. Lo sviluppo di GNU ce l'ha fatta
possibile utilizzare un computer senza software che possa calpestare il
tuo libertà
\end{document}
答案1
您使用的方法是错误的:每个flushright
或flushleft
环境都会在其前后添加垂直空间(确保空间不会累积)。
\documentclass{article}
\usepackage{showframe} % to show the text block margins
\ExplSyntaxOn
\keys_define:nn { ragonese/address }
{
name .tl_set:N = \l_ragonese_address_name_tl,
role .tl_set:N = \l_ragonese_address_role_tl,
place .tl_set:N = \l_ragonese_address_place_tl,
address .tl_set:N = \l_ragonese_address_address_tl,
}
\NewDocumentCommand{\sender}{m}
{
\begin{flushright} % opens a group
\ragonese_address_print:n { #1 }
\end{flushright}
}
\NewDocumentCommand{\addressee}{m}
{
\begin{flushleft} % opens a group
\ragonese_address_print:n { #1 }
\end{flushleft}
}
\cs_new_protected:Nn \ragonese_address_print:n
{
\keys_set:nn { ragonese/address } { #1 }
\begin{tabular}{@{}l@{}}
\tl_use:N \l_ragonese_address_name_tl \\
\tl_if_blank:VF \l_ragonese_address_role_tl { \tl_use:N \l_ragonese_address_role_tl \\ }
\tl_use:N \l_ragonese_address_place_tl \\
\tl_use:N \l_ragonese_address_address_tl
\end{tabular}
}
\ExplSyntaxOff
\begin{document}
\sender{
name=Heime Borgia,
role=Developer,
place=Plateau de Moulon,
address=3 rue Joliot-Curie
}
\addressee{
name=Gon Cholden,
role=Developer,
place=Plateau de Moulon,
address=3 rue Joliot-Curie
}
\addressee{
name=Feodor Svertlov,
place=Plateau de Moulon,
address=3 rue Joliot-Curie
}
\end{document}
答案2
我希望这接近您想要的。主要变化是增加了\parbox
和\parskip
。空行用于开始新段落(或\par
)。
\documentclass[a4paper,12pt]{article}
\usepackage[english,italian]{babel}
\setlength{\parindent}{0pt}% Remove paragraph indent
\setlength{\parskip}{\baselineskip}
\begin{document}
%% ENGLISH
\selectlanguage{english}
\hspace*{0.5\linewidth}\parbox{0.5\textwidth}{%
Heime Borgia (sender)\\
Developer (role)\\
3 rue Joliot-Curie (address)}
Gon Cholden (receiver)\\
Developer (role)\\
3 rue Joliot-Curie (address)
Gon Cholden (receiver)\\
Developer (role)\\
3 rue Joliot-Curie (address)
\hspace*{0.5\linewidth}January 2023 (date)
{\centering\large The Deterioration of Health and safety (title)\par}% \textbf might look good here
GNU is an operating system that is free software—that is, it respects
users' freedom. The GNU operating system consists of GNU packages
(programs specifically released by the GNU Project) as well as free
software released by third parties. The development of GNU made it
possible to use a computer without software that would trample your
freedom.
%% ITALIAN
\newpage
\selectlanguage{italian}
\hspace*{0.5\linewidth}\parbox{0.5\textwidth}{%
Heime Borgia (sender)\\
Developer (role)\\
3 rue Joliot-Curie (address)}
Gon Cholden (reciever)\\
Developer (role)\\
3 rue Joliot-Curie (address)
Gon Cholden (reciever)\\
Developer (role)\\
3 rue Joliot-Curie (address)
\hspace*{0.5\linewidth}January 2023 (date)
\vskip 2\parskip
\centerline{\large Il Deterioramento della Salute e della Sicurezza (Title)}
GNU è un sistema operativo che è software libero, ovvero rispetta
libertà degli utenti. Il sistema operativo GNU è costituito da pacchetti
GNU (programmi rilasciati appositamente dal Progetto GNU) e gratuiti
software rilasciato da terze parti. Lo sviluppo di GNU ce l'ha fatta
possibile utilizzare un computer senza software che possa calpestare il
tuo libertà
\end{document}