7

I'm writing some fiction and typesetting it using texlive. I want to include a number of "emails" as part of the story but I'm a bit stuck how best to achieve this. My first attempt looks like this:

\rule{250pt}{1pt}
\newline
\texttt{From: HamiltonP, Beth\newline
To: Croft, Norrie\newline
Date: September 12th 2014\newline
Subject: Paris\newline
\newline
<some paragraph text>
\newline
<more paragraph text> }
\newline

\rule{250pt}{1pt}
\newline

obviously a monospace font is not particular appropriate for modern emails but it should be in a different font from the main text (maybe a sans serif for instance) and probably a different (smaller?) size.

Is there a straightforward way to do this? has someone done something similar before?

Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036
susie
  • 123

1 Answers1

20

This is my favorite kind of question!

Update

If you get some nice icons related to emails, then you can add them to the design (I got some icons from iconfinder for my example). Here's the tcolorbox version (see below) with an icon bar added:

enter image description here

The code:

\documentclass{memoir}
\usepackage{graphicx}
\usepackage[many]{tcolorbox}
\usetikzlibrary{positioning}
\usepackage{lipsum}% to generate text for the example

\definecolor{myboxgray}{RGB}{216,207,190}
\definecolor{mybackgray}{RGB}{243,232,223}
\definecolor{mybargray}{RGB}{192,185,169}

