如果我想使用
\tkzDefPoint(0,0){A}
\tkzDefPoint(3,0){B}
在多个 tkz 图表上,有没有办法将其放在序言中,也许使用'\newcommand'类型的东西,以避免我在同一文档中每个单独的图表中重复使用相同的代码。
\documentclass{book}
\usepackage{etoolbox}
\usepackage{blindtext}
\usepackage{tkz-euclide}
Un
% Proposition environment
\newenvironment{proposition}
{\begin{center}\em}
{\end{center}}
%Diagram environment
\newenvironment{diagram}
{\stepcounter{CountDiag}\vspace*{10pt}
\begin{center}
\begin{tikzpicture}}
{\end{tikzpicture}\vspace*{-5pt}\par Diagram~\theCountDiag
\end{center}}
%Step environment
\newenvironment{step}
{\stepcounter{CountStep}\vspace*{10pt} Step~\theCountStep\par
{\raggedright}}
\newcounter{CountStep}
\newcounter{CountDiag}
%Reset counters
\AtBeginEnvironment{proposition}{\setcounter{CountStep}{0}}
\AtBeginEnvironment{proposition}{\setcounter{CountDiag}{0}}
\begin{document}
\begin{diagram}
\tkzDefPoint(0,0){A}
\tkzDefPoint(1.25,0.3){B}
\tkzDrawSegment(A,B)
\tkzLabelPoint[left](A){$A$}
\tkzLabelPoint[right](B){$B$}
\end{diagram}
\begin{step}
From postulate 2 we can set the compasses to the length of the line $AB$ and setting the point at $A$ and draw a circle, with radius $AB$, then repeat from $B$.
\end{step}
\begin{diagram}
\tkzDefPoint(0,0){A}
\tkzDefPoint(3,0){B}
\tkzDrawSegment(A,B)
\tkzLabelPoint[left](A){$A$}
\tkzLabelPoint[right](B){$B$}
\tkzDrawCircles(A,B B,A)
\end{diagram}
\end{document}
答案1
如果同一文档中有两个图形,则第一个图形中的节点始终在第二个图形中定义。有时这是一个问题。您有几种可能性。您可以将部分代码保存在外部文件或命令中。如果您想保留名称但更改值,则可以使用命令添加参数。
\documentclass{book}
\usepackage{tkz-euclide}
\newcommand{\preamble}[2]{%
\tkzDefPoint(0,0){A}
\tkzDefPoint(#1,#2){B}
\tkzDrawSegment(A,B)
\tkzLabelPoint[left](A){$A$}
\tkzLabelPoint[right](B){$B$}
}
\begin{document}
\begin{tikzpicture}
\preamble{3}{0}
\end{tikzpicture}
\begin{tikzpicture}
\preamble{1.25}{0.3}
\tkzDrawCircles(A,B B,A)
\end{tikzpicture}
\end{document}