1

I am having some issues with the following code:

\documentclass[crop,border=0]{standalone}
\usepackage{amsmath}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture} [>=latex]
    \draw[->, out=225, in=200] (-0.5,1.2) to (12-0.5,-1.6) node [pos=0.8, below] {\scriptsize $\begin{pmatrix}1 & 0 & 0 & 0 \end{pmatrix}$};
\end{tikzpicture}
\end{document}

No matter what I choose for pos I always get the row vector to be positioned as the figure below (fixed location and not below the arrow). My intent is to have the vector placed towards the end of the arrow and below it.

Example of arrow I get

Any suggestion? Thx!

  • Try something like: node [pos=0.8,below left,shift={(-0.8,-0.5)}] in the options... – koleygr Aug 19 at 14:50
  • Or try, \draw[->, out=225, in=200] (-0.5,1.2) to (12-0.5,-1.6)coordinate(end) ; \node at (end)[below=2mm] {\scriptsize $\begin{pmatrix}1 & 0 & 0 & 0 \end{pmatrix}$}; – ferahfeza Aug 19 at 14:57
  • 1
    The correct syntax is to put the node immediately after to: \draw[->, out=225, in=200] (-0.5,1.2) to node [pos=0.8, below] {\scriptsize $\begin{pmatrix}1 & 0 & 0 & 0 \end{pmatrix}$} (12-0.5,-1.6) ;. This works without quotes, which sometimes can have side effects. The correct bounding box can be obtained employing the bezier bounding box key from the box library from here. – Schrödinger's cat Aug 19 at 19:11
6

The correct syntax is to put the node immediately after to:

\documentclass[crop,border=0]{standalone}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{bbox}
\begin{document}
\begin{tikzpicture} [>=latex,bezier bounding box]
    \draw[->, out=225, in=200] (-0.5,1.2) to node [pos=0.8, below] {\scriptsize
    $\begin{pmatrix}1 & 0 & 0 & 0 \end{pmatrix}$} (12-0.5,-1.6) ;
\end{tikzpicture}
\end{document}

enter image description here

The bbox library, which was used to get the right bounding box, can be found here.

ADDENDUM: If one uses the arrows.meta and bending, the (experimental) bbox library needs to be slightly modified (because bending introduces very short Bezier curves). Save the following as tikzlibrarybbox.code.tex:

\tikzset{%
  bezier bounding box/.is choice,%
  bezier bounding box/.default=true,%
  bezier bounding box/true/.code=\tikzset{switch on bezier bounding box},%
  bezier bounding box/false/.code=\tikzset{switch off bezier bounding box}}%
