如何“延长” TikZ 路径

如何“延长” TikZ 路径

我需要延长路径,而不是缩短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}

在此处输入图片描述

相关内容