2

As is known, the sender's name is automatically displayed inside the sender field with the value taken out of fromname's variable (like below).

Minimum example:

\documentclass{scrlttr2}

\usepackage[english, ngerman]{babel}

\begin{document}
\setkomavar{fromname}    {John Doe (sender)}
\setkomavar{fromaddress} {25th Doe's Avenue \\ 54321 Springfield}

\begin{letter}{%
        Maria Lae\\
        2th Coast Road\\
        12345 Milltown%
        }

    \opening{Dear Maria,}
             as you can see, I want to change the color of my name inside sender-field
             independent respectively for first name and family name.
        \bigskip\\
             Unfortuntely, I don't know how to solve this...
        \bigskip\\
             Do you have any idea?
    \closing{Sincerely yours}
\end{letter}

\end{document}

Now I want to change the shown font color of firstname and familyname independently into different colors for each word.

Actually my only idea is based on the creation of new KOMA-variables, respective for firstname and familyname:

\newkomavar[sender-firstname]{fromfirstname}
\setkomavar{fromfirstname}{John}

\newkomavar[sender-familyname]{fromfamilyname}
\setkomavar{fromfamilyname}{Doe}

Then, the next problem will be how to replace the existing fromname-registration (inside the sender-field) by the two newly created variables (fromfirstname and fromfamilyname).

Do you have any ideas or other solutions?

Thank you very much for your help!

Dave
  • 3,758

1 Answers1

2

If you only want to color the first name and the familiy name in the first header you can set the firsthead variable:

\documentclass[parskip=full-]{scrlttr2}
\usepackage{xcolor}
\usepackage[english, ngerman]{babel}
% new variables and fonts
\newkomavar[sender-firstname]{fromfirstname}
\newkomafont{fromfirstname}{}
\newkomavar[sender-familyname]{fromfamilyname}
\newkomafont{fromfamilyname}{}

\begin{document}
% set variables
\setkomavar{fromfirstname}{John}
\setkomavar{fromfamilyname}{Doe}
\setkomavar{fromname} {\usekomavar{fromfirstname} \usekomavar{fromfamilyname}}
\setkomavar{fromaddress} {25th Doe's Avenue \\ 54321 Springfield}
% set firsthead
\setkomavar{firsthead}{%
  \begin{parbox}[b]{\textwidth}\raggedright
    {\usekomafont{fromname}\strut\ignorespaces
      {\usekomafont{fromfirstname}\strut\ignorespaces\usekomavar{fromfirstname}}
      {\usekomafont{fromfamilyname}\strut\ignorespaces\usekomavar{fromfamilyname}}%
    }\\
    {\usekomafont{fromaddress}\strut\ignorespaces\usekomavar{fromaddress}}
  \end{parbox}%
}
% set fonts
\addtokomafont{fromfirstname}{\color{red}}
\addtokomafont{fromfamilyname}{\color{blue}}

\begin{letter}{%
  Maria Lae\\
  2th Coast Road\\
  12345 Milltown%
}

\opening{Dear Maria,}
as you can see, I want to change the color of my name inside sender-field
independent respectively for first name and family name.

Unfortuntely, I don't know how to solve this

Do you have any idea?
\closing{Sincerely yours}
\end{letter}
\end{document}

enter image description here

esdd
  • 85,675