我得到了一个很好的代码来画一个箭 在曲线的中间位置。从Tikz:箭头位于中心
\tikzset{->-/.style={decoration={
markings,
mark=at position .5 with {\arrow{>}}},postaction={decorate}}}
我不知道如何制作点位于曲线的某处。
代码可能看起来像......(-dot-是不是在职的)
\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\begin{document}
\tikzset{->-/.style={decoration={
markings,
mark=at position #1 with {\arrow{>}}},postaction={decorate}}}
\tikzset{-dot-/.style={decoration={
markings,
mark=at position #1 with {\fill circle (2pt)}},postaction={decorate}}}
\begin{tikzpicture}
%\fill (2,2) circle (2pt);
\draw[->-=.5] (0,0) to [bend left] (2,4);
\draw[-dot-=.8] (0,0) to [bend right] (2,4);
\end{tikzpicture}
\end{document}
新答案:
现在我得到了一个非常简单的解决方案(感谢来自提取TikZ中曲线上任意点的x,y坐标):
\documentclass{article}
\usepackage{tikz}
%
\begin{document}
%
\begin{tikzpicture}
\draw (0,0) to [bend left=20] coordinate[pos=0.7] (A)(2,4);
\fill[blue] (A) circle (2pt);
\end{tikzpicture}
%
\end{document}
答案1
似乎你漏掉了一个;
。MWE\fill circle (2pt);
将是
\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\begin{document}
\tikzset{->-/.style={decoration={
markings,
mark=at position #1 with {\arrow{>}}},postaction={decorate}}}
\tikzset{-dot-/.style={decoration={
markings,
mark=at position #1 with {\fill circle (2pt);}},postaction={decorate}}} %%% in this line added a ;
\begin{tikzpicture}
%\fill (2,2) circle (2pt);
\draw[-dot-=.5] (0,0) to [bend left] (2,4);
\draw[-dot-=.8] (0,0) to [bend right] (2,4);
\end{tikzpicture}
\end{document}
答案2
有一个箭头,它是一个点,因此您可以使用它并使用语法\arrow
。您需要加载箭头库才能使用它。
\documentclass{scrartcl}
%\url{http://tex.stackexchange.com/q/56347/86}
\usepackage{tikz}
\usetikzlibrary{arrows,decorations.markings}
\begin{document}
\tikzset{->-/.style={decoration={
markings,
mark=at position #1 with {\arrow{>}}},postaction={decorate}}}
\tikzset{-dot-/.style={decoration={
markings,
mark=at position #1 with {\arrow{*}}},postaction={decorate}}}
\begin{tikzpicture}
%\fill (2,2) circle (2pt);
\draw[->-=.5] (0,0) to [bend left] (2,4);
\draw[-dot-=.8] (0,0) to [bend right] (2,4);
\end{tikzpicture}
\end{document}
通过一些小技巧(不推荐),可以将其设置为增强箭头规范。回想一下,将->
可选参数放入命令中会在末尾\draw
安装箭头。通过修改此代码,我们可以将其设置为在中间或曲线上的某个指定点放置一个点。>
-*-
\documentclass{scrartcl}
%\url{http://tex.stackexchange.com/q/56347/86}
\usepackage{tikz}
\usetikzlibrary{arrows,decorations.markings}
\makeatletter
\def\tikz@@processarrows#1-#2\@nil{%
\expandafter\ifx\csname tikz@special@arrow@start#1\endcsname\relax%
\pgfsetarrowsstart{#1}
\else%
\pgfsetarrowsstart{\csname tikz@special@arrow@start#1\endcsname}%
\fi%
\pgfutil@in@-{#2}%
\ifpgfutil@in@%
% has a midpoint specification
\tikz@@processmidarrow#2\@nil
\else
\expandafter\ifx\csname tikz@special@arrow@end#2\endcsname\relax%
\pgfsetarrowsend{#2}
\else%
\pgfsetarrowsend{\csname tikz@special@arrow@end#2\endcsname}%
\fi%
\fi
}
\def\tikz@@processmidarrow#1-#2\@nil
{
\expandafter\ifx\csname tikz@special@arrow@end#2\endcsname\relax%
\pgfsetarrowsend{#2}
\else%
\pgfsetarrowsend{\csname tikz@special@arrow@end#2\endcsname}%
\fi%
\def\tikz@temp{#1}%
\ifx\tikz@temp\pgfutil@empty%
\else%
\ifx\tikz@value\pgfutil@empty
\else
\tikzset{arrow midpoint location/.expand once=\tikz@value}
\fi
\tikzset{arrow midpoint=#1}
\fi%
}
\tikzset{
arrow midpoint location/.initial=.5,
arrow midpoint/.style={decoration={
markings,
mark=at position \pgfkeysvalueof{/tikz/arrow midpoint location} with {\arrow{#1}}},postaction={decorate}}}
\pgfkeys{/tikz/.unknown/.code=%
% Is it a pgf key?
\let\tikz@key\pgfkeyscurrentname%
\def\tikz@value{#1}%
\pgfkeys{/pgf/\tikz@key/.try={#1}}%
\ifpgfkeyssuccess%
\else%
\expandafter\pgfutil@in@\expandafter!\expandafter{\tikz@key}%
\ifpgfutil@in@%
% this is a color!
\expandafter\tikz@addoption\expandafter{\expandafter\pgfutil@color\expandafter{\tikz@key}}%
\edef\tikz@textcolor{\tikz@key}%
\else%
\pgfutil@doifcolorelse{\tikz@key}
{ %
\expandafter\tikz@addoption\expandafter{\expandafter\pgfutil@color\expandafter{\tikz@key}}%
\edef\tikz@textcolor{\tikz@key}%
}%
{%
% Ok, second chance: This might be an arrow specification:
\expandafter\pgfutil@in@\expandafter-\expandafter{\tikz@key}
\ifpgfutil@in@%
% Ah, an arrow spec!
\expandafter\tikz@processarrows\expandafter{\tikz@key}%
\else%
% Ok, third chance: A shape!
\expandafter\ifx\csname pgf@sh@s@\tikz@key\endcsname\relax%
\pgfkeys{/errors/unknown key={/tikz/\tikz@key}{#1}}%
\else%
\edef\tikz@shape{\tikz@key}%
\fi%
\fi%
}%
\fi%
\fi%
}
\makeatother
\begin{document}
\begin{tikzpicture}
\draw[*-] (0,0) -- (2,4);
\draw[->-] (0,0) to [bend left] (2,4);
\draw[-*->=0.8] (0,0) to [bend right] (2,4);
\end{tikzpicture}
\end{document}