You can use the line cap=round
option (other permissible values are butt
(default) and rect
):
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[double distance = 0.5cm,line cap=round] (0,0) -- (1,0);
\end{tikzpicture}
\end{document}
![result](https://i.stack.imgur.com/7Toow.png)
Note however that the cap extends beyond the actual line (i.e. (0,0) is at the center of the cap and not on the boundary).
Here is an actual arrow tip:
\documentclass{article}
\usepackage{tikz}
\makeatletter
\pgfarrowsdeclare{open cap}{open cap}
{\pgfarrowsleftextend{+0pt}\pgfarrowsrightextend{+0.5\pgflinewidth}}
{
\pgfmathsetlength{\pgfutil@tempdimb}{.5*\pgflinewidth-.5*\pgfinnerlinewidth}%
\pgfsetlinewidth{\pgfutil@tempdimb}
\pgfsetbuttcap
\pgfsetdash{}{0pt}
\pgfmathsetlength{\pgfutil@tempdima}{.5*\pgfutil@tempdimb+.5*\pgfinnerlinewidth}%
\pgfpathmoveto{\pgfqpoint{0pt}{\pgfutil@tempdima}}
\pgfpatharc{270}{90}{-\pgfutil@tempdima}
\pgfusepathqstroke
}
\makeatother
\begin{document}
\begin{tikzpicture}
\draw[very thick,double distance = 0.5cm,open cap-open cap] (0,0) -- (1,0);
\end{tikzpicture}
\end{document}
![result](https://i.stack.imgur.com/ZC0Ik.png)
Here (0,0) is at the end of the line (i.e. the boundary of the cap).
A @whlt3 mentioned in the comments, adding the ->
option to the draw command will produce an arrow. There are different arrow option available, and below I have used -latex
as I think that looked better in this case. In the linked question Drawing Arrows in Tables the arrow style -triangle 45
was used so may not have been obvious. A few of the arrow types are mentioned at Graph into graph with arrows, but many more are available -- see the TikZ/PGF
documentation for more arrow options.
However, in this case I would also recommend that you also adapt a slightly different syntax so that you can specify the out
and in
angle for the line so that provide flexibility in case the straight line would overlap some other code to yield:
![enter image description here](https://i.stack.imgur.com/0t3Hb.png)
Notes:
- This requires two runs. Once to determine the begin and end point of the lines, and the second to draw them.
Code:
\documentclass[border=5pt]{standalone}
\usepackage{listings}% http://ctan.org/pkg/listings
\usepackage{tikz}% http://ctan.org/pkg/pgf
\usetikzlibrary{calc}
% https://tex.stackexchange.com/questions/1559/adding-a-large-brace-next-to-a-body-of-text/1570#1570
\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}
\lstset{
frame=single,
mathescape % Allows escaping to (La)TeX mode within $..$
}
\begin{document}
\noindent\begin{minipage}{.45\textwidth}
\begin{lstlisting}[caption={Original code}]
1 code $\tikzmark{L1line1}$
2 some longer code here
3 some longer code here
4 more code$\tikzmark{L1line4}$
\end{lstlisting}
\end{minipage}\hfill
\begin{minipage}{.5\textwidth}
\begin{lstlisting}[caption={Code after insertion of detour}]
$\tikzmark{L2line1}$ 86
$\tikzmark{L2line4}$ 4
\end{lstlisting}
\end{minipage}
\tikz[overlay,remember picture,-latex] \draw[color=red,thick,out=0,in=160] ($(L1line1)+(0pt,0.7ex)$) to ($(L2line1)+(0pt,0.7ex)$);
\tikz[overlay,remember picture,-latex] \draw[color=blue,thick,out=0,in=200] ($(L1line4)+(0pt,0.7ex)$) to ($(L2line4)+(0pt,0.7ex)$);
\end{document}
Best Answer
The comments have already mentioned
\overleftrightarrow
. Here is an alternative that tries to make the segment use the same heads as\vec
, also shown for comparison.Based on my answer at "Double headed" vector, except that I had to make it extensible to match segments of different sizes.
On the left are two
\vec
s, two\dvec
s and on the right are two\overleftrightarrow
s. Below is a very wide\dvec
.EDITED, based on Leon's suggestion, to improve the height of the
\dvec
, so as to be compatible with\vec
when using\left...\right
syntax.ADDENDUM
Based on the OP's request, I provide
\ray{}
below: