找回密码
 快速注册
搜索
查看: 26|回复: 12

请教clip边界的颜色怎么做?

[复制链接]

413

主题

1558

回帖

1万

积分

积分
11498

显示全部楼层

abababa 发表于 2024-12-13 17:54 |阅读模式
如下代码,我想画的图的边界被填成黑色了,怎么能让边界变成蓝色的呢?
  1. \begin{tikzpicture}[scale=1,label style/.style={font=\scriptsize}]
  2. \clip[draw] (0,3) -- (1,3) -- (1,2) -- (4,2) -- (4,1) -- (5,1) -- (5,0) -- (0,0) -- cycle;
  3. \draw[help lines, color=blue] (0,0) grid (5,3);
  4. \end{tikzpicture}
复制代码

730

主题

1万

回帖

9万

积分

积分
93593
QQ

显示全部楼层

kuing 发表于 2024-12-13 18:34
没想到,\clip[draw=blue] 竟然是不行的……

可以在第一行的中括号里加一个 blue

413

主题

1558

回帖

1万

积分

积分
11498

显示全部楼层

 楼主| abababa 发表于 2024-12-13 19:43
kuing 发表于 2024-12-13 18:34
没想到,\clip[draw=blue] 竟然是不行的……

可以在第一行的中括号里加一个 blue ...

我刚才想了一下,在之前把那个边画出来也行。
  1. \begin{tikzpicture}[scale=0.5,label style/.style={font=\scriptsize}]
  2. \path[save path=\pathA] (0,3) -- (1,3) -- (1,2) -- (4,2) -- (4,1) -- (5,1) -- (5,0) -- (0,0) -- cycle;
  3. \draw[color=blue][use path=\pathA];
  4. \clip[use path=\pathA];
  5. \draw[help lines, color=blue] (0,0) grid (5,3);
  6. \end{tikzpicture}
复制代码

这个clip挺好用的啊,搜索发现还能画集合那种相交的阴影之类的。

点评

嗯这样也挺好,还善用了 save path 👍  发表于 2024-12-13 20:04

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2024-12-13 19:56
kuing 发表于 2024-12-13 10:34
没想到,\clip[draw=blue] 竟然是不行的……

可以在第一行的中括号里加一个 blue ...


There is a slightly annoying catch: You cannot specify certain graphic options for the command used for clipping. For example, in the above code we could not have moved the fill=red to the \fill command. The reasons for this have to do with the internals of the pdf specification. You do not want to know the details. It is best simply not to specify any options for these commands.
tikz.dev/tikz-actions#pgf./tikz/clip

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2024-12-13 20:02
abababa 发表于 2024-12-13 11:43
我刚才想了一下,在之前把那个边画出来也行。


Just use preaction.
\path[preaction={clip},draw=black,postaction={fill=black, draw=white, line width=6mm}]
extra options not allowed for clipping path command

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2024-12-13 20:08
abababa 发表于 2024-12-13 09:54
label style/.style={font=\scriptsize}

label style是什么呢?

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2024-12-13 20:19
abababa 发表于 2024-12-13 11:43
我刚才想了一下,在之前把那个边画出来也行。

确实和顺序有关!
在clip之前把那个边画出来的效果(局部):
Screenshot 2024-12-13 121904.png
在clip之后把那个边画出来的效果(局部):
Screenshot 2024-12-13 121930.png

413

主题

1558

回帖

1万

积分

积分
11498

显示全部楼层

 楼主| abababa 发表于 2024-12-13 20:33
hbghlyj 发表于 2024-12-13 20:08
label style是什么呢?

我现在也不知道这是什么了,这些都是以前我和maven讨论的时候加的一些参数,后来他把这个做到他那个tkz-euclide-gui网页画图里了,我有时需要用原生的tikz画图也把那个打开一下,生成一个空的tikz代码,然后复制这一段进来。

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2024-12-13 20:35
abababa 发表于 2024-12-13 12:33
我现在也不知道这是什么了,这些都是以前我和maven讨论的时候加的一些参数 ...


对比了3种代码:
\node[label=A]at(0,0){};
\scriptsize
\node[label=A]at(0,0){};
[every label/.style={font=\scriptsize}]
\node[label=A]at(0,0){};
[label style/.style={font=\scriptsize}]
\node[label=A]at(0,0){};

发现[label style/.style={font=\scriptsize}]没有作用

413

主题

1558

回帖

1万

积分

积分
11498

显示全部楼层

 楼主| abababa 发表于 2024-12-13 20:59
hbghlyj 发表于 2024-12-13 20:35
对比了3种代码:
\node(0,0){A};

是不是只针对tkz-euclide画出来的图才有这个效果?可能是那里内置的一些配置。

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2024-12-13 21:25
abababa 发表于 2024-12-13 12:59
是不是只针对tkz-euclide画出来的图才有这个效果?可能是那里内置的一些配置。 ...


试了一下,仍然没有效果呢
Screenshot 2024-12-13 134111.png
  1. \documentclass{article}
  2. \usepackage{tkz-euclide}
  3. \begin{document}
  4. \begin{tikzpicture}
  5. \node[label=A]at(0,0){};
  6. \end{tikzpicture}%
  7. \begin{tikzpicture}[label style/.style={font=\scriptsize}]
  8. \node[label=A]at(0,0){};
  9. \end{tikzpicture}
  10. \end{document}
复制代码

413

主题

1558

回帖

1万

积分

积分
11498

显示全部楼层

 楼主| abababa 发表于 2024-12-14 09:03
hbghlyj 发表于 2024-12-13 21:25
试了一下,仍然没有效果呢

你没用tkz-euclide里的命令来做,用了就有区别了:
  1. \begin{tikzpicture}[scale=1,label style/.style={font=\scriptsize}]
  2. \tkzDefPoints{1/1/A,1/2/B}
  3. \tkzLabelPoints[color=blue](A)
  4. \node at (B){$B$};
  5. \end{tikzpicture}
复制代码

手机版|悠闲数学娱乐论坛(第3版)

GMT+8, 2025-3-4 06:55

Powered by Discuz!

× 快速回复 返回顶部 返回列表