I thought that my woes in Decoration marking arrow style ignored in custom node shape? were temporarily solved, but alas: if I do a dimension line (A) -- (B), then all is fine; but if I do (B) -- (A), then one of the arrows gets inverted; the output of the MWE below is:


Now, as I saw in How to draw just the arrow tip in TikZ, just the arrow tip can be reproduced with, say:

\draw[-latex] (0.4,0.4);

This is a line with length 0, starting at (0.4,0.4); interestingly, in the MWE, the result of this command is an arrow pointing up (and the answer at previous link uses node[rotate=90,inner sep=0pt] {\tikz\draw[-triangle 90](0,0) ;}; to rotate the arrow).

My first question is: can the orientation of an arrow be changed for a zero length line, without wrapping it in a context (like \node, or {scope} etc) that would rotate it wholesale?

My second question is - can the dimension line code be somehow fixed, so the correct dimension line arrows are displayed, regardless if the line drawing goes in the (A) -- (B) or the opposite (B) -- (A) direction?

The MWE:



\pagecolor{yellow!15} % ignored with preview, but not w/ varwidth




% https://tex.stackexchange.com/questions/185444/
  \edef\tout{#1 %
    pgfgettransform: \trfm ; %
    pgf@pt@aa, pgf@pt@ba, pgf@pt@ab, pgf@pt@bb: \pgf@pt@aa, \pgf@pt@ba, \pgf@pt@ab, \pgf@pt@bb %
  \typeout{\tout} %

% https://tex.stackexchange.com/a/185454/2595
\tikzset{ %
  declare function={multip(\a,\b)=\a*\b;}, % otherwise cannot use pgfmathparse here
  tconarrC/.style n args={5}{
    line width=#3,
      mark=at position 0 with {%
        \typeoutMyInfoString{pos 0:}%
        \pgftransformresetnontranslations %
        \pgftransformscale{#4} %
        \arrow[sloped,rotate=0,scale=1,fill=#5]{#1}; % (c3)
      mark=at position 1 with {% 0.999999
        \typeoutMyInfoString{pos 1:}%
        \pgftransformscale{#4} %
    shorten >={multip(#4,#3)},
    shorten <={multip(#4,#3)},
    reset transform/.code={},
    postaction={reset transform,decorate},
    every rectangle node/.style={midway,},
  minbox/.style={shape=rectangle,inner sep=0pt,outer sep=0pt,minimum size=0pt},
} % end tikzset
\pgfdeclareshape{myshape}{ %
  \inheritsavedanchors[from={rectangle}] %
  \inheritbackgroundpath[from={rectangle}] %
  \inheritanchorborder[from={rectangle}] %
  \foreach \x in {center,north,north east,north west,south,south east,south west,east,west}{ %
    \inheritanchor[from={rectangle}]{\x} %
  } %
  \backgroundpath{ %
    \edef\ename{\tikz@fig@name} %
    \node[rectangle,minimum size=10pt,draw] (\ename-A) at (\ename.east) {};
    \node[rectangle,minimum size=10pt,draw] (\ename-B) at (\ename.west) {};
  \foregroundpath{ %
      (\ename-A.center) -- (\ename-B.center)
      node[minbox,above=0pt] (\ename-L) {M$_1$}
      ($(\ename-B.center)-(0,1em)$) -- ($(\ename-A.center)-(0,1em)$)
      node[minbox,above=0pt] (\ename-L) {M$_2$}
} % declareshape

\node[fill] (origin) at (0,0) {};
\draw[-latex] (0.4,0.4);

\node[myshape,minimum size=2cm,anchor=south west] (tshape) at (1,1) {};

  ($(tshape-A.center)-(0,3em)$) -- ($(tshape-B.center)-(0,3em)$)
  node[above=-1pt] {A};
  ($(tshape-B.center)-(0,4em)$) -- ($(tshape-A.center)-(0,4em)$)
  node[above=-1pt] {B};


Your Answer

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

Browse other questions tagged or ask your own question.