
我想在參數曲線的垂直部分畫一個箭頭。例如,考慮以下擺線。
\documentclass{scrbook}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{
arrows.meta
, bending
, decorations.markings
}
\pgfplotsset{compat = 1.17}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width = 0.4\textwidth
, height = 0.25\textwidth
, axis equal
, axis lines = middle
, enlargelimits = false
, tick style = {draw = none}
, ymin = {0.0}
, xtick = \empty
, ytick = \empty
]
\addplot+[
no markers
, thick
, domain = -2.08869:8.37188
, smooth
, postaction = {decorate}
, decoration = {
markings
, mark = at position 0.132010 with {\arrow{Stealth[length = 2mm, bend]}}
, mark = at position 0.210413 with {\arrow{Stealth[length = 2mm, bend]}}
}
] ({x - 1.5 * sin(x r)}, {1.5 - 1.5 * cos(x r)});
\end{axis}
\end{tikzpicture}
\end{document}
我計算了相應的積分,並知道曲線「垂直」部分的位置分別為 0.132 和 0.210,以總長度的分數表示。結果看起來很難看,因為這是箭頭尖端的位置:
如何將箭頭的中心放在這些點上,而不是其尖端?
還有一個附帶問題:我指定了“彎曲”,但它看起來根本不彎曲。為什麼?
答案1
因為您明確定義了標記的長度\arrow
。您可以使用decoration tranform
,請參閱pgfmanual
§24.4.1。在本例中,我將箭頭移動了一半長度。
這是輸出,藍色是你的圖,篩選後的圖是半透明的紅色。
% arara: lwpdflatex
\documentclass{scrbook}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{
arrows.meta
, bending
, decorations.markings
}
\pgfplotsset{compat = 1.17}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width = 0.4\textwidth
, height = 0.25\textwidth
, axis equal
, axis lines = middle
, enlargelimits = false
, tick style = {draw = none}
, ymin = {0.0}
, xtick = \empty
, ytick = \empty
]
\addplot+[
no markers
, thick
, domain = -2.08869:8.37188
, smooth
, trig format=rad
, postaction = {decorate}
, decoration = {
markings
, mark = at position 0.132010 with {\arrow{Stealth[length = 2mm, bend]}}
, mark = at position 0.210413 with {\arrow{Stealth[length = 2mm, bend]}}
}
] ({x - 1.5 * sin(x)}, {1.5 - 1.5 * cos(x)});
\addplot+[
no markers
, thick,opacity=0.5
, domain = -2.08869:8.37188
, smooth
, trig format=rad
, postaction = {decorate}
, decoration = {
markings
, transform={xshift=1mm}
, mark = at position 0.132010 with {\arrow{Stealth[length = 2mm, bend]}}
, mark = at position 0.210413 with {\arrow{Stealth[length = 2mm, bend]}}
}
] ({x - 1.5 * sin(x)}, {1.5 - 1.5 * cos(x)});
\end{axis}
\end{tikzpicture}
\end{document}