![如何“延长” TikZ 路径](https://linux22.com/image/269234/%E5%A6%82%E4%BD%95%E2%80%9C%E5%BB%B6%E9%95%BF%E2%80%9D%20TikZ%20%E8%B7%AF%E5%BE%84.png)
我需要延长路径,而不是缩短TikZ
路径。但我找不到lengthen
关键点。
\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\makeatletter
\newcommand*\xtikzpath[3]%
{%
(#1\LP@rel@tikzpath,#2\LP@rel@tikzpath)%
\foreach \LP@dir/\LP@length in {#3}%
{%
\ifnum\LP@dir=2%
--++(0,-\LP@length)%
\fi%
\ifnum\LP@dir=4%
--++(-\LP@length,0)%
\fi%
\ifnum\LP@dir=6%
--++(\LP@length,0)%
\fi%
\ifnum\LP@dir=8%
--++(0,\LP@length)%
\fi%
};%
}%
%
\newcommand*\fourwindscell[4]%
{%
\foreach \LP@fw@dir/\LP@fw@length in {#4}%
{%
\bgroup%
\def\LP@rel@tikzpath{.5}%
\draw[-|,color=blue,line width=.1cm
%,lengthen >=3mm
]%
\xtikzpath{#1}{#2}{\LP@fw@dir/\LP@fw@length};%
\egroup%
};%
\node[fill=white,font=\LARGE] at (#1.5,#2.5) {#3};%
}%
\makeatother
\begin{document}
\begin{tikzpicture}
\fourwindscell{1}{1}{5}{8/2,6/3}
\fourwindscell{3}{2}{2}{4/1,6/1}
\fourwindscell{4}{3}{2}{4/2}
\draw (1,1) grid[step=1] (5,4);
\end{tikzpicture}
\end{document}
有没有办法可以延长路径?
答案1
尽管没有记录,但可以使用shorten
具有负值的键来指定lengthen
路径!
只需添加shorten >=-3mm
到原始 MWE 即可获得所需结果!
\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\makeatletter
\newcommand*\xtikzpath[3]%
{%
(#1\LP@rel@tikzpath,#2\LP@rel@tikzpath)%
\foreach \LP@dir/\LP@length in {#3}%
{%
\ifnum\LP@dir=2%
--++(0,-\LP@length)%
\fi%
\ifnum\LP@dir=4%
--++(-\LP@length,0)%
\fi%
\ifnum\LP@dir=6%
--++(\LP@length,0)%
\fi%
\ifnum\LP@dir=8%
--++(0,\LP@length)%
\fi%
};%
}%
%
\newcommand*\fourwindscell[4]%
{%
\foreach \LP@fw@dir/\LP@fw@length in {#4}%
{%
\bgroup%
\def\LP@rel@tikzpath{.5}%
\draw[-|,color=blue,line width=.1cm,shorten >=-3mm]%
\xtikzpath{#1}{#2}{\LP@fw@dir/\LP@fw@length};%
\egroup%
};%
\node[fill=white,font=\LARGE] at (#1.5,#2.5) {#3};%
}%
\makeatother
\begin{document}
\begin{tikzpicture}
\fourwindscell{1}{1}{5}{8/2,6/3}
\fourwindscell{3}{2}{2}{4/1,6/1}
\fourwindscell{4}{3}{2}{4/2}
\draw (1,1) grid[step=1] (5,4);
\end{tikzpicture}
\end{document}