15

I got a nice code to draw an arrow at the mid position of the curve. From Tikz: Arrowheads in the center

\tikzset{->-/.style={decoration={
 markings,
 mark=at position .5 with {\arrow{>}}},postaction={decorate}}}

I do not know how to make a dot some where along the curve.

The code may look like...(-dot- is not working)

\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} 

New Answer:

Now I got a very simple solution (Thanks to Altermundus from Extract x, y coordinate of an arbitrary point on curve in TikZ):

\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}

enter image description here

1
  • 1
    It is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. Commented May 18, 2012 at 5:32

2 Answers 2

10

It seems you left out a ; in \fill circle (2pt);. The MWE will be

\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} 

enter image description here

0
11

There is an arrow which is a dot so you can use that and use the \arrow syntax. You need to load the arrows library to make use of this.

\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}

With a little hacking (not really recommended), this can be set up to an augmented arrow specification. Recall that putting -> in the optional argument to, say, a \draw command installs the arrow > at the end. By modifying the code for this, we can make it so that -*- puts a dot in the middle, or at some specified point along the curve.

\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} 

arrow in middle of curve

3
  • It is very simple and nice solution.\tikzset{-dot-/.style={decoration={ markings, mark=at position #1 with {\arrow{*}}},postaction={decorate}}}
    – sandu
    Commented May 18, 2012 at 7:30
  • 1
    There are some unnecessary % signs such as right after \else, \fi, etc. Commented May 21, 2012 at 10:31
  • 2
    @Forgiver Those parts were cut-and-pasted from the original TikZ code. The unnecessary %s are in the code there. Commented May 21, 2012 at 10:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .