# Simplify how I write my address in documents

Often when writing letters and articles, I need to print my address at the beginning or end of the document. I do this in the following ugly way:

\documentclass{article}
\begin{document}
\noindent My name\\
\noindent My university\\
\noindent My department\\
\noindent My e-mail\\
\end{document}


Clearly there must be a better way to do this than having to repeat \noindent ... \\ for every line. I'm thinking I could define a new command \myaddress that will simply print all of those lines:

\documentclass{article}
% define address command here
\begin{document}
\end{document}


Or at the very least define a new environment that takes care of the indentation and line break:

\documentclass{article}
% define address environment here
\begin{document}
My name
My university
My department
My e-mail
\end{document}


But I have no idea how to do either.

• What does make you think that \noindent is necessary after the first line? It isn't. Of course, the last \\ is not necessary either (better, it's wrong). – egreg Feb 18 '14 at 20:58
• Unless I've overlooked something, you can also use \obeylines in the start of your macro definition rather than putting a \\ after each line. – ChrisS Feb 19 '14 at 0:38
• @ChrisS: I can't get that to work. Can you? – Sverre Feb 19 '14 at 9:14
• @Sverre: It turns out it was overlooking something: \obeylines doesn't work in a macro definition. – ChrisS Feb 19 '14 at 9:19

You can easily do something as simple as

\newcommand\printmyaddress{%
\begingroup
\parindent 0pt
\myname       \par
\myuniversity \par
\mydepartment \par
\myemail      \par
\endgroup}


and then set those macros accordingly. Put it in a .sty file and you'd be good enough to go (assuming the formatting is done as you like it).

Maybe it's more fun to be more elaborate, however. One idea would be a key-value approach that allows you to have default values that can be overriden piece by piece if you like. There are many options this way; here's one that uses l3keys:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{xparse}

% from here to \ExplSyntaxOff, you could put this in a separate .sty
% to keep things tidy...
\ExplSyntaxOn
% get things set up with defaults:
\keys_define:nn { svdetails }
{
name       .tl_gset:N = \g_svdetails_name_tl,
university .tl_gset:N = \g_svdetails_university_tl,
department .tl_gset:N = \g_svdetails_department_tl,
email      .tl_gset:N = \g_svdetails_email_tl,
% set the default values (change to real values)
name       .initial:n = NAMEDEFAULT,
university .initial:n = UNIDEFAULT,
department .initial:n = DEPTDEFAULT,
email      .initial:n = EMAILDEFAULT
}

\NewDocumentCommand{\biodetails}{ m }
{
\keys_set:nn { svdetails } { #1 }
}

% How do we want things to look when printed?
% (Nothing fancy here: just 'zero' the \parindent and print
% everything in a new paragraph. But it would be easy to change.)
\NewDocumentCommand{\printdetails}{ }
{\begingroup
\parindent 0pt
\g_svdetails_name_tl       \par
\g_svdetails_university_tl \par
\g_svdetails_department_tl \par
\g_svdetails_email_tl      \par
\endgroup}

\ExplSyntaxOff

% override document defaults; not strictly necessary since we
% already set defaults above...
\biodetails{
name=Sverre Sverre,
university=University of Somewhere,
department=Department of XYZ,
email=sverre@sverre.com,
}

\begin{document}

\printdetails

\end{document}


Perhaps

\documentclass{article}

\begin{flushleft}
\setlength{\tabcolsep}{0pt}%  For flushing at least a little bit
\begin{tabular}{l}
My Name \\
My university \\
My department \\
My e-mail \\
\end{tabular}
\end{flushleft}
}% End of \newcommand*

\begin{document}
\end{document}


is a possible 'quick' solution. The linespacings can be set by redefinition of \arraystretch for example, if needed.

• Using a tabular environment will, however, not flush the text to the margin. But I used your suggestion as a template, and (as a quick fix) put my entire address, with \noindent ...\\, inside \newcommand{\myaddress}{}. – Sverre Feb 17 '14 at 18:29
• @Sverre: Ok, I see, that I missed flushing to the margin... perhaps, one could do with setting \tabcolsep to zero. – user31729 Feb 17 '14 at 18:30
• @Christian Instead of changing a global variable to a bad value, disable the seps locally by changing {l} to {@{}l@{}} – yo' Feb 17 '14 at 18:39
• @tohecz: That's a nice idea, but if I use another table after my \myaddress command, the tabcolsep value is restored to original value -- it is changed within a \newcommand. – user31729 Feb 17 '14 at 18:42
• @Christian Your setting to \tabcolsep is indeed local because it's issued inside a flushleft environment (not because it's changed within \newcommand). But the @{}l@{} method is much easier. – egreg Feb 18 '14 at 21:09

A left-aligned \Longstack will work here. Depending on how you need the vertical placement of the item, a \Longunderstack may be preferable to \Longstack, though in many situations, it won't matter which is chosen.

\documentclass{article}
\usepackage[usestackEOL]{stackengine}
\begin{document}
\noindent\Longstack[l]{
My name\\
My university\\
My department\\
My e-mail}
\textbf{versus}
\Longunderstack[l]{
My name\\
My university\\
My department\\
My e-mail}
\end{document}


Based on the suggestions here and on Ulrike's comment to Cancel the use of \baselineskip when at the top of page, the following seems to be a good solution.

\documentclass{article}