我对以下代码有一些问题:
\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}
无论我选择什么,pos
我总是让行向量定位如下图所示(固定位置,而不是箭头下方)。我的目的是将向量放置在箭头末端下方。
有什么建议吗?谢谢!
答案1
正确的语法是将节点紧跟在后面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}
bbox
用于获取正确边界框的库可以在这里。
附录:如果使用和arrows.meta
,则需要稍微修改bending
(实验)库(因为弯曲会引入非常短的贝塞尔曲线)。将以下内容保存为:bbox
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)
然后下面的操作也可以:
\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}
答案2
请尝试以下操作:
\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}
附录
您可以考虑\clip (-1.2,1.2) rectangle (11.5,-3);
在绘制曲线之前添加。使用它,您将切掉图片左侧的空白(由弯曲的锚点引起)。对于边缘标签的较小字体,您可以像在下一个 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}