Latex 中的新符号

Latex 中的新符号

我想直接在 latex 中定义以下命令。

  • \cross{a}{b}这应该会创建一个黑色正方形,里面有一个灰色十字,符号$a$$b$沿对角线排列。注意:字母 a 和 b 作为参数传递。我只对参数是单个小写字母的情况感兴趣。

  • \crossdot{a}{b}与 类似\cross{a}{b},只是要在十字中间添加一个灰色圆圈。

这两个新符号都应该在文本中使用,因此我希望它们的大小与大写字母差不多$G$。稍微大一点也可以。下面是一张说明我想要的图片。

我如何在乳胶中为这些符号创建命令?

\cross{a}{b}、\crossdot{a}{b} 和字母 $G$

答案1

堆叠和缩放。

\documentclass{article}
\usepackage{xcolor,stackengine,scalerel}
\newcommand\graybox[1][]{\color{gray}%
  \fbox{\makebox[\dimexpr\ht\strutbox+\dp\strutbox\relax]{\textcolor{black}{$#1$}\strut}}}
\newcommand\crossbox[2]{\hbox{\fboxsep=-\fboxrule\relax\fbox{%
  \fboxrule=.5\fboxrule\relax\stackon[0pt]{\graybox\graybox[#2]}{\graybox[#1]\graybox}}}}
\newcommand\cross[2]{\kern1pt\scalerel*{\crossbox{#1}{#2}}{G}\kern1pt}
\newcommand\crossdot[2]{\stackinset{c}{}{c}{-.31pt}{\textcolor{gray}{$\cdot$}}%
  {\cross{#1}{#2}}}
\begin{document}
$\cross{g}{d} \crossdot{a}{b} G$
\end{document}

在此处输入图片描述

在这个版本中,\fboxsep内部的尺寸\crossbox已被缩小,插入字母的尺寸略有增加。

\documentclass{article}
\usepackage{xcolor,stackengine,scalerel}
\newcommand\graybox[1][]{\color{gray}%
  \fbox{\makebox[\dimexpr\ht\strutbox+\dp\strutbox\relax]{\textcolor{black}{$#1$}\strut}}}
\newcommand\crossbox[2]{\hbox{\fboxsep=-\fboxrule\relax\fbox{\fboxsep=-1pt\relax%
  \fboxrule=.5\fboxrule\relax\stackon[0pt]{\graybox\graybox[#2]}{\graybox[#1]\graybox}}}}
\newcommand\cross[2]{\kern1pt\scalerel*{\crossbox{#1}{#2}}{G}\kern1pt}
\newcommand\crossdot[2]{\stackinset{c}{}{c}{-.31pt}{\textcolor{gray}{$\cdot$}}%
  {\cross{#1}{#2}}}
\begin{document}
$\cross{g}{d} \crossdot{a}{b} G$
\end{document}

在此处输入图片描述

答案2

另一个解决方案:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{lmodern}

\newcommand{\cross}[2]{%
    \resizebox{11pt}{!}{
    \begin{tikzpicture}[font=\tiny, every node/.style={draw=gray, text=black, inner sep=0.5pt, outer sep=0pt, minimum size=8pt}
    ]
        \node (A) {$#1$};
        \node[below right=0pt of A] (B) {$#2$};
        \draw (A.north west) rectangle (B.south east);
    \end{tikzpicture}}}

\newcommand{\crossdot}[2]{%
    \resizebox{11pt}{!}{
    \begin{tikzpicture}[font=\tiny, every node/.style={draw=gray, text=black, outer sep=0pt, inner sep=0.5pt, minimum size=8pt}]
        \node {$#1$};
        \node[below right=0pt of A] (B) {$#2$};
        \draw (A.north west) rectangle (B.south east);
        \fill[gray] (A.south east) circle(1pt);
    \end{tikzpicture}}}

\begin{document}

$G$ \cross{a}{b} \cross{m}{g} \crossdot{m}{h}
\end{document}

在此处输入图片描述

答案3

您可以优化这两个宏以使其具有共同的主体,但只是开始:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\newcommand\cross[3][]{%
    \begin{tikzpicture}[baseline, x=1em, y=1em, #1]
        \draw[gray] (0,0) rectangle (1,1);
        \draw[gray] (0,0.5) rectangle (1,0.5);
        \draw[gray] (0.5,0) rectangle (0.5,1);
        \node[inner sep=0pt, font=\tiny] at (0.25,0.75){$#2$};
        \node[inner sep=0pt, font=\tiny] at (0.75,0.25){$#3$};
    \end{tikzpicture}}
    \newcommand\crossdot[3][]{%
    \begin{tikzpicture}[baseline, x=1em, y=1em, #1]
        \draw[gray] (0,0) rectangle (1,1);
        \draw[gray] (0,0.5) rectangle (1,0.5);
        \draw[gray] (0.5,0) rectangle (0.5,1);
        \fill[gray] (0.5,0.5) circle (1pt);
        \node[inner sep=0pt, font=\tiny] at (0.25,0.75){$#2$};
        \node[inner sep=0pt, font=\tiny] at (0.75,0.25){$#3$};
    \end{tikzpicture}}
\begin{document}

G\cross{a}{b} \crossdot{c}{d} G \cross[scale=0.8, transform shape]{c}{d}


\end{document}

在此处输入图片描述

相关内容