# subpath with arrow tips

I'm trying to place arrow heads at the ends of a certain segment of a line and additionally put a label somewhere alongside the segment.

An example of what I mean is shown in the image below. I want to isolate the part of the arced path (line 1) on the top right between the intersection points with the straight line (line 2), which in the image is the thick line segment.

I want to be able to put a label somewhere alongside the thick line using node[near start], node[midway] etc. as is done in the left image. But additionally want arrow heads at the ends as in the right image.

This concludes the question, the code for creating the images is given below. Also some additional information on the pro's and con's, in my opinion, of both methods of creating the image is given.

The left image was created by clipping part of the image and redrawing the arced line. However, if arrow heads are added using this method they fall outside the clipping area therefore not showing up in the picture.

\documentclass[tikz]{standalone}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
% \draw[help lines] (-1, -1) grid (2, 2);
\def\LineA{(-1, 0) .. controls (2, 2) and (2, 1) .. (0, -1)}
\draw[name path=line1]
\LineA
node {line 1}
;
\draw[name path=line2]
(-1, 1) -- (1, -1)
node {line 2}
;
\path[name intersections={of=line1 and line2}]
(intersection-1) (intersection-2)
;
\begin{scope}
\clip (-1, 1) -- (-1, 2) -- (2, 2) -- (2, -1) -- (1, -1) -- cycle;
\draw[very thick] \LineA node[midway] {$C$};
\end{scope}
\end{tikzpicture}
\end{document}


The right image was created by using intersection segments (requiring \usepackage{pgfplots} and \usetikzlibrary{fillbetween} in the preamble) which enables to really isolate the line segment in question. Then, if that line segment is redrawn it can be given arrow heads. However, TikZ doesn't seem to know the shape of the line segment and doesn't know how to place the label properly. That is, using the syntax node[midway] {$C$} seems to place places the node halfway between the intersection points of line 1 and line 2. Additionally the intersection points are not calculated very precisely, as can ben seen (if you look closely) at the bottom right arrow: it just overshoots the intersection point. The code to create the second image is:

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{fillbetween}
\begin{tikzpicture}
\path[name path = line1, draw] (-1,0) .. controls (2,2) and (2,1) .. (0,-1) node {line 1};
\path[name path = line2, draw] (-1,1) -- (1,-1) node {line 2};
\draw[<->, very thick, intersection segments={of=line1 and line2, sequence=L2}] node[midway] {$C$};
\end{tikzpicture}
\end{document}


It seems logical to being able to isolate part of a path as is done using intersection segments not having to clip part of the image. But additionally that line segment should be a proper path. It should be possible, for instance, to place nodes along the curve, which intersection segments doesn't seem to support.

This is more or less a follow up question to my question here, to which I added the question of the placement of the arrow heads. I deliberately did not edit my question there as it has been answered in a satisfactory way thereby closing the thread.

This is as far as I got. Note that (intersection-2) does not match the end of segment L2 (but does match the start of segment L3) This looks like a bug.

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{fillbetween}
\begin{document}
\begin{tikzpicture}
\path[name path = line1, draw] (-1,0) .. controls (2,2) and (2,1) .. (0,-1) node[below left] {line 1}
node[above right, midway] {$C$};
\path[name path = line2, draw] (-1,1) -- (1,-1) node[below right] {line 2};
\draw[very thick, intersection segments={of=line1 and line2, sequence=L2}];
\draw[green,opacity=.5, very thick, intersection segments={of=line1 and line2, sequence=L3}];
\path [name intersections={of=line1 and line2}];
\draw[red] (intersection-1) -- (intersection-2);
\end{tikzpicture}
\end{document}


Using Zarko's suggeestion and removing the node offsets.

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{fillbetween}

\begin{document}
\begin{tikzpicture}
\path[name path = line1, draw] (-1,0) .. controls (2,2) and (2,1) .. (0,-1) node {line 1}
node[midway] {$C$};
\path[name path = line2, draw] (-1,1) -- (1,-1) node {line 2};
\draw[very thick, shorten >=\pgflinewidth, <->, intersection segments={of=line1 and line2, sequence=L2}];
\end{tikzpicture}
\end{document}


• very interesting solution (+1)! where is described intersection segments? try code line with intersection segments replaced with \draw[very thick, shorten >=\pgflinewidth, <->, intersection segments={of=line1 and line2, sequence=L2}]; as workaround for "bug". – Zarko Jul 29 '17 at 16:04
• @John Thank you for you solution. Although it does solve the problem in this case, it is not what I was looking for. Now the label is put halfway line 1, it is not placed next to the thick line. So indeed, it solves the problem here as midway line 1 is almost equal to midway of the thick line. But in general this isn't so and I'm looking for a solution in which the label is actually placed alongside the thick line. Additionally, the intersections are not calculated accurately using the intersection segments, as can be seen. It definitely is a usable workaround though, thanks for that. – Alwin Jul 29 '17 at 16:32
• @Zarko - I tried using "shorten", but forgot the keyword is actually "shorten >". – John Kormylo Jul 29 '17 at 21:55
• @Zarko Did you find the description? – cfr Jul 29 '17 at 22:48
• @Zarko and @cfr intersection segments is a command from pgfplots. Its manual can be found at pgfplots.sourceforge.net/pgfplots.pdf and the section that describes `intersection segments' is 5.7.6 Intersection Segment Recombination – Alwin Jul 29 '17 at 23:08