Tikz 기반 텍스트를 만드는 것이 가능합니까?

Tikz 기반 텍스트를 만드는 것이 가능합니까?

내 Tikz 플롯 중 하나에서 빨간색으로 채워진 간단한 원을 만들었습니다.

\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}

결과

관련 정보