2

I'm drawing some nodes with to and from edges with some of the edges red, and with a cross through it. I have a custom decoration for the cross, and draw a red arrow head at the end of the line. In trying to shorten the line, to avoid it going out of the arrow head bounds, I find that the custom marker is also shortened.

What I have so far is as shown in the code and image below. Is there a way can shorten the line without affecting the cross, or even a better way to do this in general?

Thanks for your help!

\documentclass[tikz]{standalone}
\usepackage{tikz-cd}
\usetikzlibrary{arrows,positioning,decorations.pathmorphing,decorations.pathreplacing,decorations.shapes,decorations.markings}
\tikzset{
  shift left/.style ={commutative diagrams/shift left={#1}},
  shift right/.style={commutative diagrams/shift right={#1}},
  crossed/.style={draw=red,shorten >= 1.8pt,
    decoration={markings, mark= at position .15 with
      {
          \draw[red] (-2pt,-2pt) -- (2pt,2pt);
          \draw[red] (2pt,-2pt) -- (-2pt,2pt);
      };,
      mark= at position 1 with {\arrow[red]{>}};
    },
    postaction={decorate},
  },
}

\begin{document}
\begin{tikzpicture}[
    mynode/.style={rectangle,draw=black,thick,inner sep=0pt, minimum size=4mm},>=latex',
]

  \node[mynode,font=\tiny] (m0) {0};
  \node[mynode,right=of m0,font=\tiny] (m1) {1};

  \path[shift left=.75ex,thick]
  (m0) edge[->] node[very near start, yshift=-0.5ex, xshift=0.5ex,  font=\tiny] {2} (m1)
  (m1) edge[crossed] node[very near start, yshift=0.5ex, xshift=-0.5ex,  font=\tiny] {4} (m0);

\end{tikzpicture}
\end{document}

This gives me:

enter image description here

Without the shorten command, I get:

enter image description here

  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – user11232 Apr 15 '15 at 6:08
2

For arrow head, you don't need mark. Add -> directly to the edge. Then for your decoration, you have to add - like,

\draw[red,-] (-2pt,-2pt) -- (2pt,2pt);
\draw[red,-] (2pt,-2pt) -- (-2pt,2pt);

so that they don't have arrow heads too.

\documentclass[tikz]{standalone}
\usepackage{tikz-cd}
\usetikzlibrary{arrows,positioning,decorations.pathmorphing,decorations.pathreplacing,decorations.shapes,decorations.markings}
\tikzset{
  shift left/.style ={commutative diagrams/shift left={#1}},
  shift right/.style={commutative diagrams/shift right={#1}},
  crossed/.style={draw=red,%shorten >= 1.8pt,
    decoration={markings, mark= at position .15 with
      {
          \draw[red,-] (-2pt,-2pt) -- (2pt,2pt);
          \draw[red,-] (2pt,-2pt) -- (-2pt,2pt);
      };,
      %mark= at position 1 with {\arrow[red,anchor=west]{>}};    %% not needed here
    },
    postaction={decorate},
  },
}

\begin{document}
\begin{tikzpicture}[
    mynode/.style={rectangle,draw=black,thick,inner sep=0pt, minimum size=4mm},>=latex',
]

  \node[mynode,font=\tiny] (m0) {0};
  \node[mynode,right=of m0,font=\tiny] (m1) {1};

  \path[shift left=.75ex,thick]
  (m0) edge[->] node[very near start, yshift=-0.5ex, xshift=0.5ex,  font=\tiny] {2} (m1)
  (m1) edge[crossed,->] node[very near start, yshift=0.5ex, xshift=-0.5ex,  font=\tiny] {4} (m0);

\end{tikzpicture}
\end{document}

enter image description here

If you insist on using the arrow head as a mark, then add shorten >= 0pt to the decorative cross lines too like

 \draw[red,shorten >= 0pt] (-2pt,-2pt) -- (2pt,2pt);
 \draw[red,shorten >= 0pt] (2pt,-2pt) -- (-2pt,2pt);

so as to prevent them from getting shortened.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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