# How to break the email-address in behind the @-symbol (scrlttr2)

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}
\usepackage{hyperref}
\KOMAoptions{
paper=a4,
pagenumber=botcenter,
fromemail,
foldmarks,
enlargefirstpage,
foldmarks=true,
fromphone,fromemail,
}
\hypersetup{
}
\hspace*{\fill}\footnotesize
\begin{tabular}{l@{}}
\usekomavar{fromname}\\
\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{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}


Try this:

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

\setkomavar{fromname}{Firstname Lastname}
\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:

EDIT:

A second way if really a tabular is used:

\documentclass[version=last]{scrlttr2}
\usepackage[ngerman]{babel}
\usepackage{graphics}
\usepackage{hyperref}
\KOMAoptions{
paper=a4,
pagenumber=botcenter,
fromemail,
foldmarks,
enlargefirstpage,
foldmarks=true,
fromphone,fromemail,
}
\hypersetup{
}
% 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{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}

• 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
• \begin{tabular}{@{}l@{}} (no point in having the padding to the right. And “breaked” should be “broken”. – egreg Nov 2 '18 at 11:48

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}
\usepackage{hyperref}
\KOMAoptions{
%paper=a4,% default
pagenumber=botcenter,
%fromemail,% used twice
%foldmarks,% default
enlargefirstpage,
%foldmarks=true,% default (and used twice)
fromphone,fromemail
}
\hypersetup{
}

\hspace*{\fill}\footnotesize
\begin{tabular}{l@{}}
\usekomavar{fromname}\\
\if@phone\\
\usekomavar*{fromphone}\usekomavar{fromphone}\fi
\if@fax\\
\usekomavar*{fromfax}\usekomavar{fromfax}\fi
\if@email\\
\if@www\\
\usekomavar*{fromurl}\usekomavar{fromurl}\fi
\end{tabular}%
}\makeatother
\setkomavar{fromname}{Firstname Lastname}
\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}

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