答案1
圆圈也可以在 TikZ 中绘制;plot
也接受mark
选项:
\documentclass{article}
\usepackage{tikz}
\newcommand*{\RedCircle}{}
\DeclareRobustCommand*{\RedCircle}{%
\tikz\path plot[
mark=*,
mark size=3,
mark options={solid, fill=red},
] coordinates {(0, 0)};%
}
\begin{document}
Circle: \RedCircle
\end{document}
以数学轴为中心垂直居中
居中的符号更适合放在括号内。
\documentclass{article}
\usepackage{tikz}
\newcommand*{\RedCircle}{}
\DeclareRobustCommand*{\RedCircle}{%
\ensuremath{\vcenter{\hbox{%
\tikz\path plot[
mark=*,
mark size=3,
mark options={solid, fill=red},
] coordinates {(0, 0)};%
}}}%
}
\begin{document}
Circle (\RedCircle)
\end{document}
边界框校正
TikZ 似乎忘记将标记的线宽考虑在边界框中。以下代码添加了一个小框架来弥补这一点:
\documentclass{article}
\usepackage{tikz}
\newcommand*{\RedCircle}{}
\DeclareRobustCommand*{\RedCircle}{%
\ensuremath{\vcenter{\hbox{%
\setlength{\fboxsep}{.21pt}%
% 0.2pt (half line width)
% + 0.01pt to get some rounding tolerance
\setlength{\fboxrule}{0pt}%
\fbox{%
\tikz\path plot[
mark=*,
mark size=3,
mark options={solid, fill=red, draw=black},
] coordinates {(0, 0)};%
}%
}}}%
}
\begin{document}
% Show bounding box:
\setlength{\fboxsep}{0pt}
\setlength{\fboxrule}{.1pt}
(\textcolor{cyan}{\fbox{\RedCircle}})
\end{document}
在 TikZ 内部添加边距(也许图像会因外部化而被剪裁):
\documentclass{article}
\usepackage{tikz}
\newcommand*{\RedCircle}{}
\DeclareRobustCommand*{\RedCircle}{%
\ensuremath{\vcenter{\hbox{%
\def\BoundingBoxCorrection{.55\pgflinewidth}%
% .5\pgflinewidth: half the line width, forgotten by TikZ
% .05\pgflinewidth: some tolerance for rounding errors
\tikz\path plot[
mark=*,
mark size=3,
mark options={solid, fill=red, draw=black},
] coordinates {(0, 0)}
(current bounding box.south west)
++(-\BoundingBoxCorrection, -\BoundingBoxCorrection)
(current bounding box.north east)
++(\BoundingBoxCorrection, \BoundingBoxCorrection)
;%
}}}%
}
\begin{document}
% Show bounding box:
\setlength{\fboxsep}{0pt}
\setlength{\fboxrule}{.1pt}
(\textcolor{cyan}{\fbox{\RedCircle}})
\end{document}