考虑这个例子:
\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate (A) at (0,0);
\coordinate (B) at (1, 3);
\draw [fill=blue] (A) circle (0.1);
\draw [fill=blue] (B) circle (0.1);
\draw ($(A)!0.1!(B)$) -- ($(A)!0.9!(B)$);
\end{tikzpicture}
\end{document}
输出看起来不错:
但是,我不想使用$(A)!0.1!(B)$
,而是$(A)!0.9!(B)$
想指定从路径的起点 0.4 厘米到终点 0.4 厘米处绘制一条线(A) -- (B)
。该怎么做?
答案1
要缩短路径的距离,您甚至不需要calc
。您只需使用shorten
键即可。
\draw[shorten >=0.4cm,shorten <=0.4cm] (A) -- (B);
例子:
\documentclass[border=1cm]{standalone}
\usepackage{tikz}
%\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate (A) at (0,0);
\coordinate (B) at (1, 3);
\draw [fill=blue] (A) circle (0.1);
\draw [fill=blue] (B) circle (0.1);
%\draw ($(A)!0.1!(B)$) -- ($(A)!0.9!(B)$);
\draw[shorten >=0.4cm,shorten <=0.4cm] (A) -- (B);
\end{tikzpicture}
\end{document}