如何设置字母以产生所有左对齐的输出?

如何设置字母以产生所有左对齐的输出?

.tex 文件的代码:

\documentclass[12pt]{sletter}

%% to use image
\usepackage{tabularx}


\usepackage{array}
\begin{document}
\begin{letter}{....}
\opening{Dear Sir or Madam: }

...

\closing{Regards,}
\end{letter}

\end{document}

代码为sletter

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{sletter}

%pass-in of letter.cls
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{letter}}
\ProcessOptions
\LoadClass[]{letter} %%changed for letter sized paper

%set margins/text
%\usepackage[letterpaper,twoside,inner=0pt,outer=0pt]{geometry}
\setlength{\textheight}{215mm}
\setlength{\textwidth}{160mm}
\setlength{\oddsidemargin}{0pt}
\setlength{\topmargin}{-20pt}
\setlength{\headsep}{35pt}
\setlength{\textwidth}{160mm}
\setlength{\evensidemargin}{0pt}
\setlength{\headheight}{12pt}

%hack


%from <http://stackoverflow.com/questions/877597/how-do-you-change-the-document-font-in-latex>, to access SYS fonts
\usepackage[xetex]{graphicx}
\usepackage{fontspec,xunicode}
\defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
\setmainfont[Scale=0.95]{Times New Roman}
%\setmonofont{Lucida Sans Typewriter}

答案1

由于sletter内部使用letter文档类,您可以重新定义\opening\closing命令,如中所述letter.cls。将以下几行添加到sletter.cls

\renewcommand*{\opening}[1]{\ifx\@empty\fromaddress
  \thispagestyle{firstpage}%
    {\@date\par}%
  \else  % home address
    \thispagestyle{empty}%
    {\begin{tabular}{@{}l@{}}\ignorespaces
      \fromaddress \\*[2\parskip]%
      \@date \end{tabular}\par}%
  \fi
  \vspace{2\parskip}%
  {\raggedright \toname \\ \toaddress \par}%
  \vspace{2\parskip}%
  #1\par\nobreak}
\renewcommand{\closing}[1]{\par\nobreak\vspace{\parskip}%
  \stopbreaks
  \noindent
  \parbox{\indentedwidth}{\raggedright
       \ignorespaces #1\\[6\medskipamount]%
       \ifx\@empty\fromsig
           \fromname
       \else \fromsig \fi\strut}%
   \par}

这是新文件sletter.cls

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{sletter}

%pass-in of letter.cls
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{letter}}
\ProcessOptions
\LoadClass[]{letter} %%changed for letter sized paper

%set margins/text
%\usepackage[letterpaper,twoside,inner=0pt,outer=0pt]{geometry}
\setlength{\textheight}{215mm}
\setlength{\textwidth}{160mm}
\setlength{\oddsidemargin}{0pt}
\setlength{\topmargin}{-20pt}
\setlength{\headsep}{35pt}
\setlength{\textwidth}{160mm}
\setlength{\evensidemargin}{0pt}
\setlength{\headheight}{12pt}

%hack


%from <http://stackoverflow.com/questions/877597/how-do-you-change-the-document-font-in-latex>, to access SYS fonts
\usepackage[xetex]{graphicx}
\usepackage{fontspec,xunicode}
\defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
\setmainfont[Scale=0.95]{Times New Roman}
%\setmonofont{Lucida Sans Typewriter}

\renewcommand*{\opening}[1]{\ifx\@empty\fromaddress
  \thispagestyle{firstpage}%
    {\@date\par}%
  \else  % home address
    \thispagestyle{empty}%
    {\begin{tabular}{@{}l@{}}\ignorespaces
      \fromaddress \\*[2\parskip]%
      \@date \end{tabular}\par}%
  \fi
  \vspace{2\parskip}%
  {\raggedright \toname \\ \toaddress \par}%
  \vspace{2\parskip}%
  #1\par\nobreak}
\renewcommand{\closing}[1]{\par\nobreak\vspace{\parskip}%
  \stopbreaks
  \noindent
  \parbox{\indentedwidth}{\raggedright
       \ignorespaces #1\\[6\medskipamount]%
       \ifx\@empty\fromsig
           \fromname
       \else \fromsig \fi\strut}%
   \par}

并使用此.tex文件:

\documentclass[12pt]{sletter}

\signature{Joe Bloggs}
\address{21 Bridge Street \\ Smallville \\ Dunwich DU3 4WE}

\begin{document}

\begin{letter}{Director \\ Doe \& Co \\ 35 Anthony Road
\\ Newport \\ Ipswich IP3 5RT}
\opening{Dear Sir or Madam:}

I am writing to you on behalf of the Wikipedia project (http://www.wikipedia.org/),
an endeavour to build a fully-fledged multilingual encyclopaedia in an entirely
open manner, to ask for permission to use your copyrighted material.

That said, allow me to reiterate that your material will be used to the noble end of
providing a free collection of knowledge for everyone; naturally enough, only if you
agree. If that is the case, could you kindly fill in the attached form and post it
back to me? We shall greatly appreciate it.

Thank you for your time and consideration.

I look forward to your reply.

\closing{Yours Faithfully,}

\ps{P.S. You can find the full text of GFDL license elsewhere}
\encl{Copyright permission form}

\end{letter}

\end{document}

你得到:

在此处输入图片描述

相关内容