当我创建混合数学符号时,我经常会发现自己\rule
在某个地方堆叠了 s。但如果你查看一组 CM 数学符号(顶行),并将其与\rule
(第二行)进行比较
\documentclass{article}
\begin{document}
\noindent$+ - = \subset \geq \ni$\\$\rule{2ex}{.3pt}$
\end{document}
您会发现,组成数学字形的笔画末端呈圆形,而 a 的rule
末端则呈扁平状。在典型尺寸下,这种差异可能微不足道,但对于放大的字形,这种差异就很明显了。
是否有一个版本的\rule
,我在这里开玩笑地称之为\mathrule
,它可以提供 的功能(甚至语法)\rule
,但带有圆形的末端?(最好不是tikz
,而是更原生的东西)。
我考虑过拉伸和挤压,例如减号,但这会导致球形端盖变成椭圆形,尤其是在失真较大时。
我本来想提出这个尝试来推动事情的发展,但赫伯特抢先了一步。我还是会把它留在这里作为思考的素材。
\documentclass{article}
\usepackage{scalerel}
\usepackage{verbatimbox}
\newsavebox\clippedbullet
\sbox{\clippedbullet}{\addvbuffer[.0pt -.55pt]{$\bullet$}}
\def\CB{\usebox{\clippedbullet}}
\newcommand\mathrule[3][0pt]{%
\raisebox{#1}{\scaleleftright{\kern-.8pt\CB\kern-2.5pt}%
{\rule{#2-#3}{#3}}{\kern-2.4pt\CB\kern+.0pt}}%
}
\begin{document}
\noindent\mathrule[2pt]{2ex}{.5pt} \mathrule{3ex}{1pt} \mathrule[-1pt]{2ex}{2pt}\\
\rule[2pt]{2ex}{.5pt} \rule{3ex}{1pt} \rule[-1pt]{2ex}{2pt}
\end{document}
答案1
\pdfcompresslevel=0 %%% to see how it works in the pdf code
\pdfcompresslevel=0
\documentclass{article}
\parindent=0pt
\makeatletter
\def\mathrule#1#2{%
\@tempdima=\dimexpr#1-0.5#2
\@tempdimb=#2
\@tempdimc=0.5#2
\hbox to #1{%
\pdfliteral{
q []0 d
1 J % set line cap to rounded ends
\strip@pt\@tempdimb\space w \strip@pt\@tempdimc\space 0 m
\strip@pt\@tempdima\space 0 l S Q }}}
\makeatletter
\begin{document}
x\mathrule{60bp}{2bp}x
x$\rule{60bp}{2bp}$x
\end{document}
答案2
我发布这篇文章是将 Herbert 的解决方案应用到我想要的地方的最终结果,这是一个\rule
提供圆形线帽的 的嵌入式替代品。Herbert 值得称赞,也会得到加分,但其他人(比如我)可能希望看到/使用这个更无缝的 的嵌入式替代品\rule
。
Herbert 的解决方案需要放入一个水平盒子中,这是他允许的,但还需要进行更多调整。水平和垂直字距相对于该盒子偏移,圆角规则的垂直对齐方式与 不同\rule
,这只是其中几个例子。
编辑:我还主动强制\mathrule
制定规则,将圆形端盖放在侧面/侧面,或者顶部/底部,具体取决于哪个尺寸较大,这样
\mathrule{2ex}{2ex}
\mathrule{3ex}{2ex}
\mathrule{2ex}{3ex}
给出
在下面的 MWE 中,我将最终结果放在\mathrule
一行上、放在文本中、堆叠以及\fbox
将其与等价的进行比较\rule
。Dan后来在他的评论中解决了此 MWE 中的 。他的更正已纳入我在本答案末尾提供的\mystery@factor
样式文件中。roundrule.sty
\pdfcompresslevel=0 %%% to see how it works in the pdf code
\documentclass{article}
\usepackage{graphicx}
\usepackage{stackengine}% Used for testing; not needed for \math(v)rule's
\parindent=0pt
\makeatletter
\newcommand\mathrule[3][0pt]{%
\ifdim#2>#3\math@hrule[#1]{#2}{#3}\else\math@vrule[#1]{#2}{#3}\fi}
\newcommand\math@hrule[3][0pt]{%
\gdef\mystery@factor{0.07}%
\@tempdima=#3%
\rule[#1]{0pt}{#3}% Needed to account for .5\@tempdima vertical offset of rounded rule
\raisebox{.5\@tempdima+#1}{%
\makebox[#2][l]{\kern-.5\@tempdima\@@mathrule{#2}{#3}}}%
}
\newcommand\math@vrule[3][0pt]{%
\gdef\mystery@factor{0.0}%
\@tempdima=#2%
\rule[#1]{0pt}{#3}% Needed to account for .5\@tempdima vertical offset of rounded rule
\raisebox{-.0\@tempdima+#1}{%
\kern0.5\@tempdima%
\rotatebox{90}{\kern-0.5\@tempdima\makebox[#3][l]{\@@mathrule{#3}{#2}}}%
\kern0.5\@tempdima}%
}
\def\@@mathrule#1#2{%
\@tempdimb=#2%
\@tempdima=\dimexpr#1-\mystery@factor\@tempdimb%Why 0.07 for \math@hrule?
\pdfliteral{%
q []0 d %
1 J % set line cap to rounded ends
\strip@pt\@tempdimb\space w \strip@pt\@tempdimb\space 0 m %
\strip@pt\@tempdima\space 0 l S Q }}
\makeatother
\begin{document}
\mathrule{60bp}{1bp}\par
\rule{60bp}{1bp}\par
x\mathrule[-1pt]{20bp}{1bp}x\mathrule{20bp}{1bp}x\par
x\rule[-1pt]{20bp}{1bp}x\rule{20bp}{1bp}x\par
\stackunder[2pt]{\rule{60bp}{3bp}}{\mathrule{60bp}{3bp}}\par
\fbox{\mathrule[-1ex]{4ex}{.5ex}}\fbox{\rule[-1ex]{4ex}{.5ex}}\par
\fbox{\mathrule[+1ex]{4ex}{.5ex}}\fbox{\rule[+1ex]{4ex}{.5ex}}\par
\clearpage
\mathrule{1bp}{60bp} \rule{1bp}{60bp}\par
x\mathrule[-1pt]{1bp}{20bp}x\mathrule{1bp}{20bp}x%
\rule[-1pt]{1bp}{20bp}x\rule{1bp}{20bp}x\par
x\rule[-1pt]{1bp}{20bp}x\rule{1bp}{20bp}x\par
\stackunder[2pt]{\rule{3bp}{10bp}\mathrule{3bp}{10bp}}%
{\mathrule{3bp}{10bp}\rule{3bp}{10bp}}\par
\fbox{\mathrule[-1ex]{.5ex}{4ex}}\fbox{\rule[-1ex]{.5ex}{4ex}}\par
\fbox{\mathrule[+1ex]{.5ex}{4ex}}\fbox{\rule[+1ex]{.5ex}{4ex}}\par
\end{document}
对于那些有兴趣特别指定包(并采纳了 azetina 的重命名建议,因为它在数学模式之外起作用),这里是roundrule.sty
,介绍宏\roundrule[]{}{}
。感谢 Dan 解决并消除了神秘因素。当然, s 可以在文本模式下使用,而无需使用美元分隔符。如果您厌倦了输入长名称, \roundrule
请随意在您的序言中使用。\let\rrule\roundrule
calc
已编辑,也需要包。
\ProvidesPackage{roundrule}
[2014/05/01 V1.01 Provides rules with rounded endcaps]
%
% THIS MATERIAL IS SUBJECT TO THE LaTeX Project Public License
%
% Special thanks to users Herbert and Prof. Dan Luecking at tex.stackexchange.com:
% http://tex.stackexchange.com/questions/161297/
% is-there-such-a-thing-as-a-mathrule-rounded-endcaps
%
% V1.00 - initial release
% V1.01 - require package calc, which was omitted as an oversight.
\pdfcompresslevel=0 %%% to see how it works in the pdf code
\RequirePackage{graphicx}
\RequirePackage{calc}
\newcommand\roundrule[3][0pt]{%
\ifdim#2>#3\round@hrule[#1]{#2}{#3}\else\round@vrule[#1]{#2}{#3}\fi}
\newcommand\round@hrule[3][0pt]{%
\@tempdima=#3%
\rule[#1]{0pt}{#3}% Needed to account for .5\@tempdima vertical offset of rounded rule
\raisebox{.5\@tempdima+#1}{%
\makebox[#2][l]{\kern-.5\@tempdima\@@roundrule{#2}{#3}}}%
}
\newcommand\round@vrule[3][0pt]{%
\@tempdima=#2%
\rule[#1]{0pt}{#3}% Needed to account for .5\@tempdima vertical offset of rounded rule
\raisebox{-.0\@tempdima+#1}{%
\kern0.5\@tempdima%
\rotatebox{90}{\kern-0.5\@tempdima\makebox[#3][l]{\@@roundrule{#3}{#2}}}%
\kern0.5\@tempdima}%
}
\def\@@roundrule#1#2{%
\@tempdima=#1%
\@tempdimb=#2%
\@tempdima=0.996264\@tempdima% LaTeX to PDF point conversion (72/72.27)
\@tempdimb=0.996264\@tempdimb% LaTeX to PDF point conversion (72/72.27)
\pdfliteral{%
q []0 d %
1 J % set line cap to rounded ends
\strip@pt\@tempdimb\space w \strip@pt\@tempdimb\space 0 m %
\strip@pt\@tempdima\space 0 l S Q }}
\endinput