4

I like to write a letter in latex, it all works fine so far, i just find that the sender information on the top rightis kind of "ugly". This results from the long email-address pushing the entire block to the left:

Firstname Lastname
Street 001
9999 Cityname
Telefon: +43 9999 999 2
Email: first.lastname@alumni.university.edu

Is it possible to force a line break after the @-symbol aligning the adress with the rest of the information so it looks like below?

Firstname Lastname
Street 001
9999 Cityname
Telefon: +43 9999 999 2
Email: first.lastname@
       alumni.university.edu

Here is the MWE:

\documentclass[version=last]{scrlttr2}
\usepackage[ngerman]{babel}
\usepackage{graphics}
\LoadLetterOption{DIN}
\usepackage{hyperref}
\KOMAoptions{
    paper=a4,
    pagenumber=botcenter,
    fromemail,
    backaddress,
    foldmarks,
    enlargefirstpage,
    foldmarks=true,
    fromrule=afteraddress,
    fromphone,fromemail,
}
\hypersetup{
    colorlinks=false,
    hidelinks=true,
}
\makeatletter\setkomavar{firsthead}{%
    \hspace*{\fill}\footnotesize
    \begin{tabular}{l@{}}
        \usekomavar{fromname}\\
        \usekomavar{fromaddress}
        \if@phone\\
        \usekomavar*{fromphone}\usekomavar{fromphone}\fi
        \if@fax\\
        \usekomavar*{fromfax}\usekomavar{fromfax}\fi
        \if@email\\
        \usekomavar*{fromemail}\usekomavar{fromemail}\fi
        \if@www\\
        \usekomavar*{fromurl}\usekomavar{fromurl}\fi
    \end{tabular}%
}\makeatother
\setkomavar{fromname}{Firstname Lastname}
\setkomavar{fromaddress}{Street 001\\9999 Cityname}
\setkomavar{fromphone}{+43\,9999\,999\,2}
\setkomavar{fromemail}{\href{mailto:first.lastname@alumni.university.edu}{first.lastname@alumni.university.edu}}
\begin{document}
\begin{letter}{%
Company\\
Mainstreet 001\\
1111 Cityname
}
\setkomavar{subject}{Subject}

\opening{Dear Mr. X,}
This is some text.
\closing{Cheers}
\end{letter}
\end{document}

Thank you in advance :)

0
4

Try this:

