我尝试在轴环境中使用 TkZ 命令 MarkRightAngle,但无法使其工作。我收到“缺少字符:字体 nullfont 中没有 ;!”错误和“第 21 行:包 pgf 错误:没有已知名为 B 的形状。”。一个可能的解决方案是匹配轴和画布比例(但我不知道如何做到这一点)并在轴环境之外添加命令。
\documentclass{article}
\usepackage{mathptmx}
\usepackage{tikz, ifthen}
\usetikzlibrary{arrows,shapes,backgrounds,patterns,decorations.pathreplacing, decorations.pathmorphing,decorations.markings,shadows,shapes.misc,calc,%
positioning,% intersections}
\usepackage{color}
\usepackage{tikzpagenodes}
\usepackage{tkz-euclide}
\usepackage[active,pdftex,tightpage]{preview}
\usepackage{pgfplots}
\usetkzobj{all}
\PreviewEnvironment[]{tikzpicture}
\PreviewEnvironment[]{pgfpicture}
\DeclareSymbolFont{symbolsb}{OMS}{cmsy}{m}{n}
\SetSymbolFont{symbolsb}{bold}{OMS}{cmsy}{b}{n}
\DeclareSymbolFontAlphabet{\mathcal}{symbolsb}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ axis lines =center,
disabledatascaling,
anchor=origin,
xlabel = $x$, ylabel =$y$,
ymax=4, ymin=-8, xmax =8, xmin=-4,
ytick={-6, -4, ...,4},xtick={-4, -2, ...,6},]
\addplot [ color=black, dashed,]
coordinates {(-2,-5) (7,-5)} ;
\addplot [ color=black, dashed,]
coordinates {(7,-5) (7,-2)} node[label=above:{$T(7,-2)$},circle, fill, inner sep=2pt] {};
\addplot [color=black,]
coordinates {(7,-2) (-2,-5)} node[label=below:{$S(-2,-5)$},circle, fill, inner sep=2pt] {};
\tkzDefPoint(7,-2){A};
\tkzDefPoint(-2,5){B};
\tkzDefPoint(7,-5){C};
\tkzMarkRightAngle(A,B,C);
\end{axis}
\end{tikzpicture}
\begin{document}
答案1
tikz
内部图axis
不是一般问题。但是,tkz-euclide
坐标等的设置完全不同。对于标记直角,使用库更容易。我通过在其选项中添加和来calc
命名您感兴趣的两个节点。然后我通过以下方式绘制了直角符号name=A
name=B
\coordinate (X) at (A |- B);
\draw ($(X)!5pt!(A)$) -| ($(X)!5pt!(B)$);
您可以更改5pt
为其他尺寸来获得不同的尺寸标记。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\begin{axis}[axis lines =center,
disabledatascaling,
anchor=origin,
xlabel = $x$, ylabel =$y$,
ymax=4, ymin=-8, xmax=8, xmin=-4,
ytick={-6, -4, ...,4}, xtick={-4, -2, ...,6}]
\addplot [color=black, dashed] coordinates {(-2,-5) (7,-5)} ;
\addplot [ color=black, dashed] coordinates {(7,-5) (7,-2)}
node[label=above:{$T(7,-2)$},circle, fill, inner sep=2pt,name=A] {};
\addplot [color=black] coordinates {(7,-2) (-2,-5)}
node[label=below:{$S(-2,-5)$},circle, fill, inner sep=2pt,name=B]
{};
\coordinate (X) at (A |- B);
\draw ($(X)!5pt!(A)$) -| ($(X)!5pt!(B)$);
\end{axis}
\end{tikzpicture}
\end{document}
答案2
我找到了一个替代解决方案。如果直角不在水平线或垂直线上,上述解决方案就会出现问题。
\documentclass{article}
\usepackage{pgfplots}
\usepackage{tkz-euclide}
\pgfplotsset{compat=1.10}
\usetkzobj{all}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ymax=4, ymin=-8, xmax=8, xmin=-4,
ytick={-6, -4, ...,4}, xtick={-4, -2, ...,6}]
\addplot [dashed] coordinates {(-2,-5) (7,-5)} ;
\addplot [dashed] coordinates {(7,-5) (7,-2)} node[pos=0,name=R]{} node[label={[shift={(0,-0.2)}]{$T(7,-2)$}},,circle,fill,inner sep=1pt,name=T] {};
\addplot coordinates {(7,-2) (-2,-5)} node[pos=1,label={[shift={(-0.5,-1.3)}]{$S(-2,-5)$}}, ,circle,fill,inner sep=1pt,name=S] {};
\coordinate (U) at ($(S)!(T)!(R)$); %using node R distorts the right angle symbol
\end{axis}
\tkzMarkRightAngle(T,U,S)
\end{tikzpicture}
\end{document}