使用 pgfkeys 计算圆的厚度

使用 pgfkeys 计算圆的厚度

如何增加给定 pt 值时的圆的粗细?

\documentclass{book}
\usepackage{xcolor}
\usepackage{circledsteps}
\newcommand{\enclose}[2]{\begingroup
\pgfkeys{/csteps/.cd, /csteps/inner xsep=5pt, /csteps/inner ysep=5pt}%
\ifmmode
\Circled{$#2$}%
\else
\Circled{#2}%
\fi
\endgroup}
\begin{document}
\pagestyle{empty}

$\textcolor{red}{\enclose{circle}{\textcolor{cyan}{5}}}$


\end{document}

答案1

我提出以下建议。我为方便起见定义了样式/csteps/inner sep。它将/csteps/inner xsep和都设置/csteps/inner ysep为提供的长度。

\documentclass{article}
\usepackage{xcolor}
\usepackage{circledsteps}
\usepackage{xparse}

\pgfkeys{
  /csteps/inner sep/.style={
    /csteps/.cd, inner xsep={#1}, inner ysep={#1}}
}

\NewDocumentCommand \enclose { O{} O{0.4pt} m }
  {%
    \begingroup
      \pgfkeys{/csteps/.cd, inner sep=5pt, #1}%
      \linethickness{#2}%
      \Circled{#3}%
    \endgroup
  }

\begin{document}

\enclose{X}\quad
\enclose[outer color=red!70!black, inner color=blue]{X}\quad
\enclose[outer color=red!70!black, inner color=blue][0.6pt]{$0.6$}\quad
\enclose[outer color=red!70!black, inner color=blue][1pt]{$1$}\quad
\enclose[outer color=red!70!black, inner color=blue][2pt]{$2$}\quad
\enclose[outer color=red!70!black, inner color=blue, inner sep=15pt][3pt]{$3$}

\end{document}

在此处输入图片描述

如果您想保留与数学模式相关的奇怪逻辑:

\documentclass{article}
\usepackage{xcolor}
\usepackage{circledsteps}
\usepackage{xparse}

\pgfkeys{
  /csteps/inner sep/.style={
    /csteps/.cd, inner xsep={#1}, inner ysep={#1}}
}

\NewDocumentCommand \enclose { O{} O{0.4pt} m }
  {%
    \begingroup
      \pgfkeys{/csteps/.cd, inner sep=5pt, #1}%
      \linethickness{#2}%
      \ifmmode \Circled{$#3$}\else \Circled{#3}\fi
    \endgroup
  }

\begin{document}

$\enclose{X}$\quad
$\enclose[outer color=red!70!black, inner color=blue]{X}$\quad
$\enclose[outer color=red!70!black, inner color=blue][0.6pt]{0.6}$\quad
$\enclose[outer color=red!70!black, inner color=blue][1pt]{1}$\quad
$\enclose[outer color=red!70!black, inner color=blue][2pt]{2}$\quad
$\enclose[outer color=red!70!black, inner color=blue, inner sep=15pt][3pt]{3}$

\end{document}

相关内容