我正在尝试创建一个新符号,只需将数字与三角形组合在一起,方法是将数字放在三角形内。它应该在数学模式下工作(文本模式会很好,但不是必需的)。
我尝试了以下方法:
\documentclass{article}
\usepackage{graphicx}
\newcommand{\trinum}[1]{%
\triangle\hspace{-.57em}\raisebox{0.1em}{\scalebox{.5}{#1}}
}
\begin{document}
Works fine in default environment
\[
\trinum{1} \qquad \trinum{2} \qquad \trinum{3}
\]
Slightly shifted when used in Huge environment:
{\Huge
\[
\trinum{1} \qquad \trinum{2} \qquad \trinum{3}
\]
}
Slightly shifted when used in tiny environment:
{\tiny % I know, it's too small to read, but just used as a check
\[
\trinum{1} \qquad \trinum{2} \qquad \trinum{3}
\]
}
Messed up when used as subscript or super script
\[
\trinum{1} \qquad x_\trinum{1} \qquad x^\trinum{1}
\]
\end{document}
答案1
魔力\ooalign
:
\documentclass{article}
\usepackage{graphicx}
\newcommand{\trinum}[1]{\mathpalette\dotrinum{#1}}
\newcommand{\dotrinum}[2]{{%
\vphantom{\triangle}%
\ooalign{%
$#1\triangle$\cr\hidewidth\scaleraise{$#1#2$}\hidewidth\cr
}%
}}
\newcommand{\scaleraise}[1]{%
\raisebox{.2\height}{\scalebox{0.5}{#1}}%
}
\begin{document}
Works fine in default environment
\[
\trinum{1} \qquad \trinum{2} \qquad \trinum{3}
\]
Slightly shifted when used in Huge environment:
{\Huge
\[
\trinum{1} \qquad \trinum{2} \qquad \trinum{3}
\]
}
Slightly shifted when used in tiny environment:
{\tiny % I know, it's too small to read, but just used as a check
\[
\trinum{1} \qquad \trinum{2} \qquad \trinum{3}
\]
}
Messed up when used as subscript or super script
\[
\trinum{1} \qquad x_{\trinum{1}} \qquad x^{\trinum{1}}
\]
\end{document}
我保留了你的原文,除了对下标和上标进行括号。参见https://tex.stackexchange.com/a/22375/4427详细信息\ooalign
答案2
TikZ 解决方案在数学和文本模式下具有不同的尺寸。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\makeatletter
\newcommand*{\trinum}{}
\DeclareRobustCommand*{\trinum}[1]{%
\ensuremath{%
\mathpalette\@trinum{#1}%
}%
}
\newdimen\trinum@sep
\newdimen\trinum@rule
\newcommand*{\@trinum}[2]{%
% #1: math style
% #2: num
\settowidth\trinum@sep{$\m@th#1\mkern1mu$}%
\setlength{\trinum@rule}{.8\trinum@sep}
\tikz\node[
regular polygon,
regular polygon sides=3,
draw,
line width=\trinum@rule,
inner sep=\trinum@sep,
]{$\m@th#1#2$};
}
\makeatother
\begin{document}
\[
\trinum{1}\trinum{2}^{
\trinum{1}\trinum{2}^{
\trinum{1}\trinum{2}
}
}
\]
\begin{center}
\Huge\trinum{2}
\huge\trinum{2}
\LARGE\trinum{2}
\Large\trinum{2}
\large\trinum{2}
\normalsize\trinum{2}
\small\trinum{2}
\footnotesize\trinum{2}
\scriptsize\trinum{2}
\tiny\trinum{2}
\end{center}
\end{document}
变化,数字也可以变得更小:
\newcommand*{\@trinum}[2]{%
% #1: math style
% #2: num
\settowidth\trinum@sep{$\m@th#1\mkern.5mu$}%
\settowidth{\trinum@rule}{$\m@th#1\mkern.8mu$}%
\tikz\node[
regular polygon,
regular polygon sides=3,
draw,
line width=\trinum@rule,
inner sep=\trinum@sep,
scale=.5,
]{$\m@th#1#2$};
}