50 tkz-euclide宏包中设置全局样式的神秘边界问题?

发布于 2025-10-03 00:03:59

@u10189 这个问题来自这个链接的评论区

image.png

问题的解释(似乎)在texdoc tkz-euclide中的「Part VIII. Working with style」

tkz...使用的所有的样式调用的是储存在point style/line style/vector style等pre-difined的样式中,因此直接修改tiikzpicture的全局样式并不会影响这些被tkz...调用的样式,所以下面的代码中第二个图会失效。

\documentclass[border=3pt]{standalone}
\usepackage{tkz-euclide}
\begin{document}

\begin{tikzpicture}
    \tkzDefPoints{0/0/A,1/1/B}
    \tkzDrawSegments[thick](A,B)
\end{tikzpicture}

\begin{tikzpicture}[thick]
    \tkzDefPoints{0/0/A,1/1/B}
    \tkzDrawSegments(A,B)
\end{tikzpicture}

\begin{tikzpicture}[line style/.append style={line width=1pt}]
    \tkzDefPoints{0/0/A,1/1/B}
    \tkzDrawSegments(A,B)
\end{tikzpicture}

% \tkzSetUpLine[line width=1pt]
\begin{tikzpicture}
    \tkzDefPoints{0/0/A,1/1/B}
    \tkzDrawSegments(A,B)
\end{tikzpicture}

\end{document}

可以使用line style/.append style={line width=1pt}来做合并式修改

image.png

顺便回答了评论里的问题,下面才是本问题的关键:

texdoc tkz-euclide的文档中的sec 40.1. Use of \tkzSetUpLine介绍了:

% \tkzSetUpLine[line width=1pt]

如下的另一份代码:

\documentclass[border=3pt]{standalone}
\usepackage{tkz-euclide}
\begin{document}

\begin{tikzpicture}
    \tkzDefPoints{0/0/A,1/1/B}
    \tkzDrawSegments[thick](A,B)
\end{tikzpicture}

\begin{tikzpicture}[thick]
    \tkzDefPoints{0/0/A,1/1/B}
    \tkzDrawSegments(A,B)
\end{tikzpicture}

\begin{tikzpicture}[line style/.append style={line width=1pt}]
    \tkzDefPoints{0/0/A,1/1/B}
    \tkzDrawSegments(A,B)
\end{tikzpicture}

\tkzSetUpLine[line width=1pt]
\begin{tikzpicture}
    \tkzDefPoints{0/0/A,1/1/B}
    \tkzDrawSegments(A,B)
\end{tikzpicture}

\end{document}

将会得到一个向右平移的神必bounding box...

image.png

为什么设置了\tkzSetUpLine[line width=1pt]会导致这一偏移呢?

Edit

如果我显式添加tikz选项给standalone或者使用multi={tikzpicture},则不会有此问题:

\documentclass[
    border=3pt,
    % tikz,
    multi={tikzpicture}
    ]{standalone}
\usepackage{tkz-euclide}
\begin{document}

\begin{tikzpicture}
    \tkzDefPoints{0/0/A,1/1/B}
    \tkzDrawSegments[thick](A,B)
\end{tikzpicture}

\begin{tikzpicture}[thick]
    \tkzDefPoints{0/0/A,1/1/B}
    \tkzDrawSegments(A,B)
\end{tikzpicture}

\begin{tikzpicture}[line style/.append style={line width=1pt}]
    \tkzDefPoints{0/0/A,1/1/B}
    \tkzDrawSegments(A,B)
\end{tikzpicture}

\tkzSetUpLine[line width=1pt]
\begin{tikzpicture}
    \tkzDefPoints{0/0/A,1/1/B}
    \tkzDrawSegments(A,B)
\end{tikzpicture}

\end{document}

image.png

查看更多

关注者
0
被浏览
40
1 个回答
越来越少
越来越少 9小时前
这家伙很懒,什么也没写!

可能需要看一下 \tkzSetUpLine 的定义, 当命令结束并且换行时, 应当添加注释符号, 否则可能产生空格, 这应该是 TeX 的特性. 也需要查看主命令内部所调用的命令的定义代码是否出现这种情况, 当出现多层次调用时, 需要检查的代码就多了.

\documentclass[border=3pt]{standalone}
\usepackage{tkz-euclide}
\begin{document}
\makeatletter
\def\tkzSetUpLine{\pgfutil@ifnextchar[{\tkz@SetUpLine}{\tkz@SetUpLine[]}}
\def\tkz@SetUpLine[#1]{%
\pgfkeys{%
      tkzsuline/.cd,
      line width   = \tkz@euc@linewidth,
      color        = \tkz@euc@linecolor,
      style        = \tkz@euc@linestyle,
%      add          = {\tkz@euc@lineleft} and {\tkz@euc@lineright},
}%
\pgfqkeys{/tkzsuline}{#1}%
\tikzset{%
        line style/.append style ={%
        line width        = \tkz@line@width,
        color             = \tkz@line@color,
        style             = \tkz@line@style,
%        add               = {\tkz@line@left} and {\tkz@line@right},
        line cap          = round,
        #1}
        }%
}%

\begin{tikzpicture}
    \tkzDefPoints{0/0/A,1/1/B}
    \tkzDrawSegments[thick](A,B)
\end{tikzpicture}

\begin{tikzpicture}[thick]
    \tkzDefPoints{0/0/A,1/1/B}
    \tkzDrawSegments(A,B)
\end{tikzpicture}

\begin{tikzpicture}[line style/.append style={line width=1pt}]
    \tkzDefPoints{0/0/A,1/1/B}
    \tkzDrawSegments(A,B)
\end{tikzpicture}

\tkzSetUpLine[line width=1pt]%
\tkzSetUpLine[line width=1pt]%
\tkzSetUpLine[line width=1pt]%
\begin{tikzpicture}
    \tkzDefPoints{0/0/A,1/1/B}
    \tkzDrawSegments(A,B)
\end{tikzpicture}

\end{document}

a9009ba518ecb6424dcdf03abda9ef5a.png

tikzpicure 环境内部, 文本字符被设置为 \nullfont, 一般没有这个问题.

tkz-euclide 包的主要优势在于提供了一些计算工具, 不在于设置样式. 我倾向于只用这个包做计算.

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览