Tikz ベースのテキストを作成することは可能ですか?

Tikz ベースのテキストを作成することは可能ですか?

私の Tikz プロットの 1 つに、赤で塗りつぶされた単純な円を作成しました。

\addplot [mark=*, mark size=3, mark options={solid, fill=red}] coordinates {
(1.25, 0) };

今、私はテキスト内でその円を参照したいのですが、テキストとインラインで同じ円を再現するコマンドを作成できるかどうか疑問に思っています。

編集

可能な解決策は、図のキャプションでほぼ機能します。

ここに画像の説明を入力してください

答え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}

結果

関連情報