如何以居中的方式在一行内嵌入小 tikz \textcircled 数字

如何以居中的方式在一行内嵌入小 tikz \textcircled 数字

我想在方程式中嵌入一些小的 tikz 文本圆圈数字。在下面的例子中,当自然数超过 9 时,事物开始不居中。我应该如何修改我从问题中获取的 \numcircledtikzscriptsize 宏制作 \textcircled 数字的好方法?

\documentclass[a4paper]{article}
\usepackage{amsmath}
\usepackage{array}
\usepackage{tikz}

\newcommand*\numcircledtikzscriptsize[1]{\tikz[baseline=(char.base)]{\node[shape=circle,draw,inner sep=0.5pt] (char) {\scriptsize \bf #1};}}

\begin{document}
\begin{equation*}
\begin{tabular}[t]{cl}
\tikz \node[inner sep=-1.8pt,fill=white,circle] {\numcircledtikzscriptsize{1}};&$y\leq x+1$\\
\tikz \node[inner sep=-1.8pt,fill=white,circle] {\numcircledtikzscriptsize{2}};&$y\leq x+1$\\
\tikz \node[inner sep=-1.8pt,fill=white,circle] {\numcircledtikzscriptsize{3}};&$y\leq x+1$\\
\tikz \node[inner sep=-1.8pt,fill=white,circle] {\numcircledtikzscriptsize{3}};&$y\leq x+1$\\
\tikz \node[inner sep=-1.8pt,fill=white,circle] {\numcircledtikzscriptsize{4}};&$y\leq x+1$\\
\tikz \node[inner sep=-1.8pt,fill=white,circle] {\numcircledtikzscriptsize{5}};&$y\leq x+1$\\
\tikz \node[inner sep=-1.8pt,fill=white,circle] {\numcircledtikzscriptsize{6}};&$y\leq x+1$\\
\tikz \node[inner sep=-1.8pt,fill=white,circle] {\numcircledtikzscriptsize{7}};&$y\leq x+1$\\
\tikz \node[inner sep=-1.8pt,fill=white,circle] {\numcircledtikzscriptsize{8}};&$y\leq x+1$\\
\tikz \node[inner sep=-1.8pt,fill=white,circle] {\numcircledtikzscriptsize{9}};&$y\leq x+1$\\
\tikz \node[inner sep=-1.8pt,fill=white,circle] {\numcircledtikzscriptsize{10}};&$y\leq x+1$\\
\tikz \node[inner sep=-1.8pt,fill=white,circle] {\numcircledtikzscriptsize{11}};&$y\leq x+1$\\
\tikz \node[inner sep=-1.8pt,fill=white,circle] {\numcircledtikzscriptsize{12}};&$y\leq x+1$\\
\end{tabular}
\end{equation*}
\end{document}

在此处输入图片描述

答案1

你正在进行节点设置两次(例如inner sep=-1.8pt),这只会让事情变得非常混乱。您应该\numcircledtikzscriptsize按原样使用:

\documentclass[a4paper]{article}
\usepackage{amsmath}
\usepackage{array}
\usepackage{tikz}

\newcommand*\numcircledtikzscriptsize[1]{\tikz[baseline=(char.base)]{\node[shape=circle,draw,inner sep=0.5pt] (char) {\scriptsize \bfseries #1};}}
\begin{document}
\begin{equation*}
    \begin{tabular}[t]{cl}
        \numcircledtikzscriptsize{1}  & $y\leq x+1$ \\
        \numcircledtikzscriptsize{12} & $y\leq x+1$ \\
    \end{tabular}
\end{equation*}
\end{document}

居中

您还可以用来\phantom设置“最大”尺寸,并使它们具有相同的高度,如下所示:

\newcommand*\numcircledtikzscriptsize[1]{\tikz[baseline=(char.base)]{\node[shape=circle,draw,inner sep=1pt] (char) {\scriptsize\phantom{77}};\node at (char){\bfseries\scriptsize #1};}}

在此处输入图片描述

相关内容