\tikzset{switch off bezier bounding box/.code={%
\def\pgf@lt@curveto##1##2##3##4##5##6{%
  \pgf@protocolsizes{##1}{##2}%
  \pgf@protocolsizes{##3}{##4}%
  \pgf@protocolsizes{##5}{##6}%
  \pgfsyssoftpath@curveto{\the##1}{\the##2}{\the##3}{\the##4}{\the##5}{\the##6}%
}%
\let\pgf@nlt@curveto\pgf@lt@curveto}}
%
% it might just be me but according to what I believe to find 
% \pgfmathsetlengthmacro appears to generate spaces
%
\tikzset{switch on bezier bounding box/.code={%
\def\pgf@lt@curveto##1##2##3##4##5##6{%
  % extrema in x
  \pgfmathsetmacro{\pgf@temp@b}{abs(\pgf@path@lastx-##5-3*##1+3*##3)}%
  % ^^^ this is used for the denominator below, cannot become too small
  \pgfmathsetmacro{\pgf@temp@c}{max(1+\pgf@path@lastx,max(##1,max(##3,##5)))}%
  % ^^^ in order to avoid dimension too large errors from squaring lengths in pt
  \ifdim\pgf@temp@c pt>1pt
   \pgfmathparse{((##1/\pgf@temp@c)*(##1/\pgf@temp@c)-1*((##1/\pgf@temp@c)*(##3/\pgf@temp@c))+(##3/\pgf@temp@c)*(##3/\pgf@temp@c)-1*((##1/\pgf@temp@c)*(##5/\pgf@temp@c))+(-(##3/\pgf@temp@c)+(##5/\pgf@temp@c))*(\pgf@path@lastx/\pgf@temp@c))}%
   \pgfutil@tempdima=\pgfmathresult pt\relax% 
   % ^^^ discriminant
   \ifdim\pgf@temp@b pt<0.01pt\relax%
    % approximately linear  
    \pgfmathparse{abs(2*(##1)-2*(##3)+(##5))}%
    \pgfutil@tempdimb=\pgfmathresult pt\relax%
    \ifdim\pgfutil@tempdimb<0.1pt\relax%
     % if the denominator is very small, it is *likely* large but could be 0/0
    \else
     \pgfmathsetmacro{\pgf@temp@a}{(2*(##1)-3*(##3)+(##5))/(2*(##1)-2*(##3)+(##5))}%
     \pgfmathparse{\pgf@path@lastx*pow(1-\pgf@temp@a,3)+3*##1*pow(1-\pgf@temp@a,2)*\pgf@temp@a+3*##3*(1-\pgf@temp@a)*\pgf@temp@a*\pgf@temp@a+##5*pow(\pgf@temp@a,3)}%
     \pgfutil@tempdimb=\pgfmathresult pt\relax%
     \pgf@protocolsizes{\pgfutil@tempdimb}{##6}%
    \fi%
   \else
    \ifdim\pgfutil@tempdima<0pt\relax% negative discriminant -> no turning point
    \else
      \pgfmathsetmacro{\pgf@temp@a}{min(1,max(0,(\pgf@path@lastx-2*##1+##3-\pgf@temp@c*sqrt(\pgfutil@tempdima))/(\pgf@path@lastx-##5-3*##1+3*##3)))}%
      \pgfmathparse{\pgf@path@lastx*pow(1-\pgf@temp@a,3)+3*##1*pow(1-\pgf@temp@a,2)*\pgf@temp@a+3*##3*(1-\pgf@temp@a)*\pgf@temp@a*\pgf@temp@a+##5*pow(\pgf@temp@a,3)}%
      \pgfutil@tempdimb=\pgfmathresult pt\relax%
      \pgf@protocolsizes{\pgfutil@tempdimb}{##6}%
      \pgfmathsetmacro{\pgf@temp@a}{min(1,max(0,(\pgf@path@lastx-2*##1+##3+\pgf@temp@c*sqrt(\pgfutil@tempdima))/(\pgf@path@lastx-##5-3*##1+3*##3)))}%
      \pgfmathparse{\pgf@path@lastx*pow(1-\pgf@temp@a,3)+3*##1*pow(1-\pgf@temp@a,2)*\pgf@temp@a+3*##3*(1-\pgf@temp@a)*\pgf@temp@a*\pgf@temp@a+##5*pow(\pgf@temp@a,3)}%
      \pgfutil@tempdimb=\pgfmathresult pt\relax%
      \pgf@protocolsizes{\pgfutil@tempdimb}{##6}%
    \fi% 
   \fi 
  \fi
  %%%%%%%%%%%%%%%%%%%%%%%%%%%
  % extrema in y (completely analogous to the above)
  \pgfmathsetmacro{\pgf@temp@b}{abs(\pgf@path@lasty-##6-3*##2+3*##4)}%
  \pgfmathsetmacro{\pgf@temp@c}{max(1+\pgf@path@lasty,max(##2,max(##4,##6)))}%
  \ifdim\pgf@temp@c pt>1pt
   \pgfmathparse{((##2/\pgf@temp@c)*(##2/\pgf@temp@c)-1*((##2/\pgf@temp@c)*(##4/\pgf@temp@c))+(##4/\pgf@temp@c)*(##4/\pgf@temp@c)-1*((##2/\pgf@temp@c)*(##6/\pgf@temp@c))+(-(##4/\pgf@temp@c)+(##6/\pgf@temp@c))*(\pgf@path@lasty/\pgf@temp@c))}%
   \pgfutil@tempdima=\pgfmathresult pt\relax% 
   % ^^^ discriminant
   \ifdim\pgf@temp@b pt<0.01pt\relax%
    % approximately linear  
    \pgfmathparse{abs(2*(##2)-2*(##4)+(##6))}%
    \pgfutil@tempdimb=\pgfmathresult pt\relax%
    \ifdim\pgfutil@tempdimb<0.1pt\relax%
     % if the denominator is very small, it is *likely* large but could be 0/0
    \else
     \pgfmathsetmacro{\pgf@temp@a}{(2*(##2)-3*(##4)+(##6))/(2*(##2)-2*(##4)+(##6))}%
     \pgfmathparse{\pgf@path@lasty*pow(1-\pgf@temp@a,3)+3*##2*pow(1-\pgf@temp@a,2)*\pgf@temp@a+3*##4*(1-\pgf@temp@a)*\pgf@temp@a*\pgf@temp@a+##6*pow(\pgf@temp@a,3)}%
     \pgfutil@tempdimb=\pgfmathresult pt\relax%
     \pgf@protocolsizes{##5}{\pgfutil@tempdimb}%
    \fi%
   \else
    \ifdim\pgfutil@tempdima<0pt\relax% negative discriminant -> no turning point
    \else
      \pgfmathsetmacro{\pgf@temp@a}{min(1,max(0,(\pgf@path@lasty-2*##2+##4-\pgf@temp@c*sqrt(\pgfutil@tempdima))/(\pgf@path@lasty-##6-3*##2+3*##4)))}%
      \pgfmathparse{\pgf@path@lasty*pow(1-\pgf@temp@a,3)+3*##2*pow(1-\pgf@temp@a,2)*\pgf@temp@a+3*##4*(1-\pgf@temp@a)*\pgf@temp@a*\pgf@temp@a+##6*pow(\pgf@temp@a,3)}%
      \pgfutil@tempdimb=\pgfmathresult pt\relax%
      \pgf@protocolsizes{##5}{\pgfutil@tempdimb}%
      \pgfmathsetmacro{\pgf@temp@a}{min(1,max(0,(\pgf@path@lasty-2*##2+##4+\pgf@temp@c*sqrt(\pgfutil@tempdima))/(\pgf@path@lasty-##6-3*##2+3*##4)))}%
      \pgfmathparse{\pgf@path@lasty*pow(1-\pgf@temp@a,3)+3*##2*pow(1-\pgf@temp@a,2)*\pgf@temp@a+3*##4*(1-\pgf@temp@a)*\pgf@temp@a*\pgf@temp@a+##6*pow(\pgf@temp@a,3)}%
      \pgfutil@tempdimb=\pgfmathresult pt\relax%
      \pgf@protocolsizes{##5}{\pgfutil@tempdimb}%
    \fi% 
   \fi 
  \fi
  \pgf@protocolsizes{\pgf@path@lastx}{\pgf@path@lasty}%
  \pgf@protocolsizes{##5}{##6}%
  \pgfsyssoftpath@curveto{\the##1}{\the##2}{\the##3}{\the##4}{\the##5}{\the##6}%
}
\let\pgf@nlt@curveto\pgf@lt@curveto}}% fix me: 0/0 cases and occasional
% dimension too large errors (they can be fixed with fpu)

Then the following works, too:

\documentclass[crop,border=0]{standalone}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{bbox,arrows.meta,bending}
\begin{document}
\begin{tikzpicture} [,bezier bounding box]
    \draw[-{Latex[bend]}, out=225, in=200] (-0.5,1.2) to node [pos=0.8, below] {\scriptsize
    $\begin{pmatrix}1 & 0 & 0 & 0 \end{pmatrix}$} (12-0.5,-1.6) ;
\end{tikzpicture}
\end{document}

enter image description here

  • @schrödingers-cat - Nice clear way. The arrow in my diagram is part of a larger one, where I do have also straight arrows. It turns our that I was doing things wrongly there too, namely I had the node specifications (position and location) and the label after the coordinates of the node. Somehow there it worked fine. That's the source of the mistake. Thx! – geguze Aug 19 at 22:57
5

Try the following:

\documentclass[crop,border=0]{standalone}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{quotes}

\begin{document}
    \begin{tikzpicture} [>=latex, auto=right
                        ]
\draw[->] (-0.5,1.2) to [out=225, in=200, "$\begin{pmatrix}1 & 0 & 0 & 0 \end{pmatrix}$", pos=0.7] (12-0.5,-1.6);
    \end{tikzpicture}
\end{document}

enter image description here

Addendum

You my consider to add \clip (-1.2,1.2) rectangle (11.5,-3); before drawing curve. With it you will cut-out white space on the left side of picture (caused by bending anchors). For smaller font of edge labels you can define its style as it is in the next MWE:

\documentclass[crop,border=0]{standalone}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{quotes}

\begin{document}
    \begin{tikzpicture} [>=latex, 
every edge quotes/.style = {font=\scriptsize, auto=right}
                        ]
\clip (-1.2,1.2) rectangle (11.5,-3);
\draw[->] (-0.5,1.2) to [out=225, in=200, "$\begin{pmatrix}1 & 0 & 0 & 0 \end{pmatrix}$", pos=0.7] (11.5,-1.6);
    \end{tikzpicture}
\end{document}

enter image description here

  • This works! Question: I tried to put this code without the [>=latex, auto=right], as I did not notice it. I did not get the label to be below. Can you explain what those options do? I tried to add below but it did not work till I added those options. Thx! – geguze Aug 19 at 15:04
  • Turns out that I have a similar arrow going right to left. In this case the code above puts the label on top of the arrow. Only change would be out=315, in=340. Suggestion? – geguze Aug 19 at 15:10
  • @geguze, option >=latex has nothing with position of edge label, with auto=right is required that label had to be on the right side of arrow. – Zarko Aug 19 at 15:13
  • Ok, I figured how to change the side of the label and thus the meaning of auto=right. It is the same as in tikz-cd: the option forces all the labels to be on the "right" of arrows and if I add ' to the label like "here it is"' then I get to shift side. Thx! – geguze Aug 19 at 15:13
  • @geguze, see addendum in my answer. – Zarko Aug 19 at 15:29

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.