Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
Basically you want to define an environment in which to put the mail, right? Are you settled on the looks? –  Johannes_B Aug 5 at 16:54
1  
    
I saw the "internet-style" quoting answer when I was searching for a solution. I didn't fully understand it but it didn't seem to produce something that would look good in a fiction setting. And no, I'm not settled on the looks really. It just needs to look like email and stand out from the body text. :) –  susie Aug 5 at 17:05
    
As I said in my answer, my favorite kind of question! –  Gonzalo Medina Aug 5 at 20:25
    
@susie I've removed your 'signature' from the post as your name appears as a little icon in the bottom-right anyway. –  Joseph Wright Aug 6 at 7:27

1 Answer 1

up vote 17 down vote accepted

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}
share|improve this answer
    
Brilliant! My favourite kind of answer! and what an answer, I couldn't ask for more. Thank you so much Gonzalo. –  susie Aug 7 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 7 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 8 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}[<optional>]{<from>}{<to>}{<date>}{<subject> <text> \end{mytemail}? If so, what should be the effect of using this optional argument? –  Gonzalo Medina Aug 8 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 8 at 13:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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