在下面的例子中,我想将文本对齐到切线的右侧,由于比例不同,倾斜度是错误的。我尝试使用“变换形状”,但文本变得难以阅读(太小),我当然可以添加比例(根据 x 和 y 而不同),但这会变成一个复杂的代码。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary {calc}
\usepackage{SIunitx}
\begin{document}
\begin{tikzpicture}[xscale=0.15,yscale=0.4]
\draw [thin,xstep=5,ystep=1,blue,dashed] (0,0) grid (50,12);
\draw[-latex,thick] (0,0) -- (51,0) node[below]{$t$ en \si{\second}};
\draw[-latex, thick] (0,0) -- (0,13) node[above right]{$v$ en \si{\mm\per\second}};
\draw[domain=0:50] plot (\x,{8*(1-exp(-\x/10))});
\draw[dashed,red,thick] (0,8)-- (50,8)node[above left]{$s_\infty=G\cdot U_0=\SI{8}{\mm/\second}$};
\draw[dashed,red,thick] (0,0) coordinate(O)-- node[sloped,above, pos=0.8]{Tangente en (0,0)}(10,8);
\draw[thick, red] (10,0) -- (10, {8*(1-exp(-1))}) coordinate(T0) -- (T0-|O)node[above]{$\num{0.63}\cdot G\cdot U_O$};
\node[below] at (10,0){10};
\node[left] at (0,10){10};
\end{tikzpicture}
\end{document}
答案1
一种方法是使用decoration
:
\draw[dashed,red,thick,
postaction={decorate},
decoration={
markings,
mark=at position 1.0 with {
\node [blue, transform shape, anchor=base, shift={(10pt,2pt)}]
{Tangente en (0,0)};
},
},
] (0,0) coordinate(O) -- (10,8);
代码:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary {calc}
\usepackage{siunitx}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}[xscale=0.15,yscale=0.4]
\draw [thin,xstep=5,ystep=1,gray,dashed] (0,0) grid (50,12);
\draw[-latex,thick] (0,0) -- (51,0) node[below]{$t$ en \si{\second}};
\draw[-latex, thick] (0,0) -- (0,13) node[above right]{$v$ en \si{\mm\per\second}};
\draw[domain=0:50] plot (\x,{8*(1-exp(-\x/10))});
\draw[dashed,red,thick] (0,8)-- (50,8)node[above left]{$s_\infty=G\cdot U_0=\SI{8}{\mm/\second}$};
\draw[dashed,red,thick,
postaction={decorate},
decoration={
markings,
mark=at position 1.0 with {
\node [blue, transform shape, anchor=base, shift={(10pt,2pt)}]
{Tangente en (0,0)};
},
},
] (0,0) coordinate(O) -- (10,8);
\draw[thick, red] (10,0) -- (10, {8*(1-exp(-1))}) coordinate(T0) -- (T0-|O)node[above, anchor=east]{$\num{0.63}\cdot G\cdot U_O$};
\node[below] at (10,0){10};
\node[left] at (0,10){10};
\end{tikzpicture}%
\end{document}
答案2
另一种方法是修复\pgftransformlineattime
。
人们也应该修正\pgftransformarcaxesattime
并\pgftransformcurveattime
遵循同样的想法。
\documentclass{article}
\usepackage{tikz}
\makeatletter
\def\pgftransformlineattime#1#2#3{%
\pgfgettransformentries\aa\ab\ba\bb\notimportantx\notimportanty%%% ⬅️⬅️⬅️ new
\pgf@process{#2}%
\pgf@xb=\pgf@x% xb/yb = start point
\pgf@yb=\pgf@y%
\pgf@process{#3}%
\pgf@xc=\pgf@x% xc/yc = end point
\pgf@yc=\pgf@y%
\pgftransformshift{\pgfpointlineattime{#1}{\pgfqpoint{\pgf@xb}{\pgf@yb}}{\pgfqpoint{\pgf@xc}{\pgf@yc}}}%
\ifpgfresetnontranslationattime%
\pgftransformresetnontranslations%
\fi%
\ifpgfslopedattime%
\advance\pgf@xc by-\pgf@xb%
\advance\pgf@yc by-\pgf@yb%
% Now that we get the tangent vector without transformation
% It suffices to apply the non-shift part of the transformation
{%%% ⬇️⬇️⬇️ new
\pgfsettransformentries\aa\ab\ba\bb{0pt}{0pt}
\pgf@pos@transform{\pgf@xc}{\pgf@yc}
\global\pgf@xc\pgf@xc
\global\pgf@yc\pgf@yc
}%%% ⬆️⬆️⬆️ new
% OK, now xc and yc are correctly tangent to the line
% Continue the usual routine
\ifpgfallowupsidedownattime%
\else%
\ifdim\pgf@xc<0pt%
\pgf@xc=-\pgf@xc%
\pgf@yc=-\pgf@yc%
\fi%
\fi%
\pgf@x=\pgf@xc%
\pgf@y=\pgf@yc%
\pgfpointnormalised{}% x/y = normalised vector
\pgf@ya=-\pgf@y%
\pgftransformcm%
{\pgf@sys@tonumber{\pgf@x}}{\pgf@sys@tonumber{\pgf@y}}%
{\pgf@sys@tonumber{\pgf@ya}}{\pgf@sys@tonumber{\pgf@x}}{\pgfpointorigin}%
\fi%
}
\makeatother
\begin{document}
\begin{tikzpicture}[xscale=2, yscale=3, xshift=40, yshift=50]
\draw (0, 0) -- node[sloped, above] {sloped correctly?} (2, 2);
\end{tikzpicture}%
\end{document}