答案1
在这个解决方案中定义了两个宏。第一个是\slsh
,它定义单词之间的对角线。您可以通过更改来调整高度2.2ex
,并通过更改来调整倾斜度1.2ex
,但保留ex
单位。
第二个宏称为\addspace
,它计算 的尺寸,在您想要的单词之间\slsh
绘制,并使用和在下方和上方添加线条以与现有文本重叠。我设置了重叠,但您可以将其设置为任意长度。\slsh
\llap
\rlap
1em
以下是代码:
\documentclass{article}
\usepackage{graphicx} % needed for \resizebox
\usepackage{calc} % needed to subtract from \hght
\newlength{\wdth}
\newlength{\hght}
\newlength{\dpth}
\newcommand{\slsh}{\resizebox{1.2ex}{2.2ex}{\normalfont /}}
\newcommand{\addspace}{\settowidth{\wdth}{\slsh}\settoheight{\hght}{\slsh}\settodepth{\dpth}{\slsh}%
\llap{\rule[-\dpth]{1em}{.09ex}}\hspace{-.13\wdth}\slsh%
\hspace{-.15\wdth}\rlap{\rule[\hght-.09ex]{1em}{.09ex}}}
\begin{document}
Electric\addspace heater
\emph{Electric\addspace heater}
\textbf{Electric\addspace heater}
{\large Electric\addspace heater}
{\Large Electric\addspace heater}
\end{document}
答案2
这可以以更方便的方式实现您的要求:
该宏\sepafter
有两个参数。第一个参数将被加下划线,第二个参数将被加上划线。它们之间/
设置了 a。
利用这一事实,即{}
TeX 不以一个标记作为参数(即这里的一个字母),可以通过书写\sepafter ch
来获得c
下划线和h
上划线,并在它们之间加上/
。
这并不完美,从斜体或倾斜字体就可以看出。因此,\sepafter
有一个可选参数来调整必要的校正。但即使这样,它也不是完美的。
编辑:添加了颜色。\sepafter
现在用于corrcolor
校正标记。它在序言中定义。
代码:
\documentclass[12pt]{article}
\usepackage{amssymb,mathtools}
\usepackage{xcolor}
\definecolor{corrcolor}{rgb}{1,0,0}
\newbox\beforebox
\newbox\afterbox
\newbox\slashbox
\def\sepcorrection{-0.1em} % default correction
\newcommand*{\sepafter}[3][\sepcorrection]{%
\setbox\beforebox\hbox{#2}% for measuring the width
\setbox\afterbox\hbox{#3}%
\setbox\slashbox\hbox{/}% for measuring height and depth
\mbox{}% to make it work at the begining of an indented paragraph
\rlap{#2}% print argument with 0 width, overlaping to the right
{\color{corrcolor}%
\rule[-\dp\slashbox]{\wd\beforebox}{0.1ex}% the underline
\hskip#1/\hskip#1}% apply some correction, so under-/overline meet slash
\rlap{#3}%
{\color{corrcolor}%
\rule[\ht\slashbox]{\wd\afterbox}{0.1ex}}% the overline
}
\begin{document}
Electricheater % to be separately written
Electri\sepafter cheater \quad just one letter on each side
Electri\sepafter cHeater \quad just one letter on each side, right side is upper case
Elect\sepafter{ric}{hea}ter \quad mark a few letters on each side
\sepafter{Electric}{heater} \quad mark whole words
Elect\sepafter{ric}heater \quad mark a few letters on left side
Electri\sepafter c{hea}ter \quad mark a few letters on right side
\vspace{1ex}
\textbf{\Huge Elect\sepafter{ric}{hea}ter} \quad other size
\vspace{1ex}
\textit{Elect\sepafter[0.04em]{ric}{hea}ter} \quad italic needs different correction, but still not perfect
\textsl{Elect\sepafter[0.04em]{ric}{hea}ter} \quad same for slanted
\end{document}