考慮這個例子:
\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)$
and$(A)!0.9!(B)$
來指定從路徑開頭 0.4cm 到距離末端 0.4cm 繪製的線(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}