从数字更改为字母

从数字更改为字母

在本页面的一个文件中,我找到了以下图形。我需要将数字更改为字母 A、B、C、D...


\documentclass[tikz,border=7pt]{standalone}
\begin{document}
    \begin{tikzpicture}[
        every node/.style={fill=red,circle, text=white, inner sep=0, minimum size=14},
        every path/.style={draw=white,double=black, very thick}
        ]
        \foreach \i in {-1,0,1}
        \foreach[evaluate={\k=int(5-3*\j+\i)}] \j in {-1,0,1}
        \path (\i,\j)  node (\k) {\k};
        \foreach[count=\i, evaluate={\k=int(9+\i)}] \a in {45,0,-45,-90}
        \path (\a:3) node (\k) {\k};
        
        \draw (1) to (2) to (3) to[out=0,in=135] (11);
        \draw (4) to (5) to (6) to (11);
        \draw (7) to (8) to (9) to[out=0,in=-135] (11);
        
        \draw (1) to (4) to (7) to[out=-90,in=135] (13);
        \draw (2) to (5) to (8) to (13);
        \draw (3) to (6) to (9) to[out=-90,in=45] (13);
        
        \draw (7) to[out=135,in=135, distance=100] (2) (2) to (6) (6) to[out=-45,in=90] (12);
        \draw (1) to (5) to (9) to (12);
        \draw (3) to[out=135,in=135, distance=100] (4) (4) to (8) (8) to[out=-45,in=180] (12);
        
        \draw (1) to[out=-135,in=-135, distance=100] (8) (8) to (6) (6) to[out=45,in=-90] (10);
        \draw (7) to (5) to (3) to (10);
        \draw (9) to[out=-135,in=-135, distance=100] (4) (4) to (2) (2) to[out=45,in=180] (10);
        
        \draw[bend left=17] (10) to (11) (11) to (12) (12) to (13);
        
    \end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

您可以定义一个\Letter命令,使用内部的打印对应于 1-26 范围内的整数的大写字母\@Alph

\documentclass[tikz,border=7pt]{standalone}

\makeatletter
\newcommand{\Letter}[1]{\@Alph{#1}}
\makeatother


\begin{document}
    \begin{tikzpicture}[
        every node/.style={fill=red,circle, text=white, inner sep=0, minimum size=14},
        every path/.style={draw=white,double=black, very thick}
        ]
        \foreach \i in {-1,0,1}
        \foreach[evaluate={\k=int(5-3*\j+\i)}] \j in {-1,0,1}
        \path (\i,\j)  node (\k) {\Letter{\k}};
        \foreach[count=\i, evaluate={\k=int(9+\i)}] \a in {45,0,-45,-90}
        \path (\a:3) node (\k) {\Letter{\k}};
        
        \draw (1) to (2) to (3) to[out=0,in=135] (11);
        \draw (4) to (5) to (6) to (11);
        \draw (7) to (8) to (9) to[out=0,in=-135] (11);
        
        \draw (1) to (4) to (7) to[out=-90,in=135] (13);
        \draw (2) to (5) to (8) to (13);
        \draw (3) to (6) to (9) to[out=-90,in=45] (13);
        
        \draw (7) to[out=135,in=135, distance=100] (2) (2) to (6) (6) to[out=-45,in=90] (12);
        \draw (1) to (5) to (9) to (12);
        \draw (3) to[out=135,in=135, distance=100] (4) (4) to (8) (8) to[out=-45,in=180] (12);
        
        \draw (1) to[out=-135,in=-135, distance=100] (8) (8) to (6) (6) to[out=45,in=-90] (10);
        \draw (7) to (5) to (3) to (10);
        \draw (9) to[out=-135,in=-135, distance=100] (4) (4) to (2) (2) to[out=45,in=180] (10);
        
        \draw[bend left=17] (10) to (11) (11) to (12) (12) to (13);
        
    \end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

我的回答基于对类似问题的回答:https://tex.stackexchange.com/a/398430/118712

您可以将变量定义\k为计数器,然后使用 输出字母值\Alph{}

\documentclass[tikz,border=7pt]{standalone}
\newcounter{ccount}

\begin{document}
    \begin{tikzpicture}[
        every node/.style={fill=red,circle, text=white, inner sep=0, minimum size=14},
        every path/.style={draw=white,double=black, very thick}
        ]
        \foreach \i in {-1,0,1}
        \foreach[evaluate={\k=int(5-3*\j+\i)}] \j in {-1,0,1}
        \setcounter{ccount}{\k}
        \path (\i,\j)  node (\k) {\Alph{ccount}};
        \foreach[count=\i, evaluate={\k=int(9+\i)}] \a in {45,0,-45,-90}
        \setcounter{ccount}{\k}
        \path (\a:3) node (\k) {\Alph{ccount}};
        
        \draw (1) to (2) to (3) to[out=0,in=135] (11);
        \draw (4) to (5) to (6) to (11);
        \draw (7) to (8) to (9) to[out=0,in=-135] (11);
        
        \draw (1) to (4) to (7) to[out=-90,in=135] (13);
        \draw (2) to (5) to (8) to (13);
        \draw (3) to (6) to (9) to[out=-90,in=45] (13);
        
        \draw (7) to[out=135,in=135, distance=100] (2) (2) to (6) (6) to[out=-45,in=90] (12);
        \draw (1) to (5) to (9) to (12);
        \draw (3) to[out=135,in=135, distance=100] (4) (4) to (8) (8) to[out=-45,in=180] (12);
        
        \draw (1) to[out=-135,in=-135, distance=100] (8) (8) to (6) (6) to[out=45,in=-90] (10);
        \draw (7) to (5) to (3) to (10);
        \draw (9) to[out=-135,in=-135, distance=100] (4) (4) to (2) (2) to[out=45,in=180] (10);
        
        \draw[bend left=17] (10) to (11) (11) to (12) (12) to (13);
        
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容