我遇到了模型“squaroid”的编译错误。我检查了代码好几次,但仍然找不到问题所在,这让我开始抓狂。我猜是某个地方缺少了一个标点符号。
相比之下,“三角形”模型运行正常。
%%%%%%%%%%%%%%%%%% INTRODUCTION %%%%%%%%%%%%%%%%%%
\documentclass[border=10pt]{standalone}
%%%%%%%%%%%%%%%%%% PACKAGE %%%%%%%%%%%%%%%%%%
\usepackage{tikz, tkz-euclide}% permet de dessiner des figures, des graphiques
%% FONT
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tgadventor}% paquet de police de caractère TGadventor
\usepackage{sansmath}% Copie-colle la police active dans
% \sfdefault (/!\ N'EST PAS UNE POLICE DE CARACTÈRES)
\usepackage{xcolor}
%%%%%%%%%%%%%%%%%% INPUT %%%%%%%%%%%%%%%%%%
%\input{preamble.tex}
%\input{parameters.tex}
%\input{types/f2d_fig}
%%%%%%%%%%%%%%%%%% SETUP %%%%%%%%%%%%%%%%%%
\tikzset{fig2D/.style={font={\sansmath\sffamily\Large}, line width=0.4mm, line cap=round, line join=round, >=latex, x=1.0cm, y=1.0cm,}}
%%%%%%%%%%%%%%%%%%%%%%%% SQUAROID %%%%%%%%%%%%%%%%%%%%%%%%
\tikzset{pics/squaroid/.style={%
code={%
\tikzset{squaroid/.cd,#1}%
\def\pv##1{%
\pgfkeysvalueof{/tikz/squaroid/##1}
}
\draw [solid, pic actions]
% point o - bas gauche
(0,0) coordinate (o)
node [inner sep=6pt, label={[\pv{poso}, inner sep=\pv{inner sep},]\pv{labo}}] {}
% point a - bas droite
(\pv{scale}*\pv{width},0) coordinate (a)
node [inner sep=6pt, label={[\pv{posa}, inner sep=\pv{inner sep},]\pv{laba}}] {}
% point b - haut droite
(\pv{scale}*\pv{width},\pv{scale}*\pv{height}) coordinate (b)
node [inner sep=6pt, label={[\pv{posb}, inner sep=\pv{inner sep},]\pv{labb}}] {}
% point c - haut gauche
(0,\pv{scale}*\pv{height}) coordinate (c)
node [inner sep=6pt, label={[\pv{posc}, inner sep=\pv{inner sep},]\pv{labc}}] {}
% connexion entre les points
(o)
-- (a) node [midway, label={[\pv{posA}, inner sep = \pv{inner sep},]\pv{labA}}] {}
-- (b) node [midway, label={[\pv{posB}, inner sep = \pv{inner sep},]\pv{labB}}] {}
-- (c) node [midway, label={[\pv{posC}, inner sep = \pv{inner sep},]\pv{labC}}] {}
-- (o) node [midway, label={[\pv{posD}, inner sep = \pv{inner sep},]\pv{labD}}] {}
;
}},
squaroid/.cd,
width/.initial=3,
height/.initial=2,
scale/.initial=1,
labA/.initial=,
labB/.initial=,
labC/.initial=,
labD/.initial=,
labo/.initial=,
laba/.initial=,
labb/.initial=,
labc/.initial=,
posA/.initial=below,
posB/.initial=right,
posC/.initial=above,
posD/.initial=left,
poso/.initial=below,
posa/.initial=below,
posb/.initial=above,
posc/.initial=above,
inner sep/.initial=6pt,
}
%%%%%%%%%%%%%%%%%%%%%%%% TRIANGLOID %%%%%%%%%%%%%%%%%%%%%%%%
\tikzset{pics/triangloid/.style={code={%
\tikzset{triangloid/.cd,#1}%
\def\pv##1{\pgfkeysvalueof{/tikz/triangloid/##1}}
\draw [solid, pic actions, fill=\pv{fill}]
%% point o - bas gauche
(0,0) coordinate (o)
node [inner sep=6pt, label={[\pv{poso}, inner sep=\pv{inner sep},]\pv{labo}}] {}
%% point a - bas droite
(\pv{scale}*\pv{width},0) coordinate (a)
node [inner sep=6pt, label={[\pv{posa}, inner sep=\pv{inner sep},]\pv{laba}}] {}
%% point b - sommet
({\pv{scale}*\pv{offset})},\pv{scale}*\pv{height}) coordinate (b)
node [inner sep=6pt, label={[\pv{posb}, inner sep=\pv{inner sep},]\pv{labb}}] {}
%% jonction entre les points
(o)
-- (a) node [midway, label={[\pv{posA}, inner sep=\pv{inner sep},shift={(0pt,-6pt)}]\pv{labA}}] {}
-- (b) node [midway, label={[\pv{posB}, inner sep=\pv{inner sep},]\pv{labB}}] {}
-- (o) node [midway, label={[\pv{posC}, inner sep=\pv{inner sep},shift={(-2pt,0pt)}]\pv{labC}}] {}
;
}},
triangloid/.cd,
width/.initial=5,
height/.initial=2,
offset/.initial=0,
labA/.initial=,
labB/.initial=,
labC/.initial=,
labo/.initial=,
laba/.initial=,
labb/.initial=,
posA/.initial=below,
posB/.initial=above right,
posC/.initial=left,
poso/.initial=below,
posa/.initial=below,
posb/.initial=above,
inner sep/.initial=0pt,
fill/.initial=black!0,
scale/.initial=1,
}
%%%%%%%%%%%%%%%%%% DOCUMENT %%%%%%%%%%%%%%%%%%
\begin{document}
\begin{tikzpicture}[fig2D, rotate=0, scale=1.5]
%%% rectangle
\begin{scope}
\pic{squaroid={width=4, height=3, labo=N, laba=M, labb=P, labc=X, labC=4 cm, labD=3 cm, posD=right, scale=1.5}};
\draw[]
(o) -- (b)
;
\end{scope}
%%% Triangle
\pic[rotate=90] {triangloid={width=3, height=1, offset=3, labb=O, posb=above, labC=$\sqrt{10}$ cm, scale=1.5}};
\pic[rotate=-90] at (4,3) {triangloid={width=3, height=2.517, labb=Z, posb=above, scale=1.5}};
\end{tikzpicture}
\end{document}
答案1
如果你仔细查看错误消息,你会看到它说
I do not know the key '/tikz/below '
表示它正在寻找一个名为 的键below<space>
。换句话说,你在某处有一个虚假的空格。在本例中,它是由 定义中的换行符引起的\pv
:
\def\pv##1{%
\pgfkeysvalueof{/tikz/squaroid/##1}
}
右括号前的换行符会添加一个空格,因此将此定义更改为
\def\pv##1{%
\pgfkeysvalueof{/tikz/squaroid/##1}% <-- add % here
}
或者
\def\pv##1{\pgfkeysvalueof{/tikz/squaroid/##1}}