9

I need to shift the arrow between two blocks up or down.

\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}

enter image description here

CroCo
  • 5,902

1 Answers1

7

The arrow can be moved by a canvas transformation:

\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}

Result

The length of the arrow (or lines) can be modified by shorten < and 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}

Result, shortened arrow line

Remark:

  • Inside \resizebox TeX is in horizontal mode. Therefore spaces matter and the unwanted spaced by line ends need to be removed, e.g. by adding the comment character at the end of line.
Heiko Oberdiek
  • 271,626