\documentclass[version=last]{scrlttr2}
\usepackage[ngerman]{babel}
\usepackage{graphics}
\LoadLetterOption{DIN}
%\LoadLetterOption{Absender}
\usepackage{hyperref}
\KOMAoptions{
    paper=a4,
    pagenumber=botcenter,
    fromemail,
    backaddress,
    foldmarks,
    enlargefirstpage,
    foldmarks=true,
    fromrule=afteraddress,
    fromphone,fromemail,
}
\hypersetup{
    colorlinks=false,
    hidelinks=true,
}
\newsavebox{\mybox}
\newcommand{\myBrokenEmail}[2]{\savebox\mybox{\hbox{E-Mail:\space}}#1\\\hspace*{\wd\mybox}#2}

\setkomavar{fromname}{Firstname Lastname}
\setkomavar{fromaddress}{Street 001\\9999 Cityname}
\setkomavar{fromphone}{+43\,9999\,999\,2}
\setkomavar{fromemail}{\href{mailto:first.lastname@alumni.university.edu}{\myBrokenEmail{first.lastname@}{alumni.university.edu}}}
\begin{document}
\begin{letter}{%
Company\\
Mainstreet 001\\
1111 Cityname
}
\setkomavar{subject}{Subject}

\opening{Dear Mr. X,}
This is some text.
\closing{Cheers}
\end{letter}
\end{document}

Output:

enter image description here

EDIT:

A second way if really a tabular is used:

\documentclass[version=last]{scrlttr2}
\usepackage[ngerman]{babel}
\usepackage{graphics}
\LoadLetterOption{DIN}
%\LoadLetterOption{Absender}
\usepackage{hyperref}
\KOMAoptions{
    paper=a4,
    pagenumber=botcenter,
    fromemail,
    backaddress,
    foldmarks,
    enlargefirstpage,
    foldmarks=true,
    fromrule=afteraddress,
    fromphone,fromemail,
}
\hypersetup{
    colorlinks=false,
    hidelinks=true,
}
% Here is the command to be used:
\newcommand{\myBrokenEmail}[2]{\begin{tabular}[t]{@{}l@{}}#1\\#2\end{tabular}\vspace{8pt}}

\setkomavar{fromname}{Firstname Lastname}
\setkomavar{fromaddress}{Street 001\\9999 Cityname}
\setkomavar{fromphone}{+43\,9999\,999\,2}
\setkomavar{fromemail}{\href{mailto:first.lastname@alumni.university.edu}{\myBrokenEmail{first.lastname@}{alumni.university.edu}}}
\begin{document}
\begin{letter}{%
Company\\
Mainstreet 001\\
1111 Cityname
}
\setkomavar{subject}{Subject}

\opening{Dear Mr. X,}
This is some text.
\closing{Cheers}
\end{letter}
\end{document}
6
  • is there any way that it works with the \LoadLetterOption{Absender} option or to get this information back at the right side? – celi Nov 2 '18 at 11:29
  • @celi. Did you tried the code with your option there? I had to remove it but I suppose that the code will still work for you. – koleygr Nov 2 '18 at 11:31
  • right, sorry for that, of course it's a file on my harddrive. sadly it doesn't work, I think it might be the problem that the email variable is used in a tabular environment? – celi Nov 2 '18 at 11:35
  • @celi... try the edited way then – koleygr Nov 2 '18 at 11:42
  • 2
    \begin{tabular}{@{}l@{}} (no point in having the padding to the right. And “breaked” should be “broken”. – egreg Nov 2 '18 at 11:48
3

With a slightly modification of the answer of @kolegyr you can still use \usekomavar{fromemail} to get the email without breaks:

\documentclass[version=last]{scrlttr2}
\usepackage[ngerman]{babel}
\usepackage{graphics}
%\LoadLetterOption{DIN}% default
\usepackage{hyperref}
\KOMAoptions{
    %paper=a4,% default
    pagenumber=botcenter,
    %fromemail,% used twice
    %backaddress,% default
    %foldmarks,% default
    enlargefirstpage,
    %foldmarks=true,% default (and used twice)
    %fromrule=afteraddress,
    fromphone,fromemail
}
\hypersetup{
    %colorlinks=false,% not needed if hidelinks is used
    hidelinks%=true,% no key-value-option
}

\makeatletter\setkomavar{firsthead}{%
    \hspace*{\fill}\footnotesize
    \begin{tabular}{l@{}}
        \usekomavar{fromname}\\
        \usekomavar{fromaddress}
        \if@phone\\
        \usekomavar*{fromphone}\usekomavar{fromphone}\fi
        \if@fax\\
        \usekomavar*{fromfax}\usekomavar{fromfax}\fi
        \if@email\\
        \usekomavar*{fromemail}\usekomavar[\let\EmailFormat\EmailInHeader]{fromemail}\fi
        \if@www\\
        \usekomavar*{fromurl}\usekomavar{fromurl}\fi
    \end{tabular}%
}\makeatother
\setkomavar{fromname}{Firstname Lastname}
\setkomavar{fromaddress}{Street 001\\9999 Cityname}
\setkomavar{fromphone}{+43\,9999\,999\,2}
\setkomavar{fromemail}{\href{mailto:first.lastname@alumni.university.edu}{\EmailFormat{first.lastname@}{alumni.university.edu}}}

\newcommand\EmailFormat[2]{#1#2}
\newcommand\EmailInHeader[2]{\begin{tabular}[t]{@{}l@{}}#1\\#2\end{tabular}}

\begin{document}
\begin{letter}{%
Company\\
Mainstreet 001\\
1111 Cityname
}
\setkomavar{subject}{Subject}

\opening{Dear Mr. X,}
This is some text.

The email in a single line:  \usekomavar{fromemail}
\closing{Cheers}
\end{letter}
\end{document}

Result:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.