在以下 MWE 中,阴影区域缩放不正确。问题似乎涉及交叉点计算。这里的问题是什么?
以下是未缩放的 MWE:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
% axes
\draw[->,name path=yaxis] (0,0) -- (0,1.2);
\draw[->,name path=xaxis] (0,0) -- (1.2,0);
\coordinate (origin) at (0,0);
% diagonal
\draw[name path=diag] (0,1) -- (1,0);
% intersection points
\node[coordinate, name intersections={of=diag and yaxis}] (diagy) at (intersection-1) {};
\node[coordinate, name intersections={of=diag and xaxis}] (diagx) at (intersection-1) {};
% fill
\fill[opacity=0.1] (origin) -- (diagy) -- (diagx);
\end{tikzpicture}
\end{document}
正确的数字,同样没有缩放:
现在如果我改变
\begin{tikzpicture}
到
\begin{tikzpicture}[scale=0.8]
我得到以下信息:
如果我更换
\node[coordinate, name intersections={of=diag and yaxis}] (diagy) at (intersection-1) {};
\node[coordinate, name intersections={of=diag and xaxis}] (diagx) at (intersection-1) {};
和
\node[coordinate] (diagy) at (0,5) {};
\node[coordinate] (diagx) at (5,0) {};
该图形的比例正确,这就是为什么我认为交叉点计算是导致问题的原因。
谢谢!
答案1
使用
% intersection points
\path[name intersections={of=diag and yaxis,by={A}}];
\path[name intersections={of=diag and xaxis,by={B}}];
定义交叉口然后
% fill
\fill[opacity=0.1] (origin) -- (A) -- (B);
以下是完整代码
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}[scale=0.8]
% axes
\draw[->,name path global=yaxis] (0,0) -- (0,1.2);
\draw[->,name path global=xaxis] (0,0) -- (1.2,0);
\coordinate (origin) at (0,0);
% diagonal
\draw[name path global=diag] (0,1) -- (1,0);
% intersection points
\path[name intersections={of=diag and yaxis,by={A}}];
\path[name intersections={of=diag and xaxis,by={B}}];
% fill
\fill[opacity=0.1] (origin) -- (A) -- (B);
\end{tikzpicture}
\end{document}
答案2
正如这里已经解释的那样https://tex.stackexchange.com/a/218292/9335,在与交叉点和变换一起使用时可能存在一个错误node at
(变换似乎在交叉点上应用了两次)。
您只需将其替换\node at (point)
为\path (point) node
即可。这是更正后的代码。
\documentclass[tikz, border=10]{standalone}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}[scale=2]
% axes
\draw[->,name path=yaxis] (0,0) -- (0,1.2);
\draw[->,name path=xaxis] (0,0) -- (1.2,0);
\coordinate (origin) at (0,0);
% diagonal
\draw[name path=diag] (0,1) -- (1,0);
% intersection points
\path[coordinate, name intersections={of=diag and yaxis}] (intersection-1) node (diagy) {};
\path[coordinate, name intersections={of=diag and xaxis}] (intersection-1) node (diagx) {};
% fill
\fill[opacity=0.1] (origin) -- (diagy) -- (diagx);
\end{tikzpicture}
\end{document}