\newcommand\mybox[1]{
  \node[text width=2cm] {\strut#1};
}

\tikzset{
mybox/.style={
  draw=myboxgray!70!black,
  fill=myboxgray,
  text width=1.3cm,
  anchor=north west,
  align=center,
  inner ysep=2pt,
  font=\sffamily\small  
  },
myinfobox/.style={
  draw=myboxgray!70!black,
  text width=\textwidth-2cm-1pt,
  anchor=north west,
  inner ysep=2pt,
  fill=white,
  font=\sffamily\small  
  },
mybar/.style={
  draw=mybargray!70!black,
  fill=mybargray,
  text width=\textwidth-0.666em,
  minimum height=20pt,
  anchor=south west,
  outer sep=0pt
  }  
}

\newtcolorbox{mytemail}[5][]{
breakable,
pad after break=-63pt,
freelance,
colback=white,
left=0pt,
right=0pt,
outer arc=0pt,
arc=0pt,
colframe=gray,
colback=mybackgray,
boxrule=0.5pt,
top=80pt,
left=4pt,
right=4pt,
before=\par\vskip26pt,
fontupper=\sffamily\small,
overlay unbroken and first={
  \draw[draw=myboxgray!70!black,fill=mybargray]
    ([yshift=20pt]frame.north west)
      rectangle
    (frame.north east);
  \node[anchor=west]
    at ([yshift=9pt]frame.north west)
    (send) {\includegraphics[height=14pt]{send}};
  \node[anchor=west,font=\sffamily\small]
    at (send.east)
    (sendtext) {Send};   
  \node[anchor=west]
    at ([xshift=10pt]sendtext.east)
    (cancel) {\includegraphics[height=14pt]{cancel}};
  \node[anchor=west,font=\sffamily\small]
    at (cancel.east)
    (canceltext) {Cancel};   
  \node[anchor=west]
    at ([xshift=10pt]canceltext.east)
    (save) {\includegraphics[height=14pt]{save}};
  \node[anchor=west,font=\sffamily\small]
    at (save.east)
    (savetext) {Save Draft};   
  \node[anchor=west]
    at ([xshift=10pt]savetext.east)
    (add) {\includegraphics[height=14pt]{attachment}};
  \node[anchor=west,font=\sffamily\small]
    at (add.east)
    (addtext) {Add Attachment};   
  \node[mybox]
    at ([shift={(2pt,-2pt)}]frame.north west) 
    (from) {\strut From:};
  \node[mybox,below=2pt of from] 
    (to) {\strut To:};
  \node[mybox,below=2pt of to] 
    (date) {\strut Date:};
  \node[mybox,below=2pt of date] 
    (subj) {\strut Subject:};
  \node[draw,myinfobox,right=2pt of from] 
    (fromtext) {\strut #2};
  \node[draw,myinfobox,right=2pt of to] 
    (totext) {\strut #3};
  \node[draw,myinfobox,right=2pt of date] 
    (datetext) {\strut #4};
  \node[draw,myinfobox,right=2pt of subj] 
    (subjtext) {\strut #5};
  \draw[myboxgray!70!black,fill=white] 
    ([shift={(2pt,-74pt)}]interior.north west) 
      rectangle 
    ([shift={(-2pt,2pt)}]interior.south east); 
  },
overlay middle and last={
  \draw[myboxgray!70!black,fill=white] 
    ([shift={(2pt,-2pt)}]interior.north west) 
      rectangle 
    ([shift={(-2pt,2pt)}]interior.south east); 
  }  
  #1
}

\begin{document}

\lipsum[4]
\begin{mytemail}{HamiltonP, Beth}{Croft, Norrie}{September 12th 2014}{Paris}
\lipsum[4]
\end{mytemail}
\lipsum[4]

\end{document}

First version

Here's one possibility in which I simulated the style used for e-mails by some providers. I present two versions; one using tcolorbox and another one using mdframed. Both versions allow page breaks.

First, I used the powerful tcolorbox package:

enter image description here

All the job is done by a mytemail environment with four mandatory arguments:

\begin{mytemail}{<from>}{<to>}{<date>}{<subject>
<text>
\end{mytemail}

an optional argument allows to pass eventual additional options to the tcolorbox defined. The box in the example was produced using

\begin{mytemail}{HamiltonP, Beth}{Croft, Norrie}{September 12th 2014}{Paris}
\lipsum[4]
\end{mytemail}

The code:

\documentclass{memoir}
\usepackage[many]{tcolorbox}
\usetikzlibrary{positioning}
\usepackage{lipsum}% to generate text for the example

\definecolor{myboxgray}{RGB}{216,207,190}
\definecolor{mybackgray}{RGB}{243,232,223}

\newcommand\mybox[1]{
  \node[text width=2cm] {\strut#1};
}

\tikzset{
mybox/.style={
  draw=myboxgray!70!black,
  fill=myboxgray,
  text width=1.3cm,
  anchor=north west,
  align=center,
  inner ysep=2pt,
  font=\sffamily\small  
  },
myinfobox/.style={
  draw=myboxgray!70!black,
  text width=\textwidth-2cm-1pt,
  anchor=north west,
  inner ysep=2pt,
  fill=white,
  font=\sffamily\small  
  }
}

\newtcolorbox{mytemail}[5][]{
breakable,
pad after break=-63pt,
freelance,
colback=white,
left=0pt,
right=0pt,
outer arc=0pt,
arc=0pt,
colframe=gray,
colback=mybackgray,
boxrule=0.5pt,
top=80pt,
left=4pt,
right=4pt,
before=\par\medskip,
fontupper=\sffamily\small,
overlay unbroken and first={
  \node[mybox]
    at ([shift={(2pt,-2pt)}]frame.north west) 
    (from) {\strut From:};
  \node[mybox,below=2pt of from] 
    (to) {\strut To:};
  \node[mybox,below=2pt of to] 
    (date) {\strut Date:};
  \node[mybox,below=2pt of date] 
    (subj) {\strut Subject:};
  \node[draw,myinfobox,right=2pt of from] 
    (fromtext) {\strut #2};
  \node[draw,myinfobox,right=2pt of to] 
    (totext) {\strut #3};
  \node[draw,myinfobox,right=2pt of date] 
    (datetext) {\strut #4};
  \node[draw,myinfobox,right=2pt of subj] 
    (subjtext) {\strut #5};
  \draw[myboxgray!70!black,fill=white] 
    ([shift={(2pt,-74pt)}]interior.north west) 
      rectangle 
    ([shift={(-2pt,2pt)}]interior.south east); 
  },
overlay middle and last={
  \draw[myboxgray!70!black,fill=white] 
    ([shift={(2pt,-2pt)}]interior.north west) 
      rectangle 
    ([shift={(-2pt,2pt)}]interior.south east); 
  }  
  #1
}

\begin{document}

\lipsum[4]
\begin{mytemail}{HamiltonP, Beth}{Croft, Norrie}{September 12th 2014}{Paris}
\lipsum[4]
\end{mytemail}
\lipsum[4]

\end{document}

And now using the also powerful mdframed package:

enter image description here

All the job is now done by a mymdemail environment with four mandatory arguments:

\begin{mytemail}{<from>}{<to>}{<date>}{<subject>
<text>
\end{mytemail}

The box in the example was produced using

\begin{mymdemail}{HamiltonP, Beth}{Croft, Norrie}{September 12th 2014}{Paris}
\lipsum[4]
\end{mymdemail}

The code:

\documentclass{memoir}
\usepackage[framemethod=tikz]{mdframed}
\usetikzlibrary{positioning}
\usepackage{lipsum}% to generate text for the example

\definecolor{myboxgray}{RGB}{216,207,190}
\definecolor{mybackgray}{RGB}{243,232,223}

\def\mdfrom{\relax}
\def\mdto{\relax}
\def\mddate{\relax}
\def\mdsubj{\relax}

\tikzset{
mybox/.style={
  draw=myboxgray!70!black,
  fill=myboxgray,
  text width=1.3cm,
  anchor=north west,
  align=center,
  inner ysep=2pt,
  font=\sffamily\small  
  },
myinfobox/.style={
  draw=myboxgray!70!black,
  text width=\textwidth-2cm-1pt,
  anchor=north west,
  inner ysep=2pt,
  fill=white,
  font=\sffamily\small  
  }
}

\newmdenv[
linecolor=myboxgray!70!black,
innertopmargin=76pt,
splittopskip=19pt,
singleextra={
  \node[mybox]
    at ([shift={(2pt,-2pt)}]O|-P) 
    (from) {\strut From:};
  \node[mybox,below=2pt of from] 
    (to) {\strut To:};
  \node[mybox,below=2pt of to] 
    (date) {\strut Date:};
  \node[mybox,below=2pt of date] 
    (subj) {\strut Subject:};
  \node[draw,myinfobox,right=2pt of from] 
    (fromtext) {\strut\mdfrom};
  \node[draw,myinfobox,right=2pt of to] 
    (totext) {\strut\mdto};
  \node[draw,myinfobox,right=2pt of date] 
    (datetext) {\strut\mddate};
  \node[draw,myinfobox,right=2pt of subj] 
    (subjtext) {\strut\mdsubj};
  \draw[myboxgray!70!black] 
    ([shift={(2pt,-74pt)}]O|-P) --
    ([shift={(-2pt,-74pt)}]P) --
    ([shift={(-2pt,2pt)}]P|-O) --
    ([shift={(2pt,2pt)}]O) -- cycle;
  },
firstextra={
  \node[mybox]
    at ([shift={(2pt,-2pt)}]O|-P) 
    (from) {\strut From:};
  \node[mybox,below=2pt of from] 
    (to) {\strut To:};
  \node[mybox,below=2pt of to] 
    (date) {\strut Date:};
  \node[mybox,below=2pt of date] 
    (subj) {\strut Subject:};
  \node[draw,myinfobox,right=2pt of from] 
    (fromtext) {\strut\mdfrom};
  \node[draw,myinfobox,right=2pt of to] 
    (totext) {\strut\mdto};
  \node[draw,myinfobox,right=2pt of date] 
    (datetext) {\strut\mddate};
  \node[draw,myinfobox,right=2pt of subj] 
    (subjtext) {\strut\mdsubj};
  \draw[myboxgray!70!black] 
    ([shift={(2pt,-74pt)}]O|-P) --
    ([shift={(-2pt,-74pt)}]P) --
    ([shift={(-2pt,2pt)}]P|-O) --
    ([shift={(2pt,2pt)}]O) -- cycle;
  },
middleextra={
  \draw[myboxgray!70!black] 
    ([shift={(2pt,-2pt)}]O|-P) --
    ([shift={(-2pt,-2pt)}]P) --
    ([shift={(-2pt,2pt)}]P|-O) --
    ([shift={(2pt,2pt)}]O) -- cycle;
  },  
secondextra={
  \draw[myboxgray!70!black] 
    ([shift={(2pt,-2pt)}]O|-P) --
    ([shift={(-2pt,-2pt)}]P) --
    ([shift={(-2pt,2pt)}]P|-O) --
    ([shift={(2pt,2pt)}]O) -- cycle;
  },  
]{mdemail}

\newenvironment{mymdemail}[4]
  {%
    \gdef\mdfrom{#1}%
    \gdef\mdto{#2}%
    \gdef\mddate{#3}%
    \gdef\mdsubj{#4}%
    \begin{mdemail}
  }
  {\end{mdemail}}

\begin{document}

\lipsum[4]
\begin{mymdemail}{HamiltonP, Beth}{Croft, Norrie}{September 12th 2014}{Paris}
\lipsum[4]
\end{mymdemail}
\lipsum[4]

\end{document}
Gonzalo Medina
  • 505,128
  • Brilliant! My favourite kind of answer! and what an answer, I couldn't ask for more. Thank you so much Gonzalo. – susie Aug 07 '14 at 19:09
  • oh one tiny request ;) is it possible to add an optional parameter to mytemail to indicate that there is an attachment? I know, I need to read more documentation and I'm just playing with it now so just maybe I'll figure it out! – susie Aug 07 '14 at 19:28
  • I thought there was a placement error of the main text box but if I remove the "12pt" from my documentclass options it is placed correctly. – susie Aug 08 '14 at 11:14
  • @susie You're welcome. Regarding the optional parameter, I have some questions. Do you want the mytemail environment to have an optional argument? Soething like `\begin{mytemail}[]{}{}{}{ \end{mytemail}`? If so, what should be the effect of using this optional argument? – Gonzalo Medina Aug 08 '14 at 13:10
  • @susie I'll check the options later to improve the placement and make it independent of the size options passed to the class. – Gonzalo Medina Aug 08 '14 at 13:10
  • Sorry - been away from internet for a few days. Have been editing in the mytemail so my email chapter is looking much better now! wrt optional argument, it would be great if it was possible to have an optional box at the bottom probably stretching full width of the parent box that could contain the attachment file name(s) and maybe a save button? – susie Aug 12 '14 at 09:25
  • I've been playing around with the mytemail environment and reading the documentation for tcolorbox(!) I've not managed to change the overall width of it. I was trying to make it slightly narrower than main text and central in the page... I'll keep reading! – susie Aug 12 '14 at 09:28
  • @susie Ah, I see now what you meant by the optional argument for attachments; I am busy right now but as soon as I can I'll update the answer showing how to achieve this. Regarding the width of the box, I will also provide a way to achieve a narrower box (in the meantime, the enlarge left by=<length> and width=<length> are the options that allow you to achieve what you want). – Gonzalo Medina Aug 13 '14 at 13:10
  • You are a gem! I'll have a play with those options in the meantime. – susie Aug 13 '14 at 18:11