[Tex/LaTex] Modification of a given letter

letters

In this letter from Wikibooks,

\documentclass{letter}
\usepackage{hyperref}
\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.

% The \ldots command produces dots in a way that will not upset
% the typesetting of the document.
\ldots 

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 at
\url{http://www.gnu.org/copyleft/fdl.html}.}
\encl{Copyright permission form}

\end{letter}

\end{document}`

I would like to make the following changes but I don't know how,

  1. The address and date I would like to be right-aligned , I tried \begin{flushright} \end{flushright} but it didn't work. Similarly for left-aligned for the signature and the \closing{Yours Faithfully,}.

  2. Change the margin distances.

  3. Add "University of Smallville" at the top centre (at the beginning) of the document.

Thanks

Best Answer

One possibility, using the geometry package to change the page layout (the margins in this case), and the xpatch package to patch the \opening command; setting \longindentation to 0pt you can get the closing part to be left aligned:

\documentclass{letter}
\usepackage{xpatch}
\usepackage[lmargin=3cm,rmargin=3.5cm,tmargin=4.5cm,bmargin=4cm]{geometry}
\usepackage{hyperref}

\newcommand\Heading{University of Smallville}

\setlength\longindentation{0pt}

\xpatchcmd{\opening}{l@}{r@}{}{}
\xpatchcmd{\opening}{\thispagestyle{empty}}{\thispagestyle{empty}{\centering\Heading\par\bigskip}}{}{}

\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.

% The \ldots command produces dots in a way that will not upset
% the typesetting of the document.
\ldots 

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 at
\url{http://www.gnu.org/copyleft/fdl.html}.}
\encl{Copyright permission form}

\end{letter}

\end{document}

A fragment of the resulting opening part:

enter image description here

And a fragment of the closing part:

enter image description here