控制 tkz-euclide 网格中的子线颜色

控制 tkz-euclide 网格中的子线颜色

我对在此网格中使用第三种颜色作为“子”线感兴趣。这可能吗?

\documentclass[twoside,12pt]{article}
\usepackage[hmargin=0.75in,vmargin=0.5in,includeheadfoot,headheight=10mm,headsep=4mm]{geometry}
\usepackage[usenames,dvipsnames]{xcolor} \definecolor{Color1}{HTML}{990000} \definecolor{Color2}{HTML}{009900} \definecolor{Color3}{HTML}{000099}
\usepackage{tikz}
\usepackage{tkz-euclide}
\begin{document}
\begin{center}
\begin{tikzpicture}
\def\tkzRatioLineGrid{0.5} 
\tkzInit[xmax=40, ymax=50, xmin=-40, ymin=-50, xstep=5, ystep=5]
\tkzGrid[color=Color2, line width=0.4mm, sub, subxstep=1, subystep=1]
\tkzAxeXY[line width=0.6mm, color=Color1]
\end{tikzpicture}
\end{center}
\clearpage
\end{document}

答案1

子线的子颜色定义为网格线颜色的一部分,在文件里tkz-tools-base我们可以找到

\pgfkeys{
  /tkzGrid/.cd,
  color/.code      = {\def\tkz@gd@color{#1}%
                      \edef\tkz@gd@subcolor{%
                      \tkz@gd@color!\tkzCoeffSubColor}}}

我们可以subcolortkzGrid这样添加键

\pgfkeys{/tkzGrid/.cd,subcolor/.code={\def\tkz@gd@subcolor{#1}}}

在这种情况下,只需添加颜色即可subcolor=Color3

代码

\documentclass[twoside,12pt]{article}
\usepackage[hmargin=0.75in,vmargin=0.5in,includeheadfoot,headheight=10mm,headsep=4mm]{geometry}
\usepackage[usenames,dvipsnames]{xcolor} \definecolor{Color1}{HTML}{990000} \definecolor{Color2}{HTML}{009900} \definecolor{Color3}{HTML}{000099}
\usepackage{tikz}
\usepackage{tkz-euclide}

\makeatletter
\pgfkeys{/tkzGrid/.cd,subcolor/.code={\def\tkz@gd@subcolor{#1}}}
\makeatother

\begin{document}
\begin{center}
\begin{tikzpicture}
\def\tkzRatioLineGrid{0.5} 
\tkzInit[xmax=40, ymax=50, xmin=-40, ymin=-50, xstep=5, ystep=5]
\tkzGrid[color=Color2, line width=0.4mm, sub, subxstep=1, subystep=1,subcolor=Color3]
\tkzAxeXY[line width=0.6mm, color=Color1]
\end{tikzpicture}
\end{center}
\clearpage
\end{document}

相关内容