[Tex/LaTex] Closing phrase (from \closing) & signature (variable) in the same line (scrlttr2)

positioningscrlttr2

The \closing command in scrlttr2.cls is

\newcommand*{\closing}[1]{{%
    \setparsizes{\z@}{\z@}{\z@ plus 1fil}\par@updaterelative\nobreak\par%
    \nobreak\vskip\baselineskip%
    \stopbreaks\noindent%
    \setlength{\@tempdima}{0pt}%
    \expandafter\@tempdimaismaxwidthof\scr@signature@var\\\@nil
    \expandafter\@tempdimaismaxwidthof\strut\ignorespaces#1\\\@nil
    \setlength{\@tempdimb}{\hsize}%
    \addtolength{\@tempdimb}{-\useplength{sigindent}}%
    \ifdim\@tempdima>\@tempdimb\setlength{\@tempdima}{\@tempdimb}\fi%
    \hspace{\useplength{sigindent}}%
    \parbox{\@tempdima}{\raggedsignature\strut\ignorespaces%
      #1\strut\\[\useplength{sigbeforevskip}]
      \strut\usekomavar{signature}\strut}}\par
  \nobreak\vskip\baselineskip%
}

How can one lift the signature variable right next after the closing-phrase (in the same line), and add the \encl{}, \cc{} commands (from scrlttr2) right after?

The code above is somewhat complicated (for there are instructions unknown to me). Likewise, trying to follow an example for the lettr.cls, so as to renew the \closing command in How to type specifically on this part of the page?, isn't easy.

Best Answer

Let's start of with an minimal example - something that really helps the community, regardless of what you may think, really. The following is taken from the KOMA-script documentation (section 4.20. Closing, p 190):

\documentclass[foldmarks=true,foldmarks=blmtP,
  fromphone,fromemail,fromlogo,
  subject=titled,
  version=last]{scrlttr2}% http://ctan.org/pkg/koma-script
\usepackage[english]{babel}% http://ctan.org/pkg/babel
\usepackage{graphicx}% http://ctan.org/pkg/graphicx
\begin{document}
\setkomavar{fromname}{John Public}
\setkomavar{signature}{John Public\\
  (former chairman)}
\renewcommand*{\raggedsignature}{\raggedright}
\setkomavar{fromaddress}{Valley 2\\
  54321 Public-Village}
\setkomavar{fromphone}{0\,12\,34~56\,78}
\setkomavar{fromemail}{Peter@Public.invalid}
\setkomavar{fromlogo}{\includegraphics[height=5\baselineskip]{tiger}}
\setkomavar{location}{\raggedright
  Club nember no.~4711\\
  since 11.09.2001\\
  chairman 2003--2005}
\setkomavar{date}{29th February 2011}
\setkomavar{place}{Public-Village}
\setkomavar{subject}{Missing general meeting}
\begin{letter}{%
  Joana Public\\
  Hillside 1\\
  12345 Public-City%
}
\opening{Dear chairman,}
  the last general meeting was about one year ago.
  I want to remind you, that the constitution of our
  club advises you to make a general meeting every
  six month. Because of this I expect the executive
  board to detain such a meeting immediately.
\closing{Expecting an invitation}
\ps PS: I hope you accept this as an friendly
  demand note.
\setkomavar*{enclseparator}{Enclosure}
\encl{Compendium of the constitution with the
  general meeting paragraphs.}
\cc{executive board\\all members}
\end{letter}
\end{document}

This is what the output looks like:

enter image description here

If we wish to modify the structure of the \closing, we should modify what is contained within the \parbox command. Let's do this using etoolbox in the form of a \patchcmd:

\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\makeatletter
\patchcmd{\closing}% <cmd>
  {\parbox}% <search>
  {\parbox{\linewidth}{\raggedsignature\strut\ignorespaces\let\\\relax%
      #1 \usekomavar{signature}}%
   \@gobbletwo}%< <replace>
  {}{}% <success><failure>
\makeatother

The above code replaces \parbox for \parbox{..}{...}\@gobbletwo. The replacement \parbox{..}{...} uses elements of the older \parbox, but doesn't insert a sigbeforevskip length that used to produce the vertical gap. Instead, \usekomavar{signature} is set with a space between the actual \closing{#1}. Also, \\ is \let to \relax (but might not be necessary) to avoid forced paragraph breaks. The latter \@gobbletwo eats the old \parbox's two arguments.

Here's an example document showing the output results (note that I've also moved a \ps below \encl and \cc, as requested):

enter image description here

\documentclass[foldmarks=true,foldmarks=blmtP,
  fromphone,fromemail,fromlogo,
  subject=titled,
  version=last]{scrlttr2}% http://ctan.org/pkg/koma-script
\usepackage[english]{babel}% http://ctan.org/pkg/babel
\usepackage{graphicx}% http://ctan.org/pkg/graphicx

\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\makeatletter
\patchcmd{\closing}% <cmd>
  {\parbox}% <search>
  {\parbox{\linewidth}{\raggedsignature\strut\ignorespaces\let\\\relax%
      #1 \usekomavar{signature}}%
   \@gobbletwo}%< <replace>
  {}{}% <success><failure>
\makeatother

\begin{document}
\setkomavar{fromname}{John Public}
\setkomavar{signature}{John Public\\
  (former chairman)}
\renewcommand*{\raggedsignature}{\raggedright}
\setkomavar{fromaddress}{Valley 2\\
  54321 Public-Village}
\setkomavar{fromphone}{0\,12\,34~56\,78}
\setkomavar{fromemail}{Peter@Public.invalid}
\setkomavar{fromlogo}{\includegraphics[height=5\baselineskip]{tiger}}
\setkomavar{location}{\raggedright
  Club nember no.~4711\\
  since 11.09.2001\\
  chairman 2003--2005}
\setkomavar{date}{29th February 2011}
\setkomavar{place}{Public-Village}
\setkomavar{subject}{Missing general meeting}
\begin{letter}{%
  Joana Public\\
  Hillside 1\\
  12345 Public-City%
}
\opening{Dear chairman,}
  the last general meeting was about one year ago.
  I want to remind you, that the constitution of our
  club advises you to make a general meeting every
  six month. Because of this I expect the executive
  board to detain such a meeting immediately.
\closing{Expecting an invitation}
\setkomavar*{enclseparator}{Enclosure}
\encl{Compendium of the constitution with the
  general meeting paragraphs.}
\cc{executive board\\all members}
\ps PS: I hope you accept this as an friendly
  demand note.
\end{letter}
\end{document}

Of course, other adjustments can also be made.