在两个块之间上下移动箭头

在两个块之间上下移动箭头

我需要将两个块之间的箭头向上或向下移动。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,fit,arrows}
\usepackage{graphicx}
\begin{document}

\noindent\resizebox{\textwidth}{!}{
\begin{tikzpicture}[auto,node distance=5cm,>=stealth']
\tikzset{
block/.style= {draw, rectangle, minimum height=2em,minimum width=4em},
sum/.style = {draw, circle, node distance=2cm},
input/.style  = {coordinate},  
output/.style = {coordinate}}

\node [block] (A) {};
\node [block, right of=A] (B) {};
\draw [->] (A) -- node {} (B);

\end{tikzpicture}
}
\end{document}

在此处输入图片描述

答案1

箭头可以通过画布变换来移动:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,fit,arrows}
\usepackage{graphicx}
\begin{document}

\noindent\resizebox{\textwidth}{!}{%
\begin{tikzpicture}[auto,node distance=5cm,>=stealth']
\tikzset{
block/.style= {draw, rectangle, minimum height=2em,minimum width=4em},
sum/.style = {draw, circle, node distance=2cm},
input/.style  = {coordinate},
output/.style = {coordinate}}

\node [block] (A) {};
\node [block, right of=A] (B) {};
\begin{scope}[transform canvas={yshift=.7em}]
  \draw [->] (A) -- node {} (B);
\end{scope}

\end{tikzpicture}%
}
\end{document}

结果

箭头(或线)的长度可以通过shorten <和进行修改shorten >

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,fit,arrows}
\usepackage{graphicx}
\begin{document}

\noindent\resizebox{\textwidth}{!}{%
\begin{tikzpicture}[auto,node distance=5cm,>=stealth']
\tikzset{
block/.style= {draw, rectangle, minimum height=2em,minimum width=4em},
sum/.style = {draw, circle, node distance=2cm},
input/.style  = {coordinate},
output/.style = {coordinate}}

\node [block] (A) {};
\node [block, right of=A] (B) {};
\begin{scope}[transform canvas={yshift=.7em}]
  \draw [->, shorten <=5mm, shorten >=5mm] (A) -- node {} (B);
\end{scope}

\end{tikzpicture}%
}
\end{document}

结果,缩短箭头线

评论:

  • TeX内部\resizebox处于水平模式。因此空格很重要,需要删除不需要的行尾空格,例如,在行尾添加注释字符。

相关内容