![在“@”处拆分长电子邮件地址](https://linux22.com/image/415143/%E5%9C%A8%E2%80%9C%40%E2%80%9D%E5%A4%84%E6%8B%86%E5%88%86%E9%95%BF%E7%94%B5%E5%AD%90%E9%82%AE%E4%BB%B6%E5%9C%B0%E5%9D%80.png)
在我的一份文档中,我想让人们选择填写他们的电子邮件地址。但是,对于一些特别长的电子邮件地址,文本框可能比它应该容纳的 tikzpicture 节点大。我现在得到了这样的结果:
但是,我更希望地址在“@”符号处精确分割,如下所示。理想情况下,只有当电子邮件地址太宽时才会发生这种情况,因此也许 if 语句可以提供帮助,但我不知道该怎么做。
这是我的代码:
\documentclass{report}
%Define helvetica as font
\usepackage[scaled]{helvet}
\usepackage[T1]{fontenc}
%Packages
\usepackage[table,xcdraw]{xcolor}
\usepackage{xfp,xparse}
\usepackage{color, colortbl}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{wrapfig}
\usetikzlibrary{matrix,shadings}
\usetikzlibrary{decorations.text}
\definecolor{Green}{HTML}{2EC1A8}
\definecolor{Grey}{HTML}{F2F2F2}
\begin{document}
\begin{titlepage}
\begin{tikzpicture}
% Static part
\node (rect) at (0,2) [draw,color=white,fill= Green,minimum width=5cm,minimum height=1cm,text =white,
text width = 5 cm,align=left] {\textbf{Opgemaakt door}};
\node (rect) at (0,-1) [draw,color=white,fill= Grey,minimum width=5cm,minimum height=5cm, align
=left,text width = 5 cm,text = black,text depth = 4cm] {
{{Organisatienaam}}\\[1\baselineskip]
{{Naamadviseur}}\\[1\baselineskip]
{{Telefoonnummer}}\\[1\baselineskip]
[email protected]
};
\end{tikzpicture}
\end{titlepage}
\end{document}
答案1
您可以使用该url
包将电子邮件地址排版为\url{emailaddress}
,它将 @ 定义为可能的断点。默认情况下,url 以等宽字体排版,但您可以使用将字体设置为默认文本字体\urlstyle{same}
。
如果不做任何进一步的修改,电子邮件地址将在 @ 后拆分:
\documentclass{report}
%Define helvetica as font
\usepackage[scaled]{helvet}
\usepackage[T1]{fontenc}
%Packages
\usepackage[table,xcdraw]{xcolor}
\usepackage{xfp,xparse}
\usepackage{color, colortbl}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{wrapfig}
\usetikzlibrary{matrix,shadings}
\usetikzlibrary{decorations.text}
\definecolor{Green}{HTML}{2EC1A8}
\definecolor{Grey}{HTML}{F2F2F2}
\usepackage{url}
\urlstyle{same}
\begin{document}
\begin{titlepage}
\begin{tikzpicture}
% Static part
\node (rect) at (0,2) [draw,color=white,fill= Green,minimum width=5cm,minimum height=1cm,text =white,
text width = 5 cm,align=left] {\textbf{Opgemaakt door}};
\node (rect) at (0,-1) [draw,color=white,fill= Grey,minimum width=5cm,minimum height=5cm, align
=left,text width = 5 cm,text = black,text depth = 4cm] {
{{Organisatienaam}}\\[1\baselineskip]
{{Naamadviseur}}\\[1\baselineskip]
{{Telefoonnummer}}\\[1\baselineskip]
\url{[email protected]}
};
\end{tikzpicture}
\end{titlepage}
\end{document}
如果要在 @ 之前拆分,则可以将 @ 定义为特殊的 url 字符,插入\allowbreak
然后打印 @ 符号(参见包装文档)。但是,这会将 @ 变成宏,因此您不能仅在 @ 的定义中打印 @,因为这会导致无限递归。但是,您可以先定义一个包含 @ 的框,然后打印该框。
相关片段:
\usepackage{url}
\urlstyle{same}
\newsavebox{\printat}
\savebox{\printat}{@}
\makeatletter\g@addto@macro\UrlSpecials{\do\@{\allowbreak\usebox{\printat}}}\makeatother
\begin{document}
答案2
您可以\allowbreak
在@后插入:
\documentclass{report}
%Define helvetica as font
\usepackage[scaled]{helvet}
\usepackage[T1]{fontenc}
%Packages
\usepackage[table,xcdraw]{xcolor}
\usepackage{xfp,xparse}
\usepackage{color, colortbl}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{wrapfig}
\usetikzlibrary{matrix,shadings}
\usetikzlibrary{decorations.text}
\definecolor{Green}{HTML}{2EC1A8}
\definecolor{Grey}{HTML}{F2F2F2}
\begin{document}
\begin{titlepage}
\begin{tikzpicture}
% Static part
\node (rect) at (0,2) [draw,color=white,fill= Green,minimum width=5cm,minimum height=1cm,text =white,
text width = 5 cm,align=left] {\textbf{Opgemaakt door}};
\node (rect) at (0,-1) [draw,color=white,fill= Grey,minimum width=5cm,minimum height=5cm, align
=left,text width = 5 cm,text = black,text depth = 4cm] {
{{Organisatienaam}}\\[1\baselineskip]
{{Naamadviseur}}\\[1\baselineskip]
{{Telefoonnummer}}\\[1\baselineskip]
someverylongemailadress@\allowbreak something.com
small@\allowbreak something.com
};
\end{tikzpicture}
\end{titlepage}
\end{document}