TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to change the output arrow in the code below so that it does not overlap the rectangle?

\documentclass[standalone]{article}

\usepackage{tikz}

\usetikzlibrary{positioning,decorations.markings,arrows}

\begin{document}

\begin{tikzpicture}[font=\small]
\tikzset{block/.style={draw, rectangle, line width=2pt, minimum height=3em, 
minimum width=5em, outer sep=0pt}}

\tikzset{vecArrow/.style={
  line width=1pt,
  decoration={
    markings,mark=at position 1 with {
       \arrow[scale=2.5,line width=0.4pt] {open triangle 60}
    }
  },
  double distance=4pt, shorten >= 13pt,
  preaction = {decorate},
  postaction = {draw,line width=4pt, white,shorten >= 10pt}
}}

\node [block] (A) {A};
\node[coordinate,right=2cm of A](B){};

\draw[vecArrow](A) -- node[above,align=center]{}(B);

\end{tikzpicture}

\end{document}
share|improve this question
up vote 3 down vote accepted

Two possible solutions:

  1. You can load the backgrounds library, then enclose the arrow inside of \begin{scope}[on background layer] ... \end{scope}.

  2. Alternatively, perhaps the best solution, you can add shorten <= \pgflinewidth, to your vecArrow style definition. The arrow will automatically shorten itself for the width of the node's border.

In both cases the result is the following:

enter image description here

share|improve this answer
1  
Alternative 2 was the easiest. Thanks for your help. – Anders Mar 2 at 9:25

The simplest solution is to draw what goes on top at the very end. In this case, since you place nodes relative to other nodes, you can just "overwrite" what's been already drawn:

\documentclass[tikz, border=10pt]{standalone}

\usepackage{tikz}
\usetikzlibrary{
  positioning,
  decorations.markings,
  arrows
}
\tikzset{
  block/.style={
    draw, 
    rectangle, 
    line width=2pt, 
    minimum height=3em, 
    minimum width=5em,
    outer sep=0pt
  },
  vecArrow/.style={
    line width=1pt,
    decoration={
      markings,
      mark=at position 1 with {
        \arrow[scale=2.5,line width=0.4pt] {open triangle 60}
      }
    },
    double distance=4pt,
    shorten >=13pt,
    preaction={decorate},
    postaction={
      draw,
      line width=4pt, 
      white,
      shorten >= 10pt
    },
  },
}
\begin{document}
\begin{tikzpicture}[font=\small]
  \node [block] (A) {};
  \node [coordinate, right=2cm of A] (B) {};
  \draw[vecArrow](A) -- (B)
        node [pos=1, anchor=west] {Anders};
  \node [block] at (A) {A};
\end{tikzpicture}

\end{document}

output

Also, it is possible to place a node at the end of a \draw command as demonstrated above.

share|improve this answer

You can draw paths before your node is inked via append after command.

\documentclass[tikz]{standalone}
\usetikzlibrary{positioning,decorations.markings,arrows}

\begin{document}

\begin{tikzpicture}[font=\small]
\tikzset{block/.style={draw, rectangle, line width=2pt, minimum height=3em, 
minimum width=5em, outer sep=0pt}}

\tikzset{vecArrow/.style={
  line width=1pt,
  decoration={
    markings,mark=at position 1 with {
       \arrow[scale=2.5,line width=0.4pt] {open triangle 60}
    }
  },
  double distance=4pt, shorten >= 13pt,
  preaction = {decorate},
  postaction = {draw,line width=4pt, white,shorten >= 10pt}
}}

\draw[vecArrow] 
   node [block,append after command={coordinate[right = 2cm of A] (B) {(A) -- (B)}}] 
        (A) {A};

\end{tikzpicture}
\end{document}

this gives the same picture given in other answers

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.