如何在回忆录课中实现类似电子邮件的功能

如何在回忆录课中实现类似电子邮件的功能

我正在写一些小说,并使用 texlive 进行排版。我想在故事中包含一些“电子邮件”,但我不知道如何最好地实现这一点。我的第一次尝试如下所示:

\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

显然,等宽字体并不特别适合现代电子邮件,但它应该与正文采用不同的字体(例如无衬线字体),并且大小可能不同(更小?)。

有没有直接的方法可以做到这一点?以前有人做过类似的事情吗?

答案1

这是我最喜欢的问题!

更新

如果你得到一些与电子邮件相关的漂亮图标,那么你可以将它们添加到设计中(我从图标查找器作为我的示例)。以下是tcolorbox添加了图标栏的版本(见下文):

在此处输入图片描述

代码:

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

第一个版本

这是我模拟某些提供商的电子邮件样式的一种可能性。我提供了两个版本;一个使用tcolorbox,另一个使用mdframed。两个版本都允许分页。

首先,我使用了强大的tcolorbox包裹:

在此处输入图片描述

mytemail所有工作均由具有四个强制参数的环境完成:

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

可选参数允许将最终的附加选项传递给定义的 tcolorbox。示例中的框是使用

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

代码:

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

现在使用同样强大的mdframed包裹:

在此处输入图片描述

现在,所有工作都由具有mymdemail四个强制参数的环境完成:

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

示例中的盒子是使用

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

代码:

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

相关内容