我想通过重复一个符号来加下划线(例如+
)。我有一段适用于下划线的代码x
,但我无法让它适用于+
:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{decorations.shapes}
\newcommand{\latexunderplus}[1]{%
\tikz[baseline=(todotted.base)]{
\node[inner xsep=0pt,inner ysep=1pt,outer sep=0pt] (todotted) {#1};
\draw[decorate,decoration={crosses,shape size=1pt},segment length=2pt] (todotted.south west) -- (todotted.south east);
}%
}%
\begin{document}
\latexunderplus{qwe}
\end{document}
从我读过的内容来看,我可能可以使用 来\pgfdeclareshape
声明与我的符号相对应的新形状,然后使用它代替crosses
。这意味着告诉 tikz 如何绘制我用于下划线的每个符号。还有其他(更简单的)方法吗?例如,某些函数可以自动将字符转换为形状?
答案1
如果您愿意尝试一点普通的 TeX,您可以使用框和引线来做到这一点:
\documentclass{article}
\def\undermark#1#2{\setbox0\hbox{#2}\hbox to 0pt{\copy0\hss}\lower2ex\hbox to
\wd0{\cleaders\hbox{#1}\hfil}}
\begin{document}
However, a service-oriented \undermark{$\cdot$}{paradigm} is further compounded
when taking into account the evolution of specifications over a given time period.
Interestingly enough, the fully integrated test program presents extremely
interesting challenges to the preliminary \undermark{$\scriptstyle+$}{qualification} limit. Similarly, the
incorporation of additional mission constraints must utilize and be functionally
interwoven with possible bidirectional logical relationship \undermark{x}{approaches}.
\end{document}
观察结果
这不是很强大 - 例如,如果在行尾附近使用它,它会弄乱换行。
我认为它的印刷效果看起来很丑。
解释
\def\undermark#1#2
定义一个需要两个参数的命令\setbox0\hbox{#2}
将盒子寄存器 0 设置为包含第二个参数的盒子\hbox to 0pt{\copy0\hss}
排版一个零宽度的框,其中包含框寄存器 0 的内容,所有内容均突出在右侧。\lower2ex
在基线下方排版以下框 2ex\hbox to \wd0{}
排版 aa 框拉伸至框寄存器 0 的宽度\cleaders\hbox{#1}\hfil
创建由包含第一个参数的框的副本组成的可拉伸图案
答案2
您可能只需旋转十字架,就能为 发明一种新的装饰\ominus
。这可以通过查找pgflibrarydecorations.shapes.code.tex
、从那里复制代码并进行调整来完成。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{decorations.shapes}
\makeatletter
\pgfdeclaredecoration{ominus}{init}
{
\state{init}[width=+0pt,next state=crosses,persistent precomputation={
\pgfmathparse{\pgfkeysvalueof{/pgf/decoration/shape start width}/sqrt(8)}
\edef\pgf@lib@dec@ssw{\pgfmathresult pt}
\pgfmathparse{\pgfkeysvalueof{/pgf/decoration/shape start height}/2}
\edef\pgf@lib@dec@ssh{\pgfmathresult pt}
}]{}
\state{crosses}[switch if less than=+\pgfdecorationsegmentlength to last,
width=+\pgfdecorationsegmentlength]
{
\pgfpathmoveto{\pgfqpoint{-\pgf@lib@dec@ssw}{0pt}}
\pgfpathlineto{\pgfqpoint{\pgf@lib@dec@ssw}{0pt}}
\pgfpathlineto{\pgfqpoint{\pgf@lib@dec@ssw}{0pt}}
\pgfpathcircle{\pgfpointorigin}{\pgf@lib@dec@ssw}\pgfusepath{stroke}
}
\state{last}[width=+\pgfdecoratedremainingdistance]
{
\pgfpathmoveto{\pgfqpoint{-\pgf@lib@dec@ssw}{0pt}}
\pgfpathlineto{\pgfqpoint{\pgf@lib@dec@ssw}{0pt}}
\pgfpathlineto{\pgfqpoint{\pgf@lib@dec@ssw}{0pt}}
\pgfpathcircle{\pgfpointorigin}{\pgf@lib@dec@ssw}\pgfusepath{stroke}
}
\state{final}{
\pgfpathmoveto{\pgfpointdecoratedpathlast}
\pgfpathmoveto{\pgfqpoint{-\pgf@lib@dec@ssw}{0pt}}
\pgfpathlineto{\pgfqpoint{\pgf@lib@dec@ssw}{0pt}}
\pgfpathlineto{\pgfqpoint{\pgf@lib@dec@ssw}{0pt}}
\pgfpathcircle{\pgfpointorigin}{\pgf@lib@dec@ssw}\pgfusepath{stroke}
}
}
\makeatother
\newcommand{\latexunderplus}[1]{%
\tikz[baseline=(todotted.base)]{
\node[inner xsep=0pt,inner ysep=1pt,outer sep=0pt] (todotted) {#1};
\draw[decorate,decoration={crosses,shape size=2pt,transform={rotate=45}},segment length=2pt] (todotted.south west) -- (todotted.south east);
}%
}%
\newcommand{\latexunderominus}[1]{%
\tikz[baseline=(todotted.base)]{
\node[inner xsep=0pt,inner ysep=1pt,outer sep=0pt] (todotted) {#1};
\draw[decorate,decoration={ominus,shape size=5pt},segment length=5pt] (todotted.south west) -- (todotted.south east);
}%
}%
\begin{document}
\latexunderplus{qwe}
\latexunderominus{qwe}
\end{document}
答案3
两种解决方案并列:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{decorations.shapes}
\usepackage{anyfontsize}
\usepackage{calc}
\def\undermark#1#2{
\setbox0\hbox{#2}\hbox to 0pt{\copy0\hss}\lower\the\dimexpr\dp0+2pt\relax\hbox to
\wd0{\cleaders\hbox{#1}\hfil}}
\makeatletter
\pgfdeclaredecoration{ominus}{init}
{
\state{init}[width=+0pt,next state=crosses,persistent precomputation={
\pgfmathparse{\pgfkeysvalueof{/pgf/decoration/shape start width}/sqrt(8)}
\edef\pgf@lib@dec@ssw{\pgfmathresult pt}
\pgfmathparse{\pgfkeysvalueof{/pgf/decoration/shape start height}/2}
\edef\pgf@lib@dec@ssh{\pgfmathresult pt}
}]{}
\state{crosses}[switch if less than=+\pgfdecorationsegmentlength to last,
width=+\pgfdecorationsegmentlength]
{
\pgfpathmoveto{\pgfqpoint{-\pgf@lib@dec@ssw}{0pt}}
\pgfpathlineto{\pgfqpoint{\pgf@lib@dec@ssw}{0pt}}
\pgfpathlineto{\pgfqpoint{\pgf@lib@dec@ssw}{0pt}}
\pgfpathcircle{\pgfpointorigin}{\pgf@lib@dec@ssw}\pgfusepath{stroke}
}
\state{last}[width=+\pgfdecoratedremainingdistance]
{
\pgfpathmoveto{\pgfqpoint{-\pgf@lib@dec@ssw}{0pt}}
\pgfpathlineto{\pgfqpoint{\pgf@lib@dec@ssw}{0pt}}
\pgfpathlineto{\pgfqpoint{\pgf@lib@dec@ssw}{0pt}}
\pgfpathcircle{\pgfpointorigin}{\pgf@lib@dec@ssw}\pgfusepath{stroke}
}
\state{final}{
\pgfpathmoveto{\pgfpointdecoratedpathlast}
\pgfpathmoveto{\pgfqpoint{-\pgf@lib@dec@ssw}{0pt}}
\pgfpathlineto{\pgfqpoint{\pgf@lib@dec@ssw}{0pt}}
\pgfpathlineto{\pgfqpoint{\pgf@lib@dec@ssw}{0pt}}
\pgfpathcircle{\pgfpointorigin}{\pgf@lib@dec@ssw}\pgfusepath{stroke}
}
}
\makeatother
\newcommand{\latexunderplus}[1]{%
\tikz[baseline=(todotted.base)]{
\node[inner xsep=0pt,inner ysep=1pt,outer sep=0pt] (todotted) {#1};
\draw[decorate,decoration={crosses,shape size=1.5pt,transform={rotate=45}},segment length=2.5pt] (todotted.south west) -- (todotted.south east);
}%
}%
\newcommand{\latexunderominus}[1]{%
\tikz[baseline=(todotted.base)]{
\node[inner xsep=0pt,inner ysep=1pt,outer sep=0pt] (todotted) {#1};
\draw[decorate,decoration={ominus,shape size=2.5pt},segment length=3pt] (todotted.south west) -- (todotted.south east);
}%
}%
\begin{document}
\newcommand{\mytest}[1]{
$\latexunderplus{\ensuremath{#1}}$
$\latexunderominus{\ensuremath{#1}}$
vs
$\undermark{\fontsize{2pt}{3pt}\selectfont +}{\ensuremath{#1}}$
$\undermark{\fontsize{2pt}{3pt}\selectfont \ensuremath{\ominus}}{\ensuremath{#1}}$
}
\mytest{\ensuremath{V_1}}\\
\mytest{qwe}\\
\mytest{abc}
\end{document}