我正在排版一个三角形tkz-euclide,尝试尽可能地自动化该过程,并注意到在使用\tkzCalcLength
和\tkzGetLength
AND不同值时存在一些计算错误,因为\tkzInit[xmin=_,xmax=_,ymin=_,ymax=_]
如果我仅显示问题会更容易:
\documentclass[letterpaper,12pt]{book}
\usepackage{tkz-euclide}
\usetikzlibrary{shapes,backgrounds,calc,arrows.meta,fit,positioning,intersections}
\usetkzobj{all}
\tikzset{ptgrs/.style={thick,transform shape,scale=\tikzscale}}
\usepackage{environ}
\makeatletter
\newsavebox{\measure@tikzpicture}
\NewEnviron{scaletikzpicturetowidth}[1]{%
\def\tikz@width{#1}%
\def\tikzscale{1}\begin{lrbox}{\measure@tikzpicture}%
\BODY
\end{lrbox}%
\pgfmathparse{#1/\wd\measure@tikzpicture}%
\edef\tikzscale{\pgfmathresult}%
\BODY
}
\makeatother
\begin{document}
\begin{center}\begin{scaletikzpicturetowidth}{0.66\textwidth}\begin{tikzpicture}[ptgrs]
\tkzInit[xmin=-0.5,xmax=35,ymin=-2,ymax=15] \tkzClip %\tkzGrid
\def\AX{12}
\def\angXAC{25.5}
\def\angBXC{38.25}
\tkzDefPoint(0,0){A}
\tkzDefPoint(\AX,0){X}
\path[name path=b] (A) -- (\angXAC:40cm);
\path[name path=l] (A) -- (X) --+ (\angBXC:30cm);
\draw [name intersections={of=b and l, by={F,C}}];
\coordinate (B) at ($(A)!(C)!(X)$);
\tkzDrawPolygon(A,B,C)
\draw (C) -- (X);
%\tkzMarkAngle[size=2.7,](X,A,C)
% \tkzLabelAngle[pos=2,transform shape=false](X,A,C){$\alpha$}
%\tkzMarkAngle[size=6,](A,C,X)
% \tkzLabelAngle[pos=5,transform shape=false](A,C,X){$\beta$}
%\tkzMarkAngle[size=1.4,](C,X,A)
% \tkzLabelAngle[pos=0.8,transform shape=false](C,X,A){$\delta$}
%\tkzMarkAngle[size=2.7,](B,X,C)
% \tkzLabelAngle[pos=2,transform shape=false](B,X,C){$\gamma$}
%\tkzMarkRightAngle[size=1](C,B,X)
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](X)--(A)
node [midway,yshift=-12pt] {$\AX$};
\tkzCalcLength[cm](B,C)\tkzGetLength{BC} \FPround\BC\BC{3}
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](C)--(B)
node [midway,xshift=32pt] {$\BC$};
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](B)--(X)
node [midway,yshift=-12pt] {$A$};
\draw[blue](current bounding box.south west)rectangle(current bounding box.north east);
\end{tikzpicture}\end{scaletikzpicturetowidth}\end{center}
\begin{center}\begin{scaletikzpicturetowidth}{0.66\textwidth}\begin{tikzpicture}[ptgrs]
\tkzInit[xmin=-0.5,xmax=40,ymin=-2,ymax=15] \tkzClip %\tkzGrid
\def\AX{12}
\def\angXAC{25.5}
\def\angBXC{38.25}
\tkzDefPoint(0,0){A}
\tkzDefPoint(\AX,0){X}
\path[name path=b] (A) -- (\angXAC:40cm);
\path[name path=l] (A) -- (X) --+ (\angBXC:30cm);
\draw [name intersections={of=b and l, by={F,C}}];
\coordinate (B) at ($(A)!(C)!(X)$);
\tkzDrawPolygon(A,B,C)
\draw (C) -- (X);
%\tkzMarkAngle[size=2.7,](X,A,C)
% \tkzLabelAngle[pos=2,transform shape=false](X,A,C){$\alpha$}
%\tkzMarkAngle[size=6,](A,C,X)
% \tkzLabelAngle[pos=5,transform shape=false](A,C,X){$\beta$}
%\tkzMarkAngle[size=1.4,](C,X,A)
% \tkzLabelAngle[pos=0.8,transform shape=false](C,X,A){$\delta$}
%\tkzMarkAngle[size=2.7,](B,X,C)
% \tkzLabelAngle[pos=2,transform shape=false](B,X,C){$\gamma$}
%\tkzMarkRightAngle[size=1](C,B,X)
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](X)--(A)
node [midway,yshift=-12pt] {$\AX$};
\tkzCalcLength[cm](B,C)\tkzGetLength{BC} \FPround\BC\BC{3}
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](C)--(B)
node [midway,xshift=32pt] {$\BC$};
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](B)--(X)
node [midway,yshift=-12pt] {$A$};
\draw[blue](current bounding box.south west)rectangle(current bounding box.north east);
\end{tikzpicture}\end{scaletikzpicturetowidth}\end{center}
\begin{center}\begin{scaletikzpicturetowidth}{0.66\textwidth}\begin{tikzpicture}[ptgrs]
\tkzInit[xmin=-0.5,xmax=45,ymin=-2,ymax=15] \tkzClip %\tkzGrid
\def\AX{12}
\def\angXAC{25.5}
\def\angBXC{38.25}
\tkzDefPoint(0,0){A}
\tkzDefPoint(\AX,0){X}
\path[name path=b] (A) -- (\angXAC:40cm);
\path[name path=l] (A) -- (X) --+ (\angBXC:30cm);
\draw [name intersections={of=b and l, by={F,C}}];
\coordinate (B) at ($(A)!(C)!(X)$);
\tkzDrawPolygon(A,B,C)
\draw (C) -- (X);
%\tkzMarkAngle[size=2.7,](X,A,C)
% \tkzLabelAngle[pos=2,transform shape=false](X,A,C){$\alpha$}
%\tkzMarkAngle[size=6,](A,C,X)
% \tkzLabelAngle[pos=5,transform shape=false](A,C,X){$\beta$}
%\tkzMarkAngle[size=1.4,](C,X,A)
% \tkzLabelAngle[pos=0.8,transform shape=false](C,X,A){$\delta$}
%\tkzMarkAngle[size=2.7,](B,X,C)
% \tkzLabelAngle[pos=2,transform shape=false](B,X,C){$\gamma$}
%\tkzMarkRightAngle[size=1](C,B,X)
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](X)--(A)
node [midway,yshift=-12pt] {$\AX$};
\tkzCalcLength[cm](B,C)\tkzGetLength{BC} \FPround\BC\BC{3}
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](C)--(B)
node [midway,xshift=32pt] {$\BC$};
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](B)--(X)
node [midway,yshift=-12pt] {$A$};
\draw[blue](current bounding box.south west)rectangle(current bounding box.north east);
\end{tikzpicture}\end{scaletikzpicturetowidth}\end{center}
\begin{center}\begin{scaletikzpicturetowidth}{0.66\textwidth}\begin{tikzpicture}[ptgrs]
\tkzInit[xmin=-0.5,xmax=50,ymin=-2,ymax=15] \tkzClip %\tkzGrid
\def\AX{12}
\def\angXAC{25.5}
\def\angBXC{38.25}
\tkzDefPoint(0,0){A}
\tkzDefPoint(\AX,0){X}
\path[name path=b] (A) -- (\angXAC:40cm);
\path[name path=l] (A) -- (X) --+ (\angBXC:30cm);
\draw [name intersections={of=b and l, by={F,C}}];
\coordinate (B) at ($(A)!(C)!(X)$);
\tkzDrawPolygon(A,B,C)
\draw (C) -- (X);
%\tkzMarkAngle[size=2.7,](X,A,C)
% \tkzLabelAngle[pos=2,transform shape=false](X,A,C){$\alpha$}
%\tkzMarkAngle[size=6,](A,C,X)
% \tkzLabelAngle[pos=5,transform shape=false](A,C,X){$\beta$}
%\tkzMarkAngle[size=1.4,](C,X,A)
% \tkzLabelAngle[pos=0.8,transform shape=false](C,X,A){$\delta$}
%\tkzMarkAngle[size=2.7,](B,X,C)
% \tkzLabelAngle[pos=2,transform shape=false](B,X,C){$\gamma$}
%\tkzMarkRightAngle[size=1](C,B,X)
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](X)--(A)
node [midway,yshift=-12pt] {$\AX$};
\tkzCalcLength[cm](B,C)\tkzGetLength{BC} \FPround\BC\BC{3}
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](C)--(B)
node [midway,xshift=32pt] {$\BC$};
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](B)--(X)
node [midway,yshift=-12pt] {$A$};
\draw[blue](current bounding box.south west)rectangle(current bounding box.north east);
\end{tikzpicture}\end{scaletikzpicturetowidth}\end{center}
\begin{center}\begin{scaletikzpicturetowidth}{0.66\textwidth}\begin{tikzpicture}[ptgrs]
\tkzInit[xmin=-0.5,xmax=55,ymin=-2,ymax=15] \tkzClip %\tkzGrid
\def\AX{12}
\def\angXAC{25.5}
\def\angBXC{38.25}
\tkzDefPoint(0,0){A}
\tkzDefPoint(\AX,0){X}
\path[name path=b] (A) -- (\angXAC:40cm);
\path[name path=l] (A) -- (X) --+ (\angBXC:30cm);
\draw [name intersections={of=b and l, by={F,C}}];
\coordinate (B) at ($(A)!(C)!(X)$);
\tkzDrawPolygon(A,B,C)
\draw (C) -- (X);
%\tkzMarkAngle[size=2.7,](X,A,C)
% \tkzLabelAngle[pos=2,transform shape=false](X,A,C){$\alpha$}
%\tkzMarkAngle[size=6,](A,C,X)
% \tkzLabelAngle[pos=5,transform shape=false](A,C,X){$\beta$}
%\tkzMarkAngle[size=1.4,](C,X,A)
% \tkzLabelAngle[pos=0.8,transform shape=false](C,X,A){$\delta$}
%\tkzMarkAngle[size=2.7,](B,X,C)
% \tkzLabelAngle[pos=2,transform shape=false](B,X,C){$\gamma$}
%\tkzMarkRightAngle[size=1](C,B,X)
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](X)--(A)
node [midway,yshift=-12pt] {$\AX$};
\tkzCalcLength[cm](B,C)\tkzGetLength{BC} \FPround\BC\BC{3}
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](C)--(B)
node [midway,xshift=32pt] {$\BC$};
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](B)--(X)
node [midway,yshift=-12pt] {$A$};
\draw[blue](current bounding box.south west)rectangle(current bounding box.north east);
\end{tikzpicture}\end{scaletikzpicturetowidth}\end{center}
\end{document}
输出如下:
如果我使用例如\FPround\BC\BC{4}
或如果我使用具有几何形状的不同边距,不精确度会变得更糟或有所不同。
要明确的是,我不认为这是一个可怕的错误,即使它是一个错误,因为正如你所看到的,代码中有很多东西,但我想知道是什么原因导致了这种情况,以及是否有办法获得更准确的长度。
答案1
我有一个更精确的答案,但还不完全令人满意。首先,问题不在于宏,\tkzCalcLength[cm](B,C)
而在于scale
选项
如果你删除,tkzClip
你会得到相同的结果
然后就像我的问题/答案一样同样的问题如果你改变
{0.66\textwidth}
和{0.5\textwidth}
。
现在的问题是找到一些计算和选项之间的联系scale
\documentclass{article}
\usepackage{tkz-euclide}
\usepackage{environ}
\makeatletter
\newsavebox{\measure@tikzpicture}
\NewEnviron{scaletikzpicturetowidth}[1]{%
\def\tikz@width{#1}%
\def\tikzscale{1}%
\begin{lrbox}{\measure@tikzpicture}%
\BODY
\end{lrbox}%
\pgfmathparse{#1/\wd\measure@tikzpicture}%
\edef\tikzscale{\pgfmathresult}%
\BODY
}
\makeatother
\tikzset{ptgrs/.style={thick,scale=\tikzscale}}
\begin{document}
\begin{center}
\begin{scaletikzpicturetowidth}{0.75\textwidth}
\begin{tikzpicture}[ptgrs]
\tkzInit[xmin=-1,xmax=35,ymin=-2,ymax=15]% \tkzClip
\def\AX{12}
\def\angXAC{25.5}
\def\angBXC{38.25}
\tkzDefPoint(0,0){A}
\tkzDefPoint(\AX,0){X}
\path[name path=b] (A) -- (\angXAC:40cm);
\path[name path=l] (A) -- (X) --+ (\angBXC:30cm);
\draw [name intersections={of=b and l, by={F,C}}];
\coordinate (B) at ($(A)!(C)!(X)$);
\tkzDrawPolygon(A,B,C)
\draw (C) -- (X);
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](X)--(A)
node [midway,yshift=-12pt] {$\AX$};
\tkzCalcLength[cm](B,C)\tkzGetLength{BC} \FPround\BC\BC{3}
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](C)--(B)
node [midway,xshift=32pt] {$\BC$};
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](B)--(X)
node [midway,yshift=-12pt] {$A$};
\draw[blue](current bounding box.south west)rectangle(current bounding box.north east);
\end{tikzpicture}
\end{scaletikzpicturetowidth}
\end{center}
\begin{center}
\begin{scaletikzpicturetowidth}{0.75\textwidth}
\begin{tikzpicture}[ptgrs]
\tkzInit[xmin=-1,xmax=40,ymin=-2,ymax=15] \tkzClip
\def\AX{12}
\def\angXAC{25.5}
\def\angBXC{38.25}
\tkzDefPoint(0,0){A}
\tkzDefPoint(\AX,0){X}
\path[name path=b] (A) -- (\angXAC:40cm);
\path[name path=l] (A) -- (X) --+ (\angBXC:30cm);
\draw [name intersections={of=b and l, by={F,C}}];
\coordinate (B) at ($(A)!(C)!(X)$);
\tkzDrawPolygon(A,B,C)
\draw (C) -- (X);
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](X)--(A)
node [midway,yshift=-12pt] {$\AX$};
\tkzCalcLength[cm](B,C)\tkzGetLength{BC} \FPround\BC\BC{3}
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](C)--(B)
node [midway,xshift=32pt] {$\BC$};
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](B)--(X)
node [midway,yshift=-12pt] {$A$};
\draw[blue](current bounding box.south west)rectangle(current bounding box.north east);
\end{tikzpicture}
\end{scaletikzpicturetowidth}
\end{center}
\begin{center}
\begin{scaletikzpicturetowidth}{0.75\textwidth}
\begin{tikzpicture}[ptgrs]
\def\AX{12}
\def\angXAC{25.5}
\def\angBXC{38.25}
\tkzDefPoint(0,0){A}
\tkzDefPoint(\AX,0){X}
\path[name path=b] (A) -- (\angXAC:40cm);
\path[name path=l] (A) -- (X) --+ (\angBXC:30cm);
\draw [name intersections={of=b and l, by={F,C}}];
\coordinate (B) at ($(A)!(C)!(X)$);
\tkzDrawPolygon(A,B,C)
\draw (C) -- (X);
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](X)--(A)
node [midway,yshift=-12pt] {$\AX$};
\tkzCalcLength[cm](B,C)\tkzGetLength{BC} \FPround\BC\BC{3}
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](C)--(B)
node [midway,xshift=32pt] {$\BC$};
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](B)--(X)
node [midway,yshift=-12pt] {$A$};
\draw[blue](current bounding box.south west)rectangle(current bounding box.north east);
\end{tikzpicture}
\end{scaletikzpicturetowidth}
\end{center}
\end{document}
我把\tkzClip
第一张图和最后一张图的 去掉了,所以图片的宽度是一样的,但是 和\tkzClip
不一样scale
,需要一步一步验证 有/无 的不同坐标scale
。