我想将数字 3 涂成蓝色,将数字 -1 涂成绿色,如下图所示。
我的代码是这样的:
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{tikz}
\usepackage{tkz-euclide}
\begin{document}
\begin{tikzpicture}
\tkzInit[xmin=-4.5,xmax=4,xstep=1]
\tkzAxeX[label={}]
\coordinate (A) at (3,0);
\coordinate (O) at (0,0);
\coordinate (B) at (-1,0);
\coordinate (C) at (.5,.7);
\coordinate (D) at (4,.7);
\coordinate (E) at (-.5,.7);
\coordinate (F) at (-4,.7);
\tkzDrawSegment[ultra thick, color=blue](O,A)
\tkzDrawSegment[ultra thick, color=green](O,B)
\tkzDrawSegments[dashed](O,C C,D O,E E,F)
\end{tikzpicture}
\end{document}
我使用 tkz-euclide 包
答案1
首先要说的是。tkz 集合是使用常规选项来制作一些自动图片的。如果你想用灵活的方法创建特定的图片,我认为最好学习 Tikz 并使用它。
手动地,您需要使用\tkzDrawX[label={}]
而不是\tkzAxeX
。解决方案是可行的,因为在您的代码中您拥有xstep=1
并使用了很多默认选项。另一种方法是用颜色覆盖一些节点fill=white
(如果背景是白色)
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{tikz}
\usepackage{tkz-euclide}
\begin{document}
\begin{tikzpicture}
\tkzInit[xmin=-4.5,xmax=4]
\tkzDrawX[label={}]
\coordinate (A) at (3,0);
\coordinate (O) at (0,0);
\coordinate (B) at (-1,0);
\coordinate (C) at (.5,.7);
\coordinate (D) at (4,.7);
\coordinate (E) at (-.5,.7);
\coordinate (F) at (-4,.7);
\tkzDrawSegment[ultra thick, color=blue](O,A)
\tkzDrawSegment[ultra thick, color=green](O,B)
\tkzDrawSegments[dashed](O,C C,D O,E E,F)
\node[below,text=green] at (-1,0) {$-1$};
\node[below,text=blue] at (3,0) {$3$};
\foreach \x in {-4,-3,-2,0,1,2,4} \node[below,] at (\x,0) {$\x$};
\end{tikzpicture}
\end{document}
第二种方法,使用默认选项。虽然不太好,但你可以得到你想要的结果
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{tikz}
\usepackage{tkz-euclide}
\begin{document}
\begin{tikzpicture}
\tkzInit[xmin=-4.5,xmax=4,xstep=1]
\tkzAxeX[label={}]
\coordinate (A) at (3,0);
\coordinate (O) at (0,0);
\coordinate (B) at (-1,0);
\coordinate (C) at (.5,.7);
\coordinate (D) at (4,.7);
\coordinate (E) at (-.5,.7);
\coordinate (F) at (-4,.7);
\tkzDrawSegment[ultra thick, color=blue](O,A)
\tkzDrawSegment[ultra thick, color=green](O,B)
\tkzDrawSegments[dashed](O,C C,D O,E E,F)
\node[below=2pt,text=blue,fill=white] at (3,0) {$3$};
\end{tikzpicture}
\end{document}