我想创建一个非常基本的信件模板,其中包含“标题”部分(地址信息、位置和日期)和文本部分。标题部分应始终具有相同的高度和相同的格式。我想将这些格式信息放在宏中,该宏应使用一些包含发件人和收件人数据的辅助宏。
如果您将下面的 LaTeX 示例编译为 PDF,并使用 PDF 阅读器打开并将两页并排放置,您会注意到相应行的位置完全匹配。但是,如果您在标题宏后启用虚拟文本,则标题行不再匹配。最大的差异(约 0.5 行高)是接收器字段中的“额外行 1”。
我如何强制 LaTeX 对标题部分使用相同的行高,而不受文本部分的影响?
到目前为止我已经尝试过:
- 使用 flushright 和 makebox 将线条推到右侧。
- 使用 hspace 将线条推到右侧。
- 将所有内容放在具有固定高度的迷你页面上。
- 将组(发送方数据和接收方数据)放在一个小页面上,并将小页面放在表格中。
- 将每一行单独放在表格行中。
这些对我都不起作用。启用文本后,所有情况下我的行位置都不均匀。你们有人知道我还能尝试什么吗?:)
如有任何提示我将不胜感激。
\documentclass[11pt,a4paper]{letter}
% include standard packages
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\absndA}{Sender Name}
\newcommand{\absndB}{Sender Address 01}
\newcommand{\absndC}{POSTCODE City}
\newcommand{\absndD}{extra line1}
\newcommand{\absndE}{extra line2}
\newcommand{\empfgA}{Receiver Company}
\newcommand{\empfgB}{Receiver Name}
\newcommand{\empfgC}{Receiver street 12}
\newcommand{\empfgD}{POSTCODE City}
\newcommand{\empfgE}{extra line1}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% set the the 2 offsets to 0
\addtolength\voffset {-1.0 in}
\addtolength\hoffset {-1.0 in}
\setlength\oddsidemargin { 2.5 cm}
\setlength\evensidemargin { 2.5 cm}
\setlength\topmargin { 0.5 cm}
\setlength\headheight { 0.5 cm}
\setlength\headsep { 0.5 cm}
\setlength\textheight {27.2 cm}
\setlength\textwidth {16.0 cm}
\addtolength\parskip { 3.0 mm}
\setlength\parindent { 0.0 mm}
\newlength{\tabcolsepTmp}
% set default font to sans
\renewcommand{\familydefault}{\sfdefault}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\headerTypeB}{%
\setlength{\tabcolsepTmp}{\tabcolsep}%
\setlength{\tabcolsep}{0pt}%
\begin{tabular}{p{0.7\textwidth}p{0.3\textwidth}}%
%& \begin{minipage}[t][7\normalbaselineskip][t]{\textwidth}%
& \absndA\\%
& \absndB\\%
& \absndC\\%
& \absndD\\%
& \absndE\\%
%\end{minipage}\\%
\multicolumn{2}{l}{%
\begin{minipage}[t][7\normalbaselineskip][t]{\textwidth}%
\empfgA\\%
\empfgB\\%
\empfgC\\%
\empfgD\\%
\empfgE%
\end{minipage}%
} \\%
\multicolumn{2}{r}{Location, \today}\\%
\end{tabular}%
\setlength{\tabcolsep}{\tabcolsepTmp}%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\headerTypeB
%\large{Greeting}
%
%text
%
%text2
\newpage
\headerTypeB
%some text
%
%more text
\end{document}
答案1
您误用了\large
宏。它不像 那样接受参数\large{Greeting}
,而是一个声明,它将当前组末尾的所有后续文本的新字体大小设置为新字体大小。
\par
要限制其范围,请将范围括在括号中。此外,组中需要段落结束才能使\large
生效。因此,您将看到先前的用法已被修改为{\large Greeting\par}
。
实际上,最初的错误调用将文本的大小更改为\large
适合文档其余部分。请参阅 LaTeX 用户指南和参考手册第 115-116 页。
\documentclass[11pt,a4paper]{letter}
% include standard packages
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\absndA}{Sender Name}
\newcommand{\absndB}{Sender Address 01}
\newcommand{\absndC}{POSTCODE City}
\newcommand{\absndD}{extra line1}
\newcommand{\absndE}{extra line2}
\newcommand{\empfgA}{Receiver Company}
\newcommand{\empfgB}{Receiver Name}
\newcommand{\empfgC}{Receiver street 12}
\newcommand{\empfgD}{POSTCODE City}
\newcommand{\empfgE}{extra line1}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% set the the 2 offsets to 0
\addtolength\voffset {-1.0 in}
\addtolength\hoffset {-1.0 in}
\setlength\oddsidemargin { 2.5 cm}
\setlength\evensidemargin { 2.5 cm}
\setlength\topmargin { 0.5 cm}
\setlength\headheight { 0.5 cm}
\setlength\headsep { 0.5 cm}
\setlength\textheight {27.2 cm}
\setlength\textwidth {16.0 cm}
\addtolength\parskip { 3.0 mm}
\setlength\parindent { 0.0 mm}
\newlength{\tabcolsepTmp}
% set default font to sans
\renewcommand{\familydefault}{\sfdefault}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\headerTypeB}{%
\setlength{\tabcolsepTmp}{\tabcolsep}%
\setlength{\tabcolsep}{0pt}%
\begin{tabular}{p{0.7\textwidth}p{0.3\textwidth}}%
%& \begin{minipage}[t][7\normalbaselineskip][t]{\textwidth}%
& \absndA\\%
& \absndB\\%
& \absndC\\%
& \absndD\\%
& \absndE\\%
%\end{minipage}\\%
\multicolumn{2}{l}{%
\begin{minipage}[t][7\normalbaselineskip][t]{\textwidth}%
\empfgA\\%
\empfgB\\%
\empfgC\\%
\empfgD\\%
\empfgE%
\end{minipage}%
} \\%
\multicolumn{2}{r}{Location, \today}\\%
\end{tabular}%
\setlength{\tabcolsep}{\tabcolsepTmp}%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\headerTypeB
{\large Greeting\par}
text
text2
\newpage
\headerTypeB
some text
more text
\end{document}