# TikZ's extended line penetrates the figure caption

Here is an example:

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{figure}\centering

\begin{tikzpicture}[extended line/.style={shorten >=-#1,shorten <=-#1}]
\draw [very thick, extended line=1cm] (0,0) -- (0,1);
\end{tikzpicture}

\caption{This is a test caption.}
\end{figure}

\end{document}


and its outcome:

How can I move the tikzpicture above the caption?

-
I am just curious. What do you use the negative shortening for? –  hpesoj626 Dec 3 '12 at 4:25
@hpesoj626 When I know the coordinates of two points, I want to draw a line that passes the two points with some extended lines at the both ends. negative shortening = extending –  FEQ Dec 3 '12 at 4:27
The reason is that the shorten pair doesn't update the bounding box. So you need to use something that does update it such as Qrrbrbirlbel's answer. –  percusse Dec 3 '12 at 4:34

Is this a valid option?

## Code

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\tikzset{
extended line/.style={
to path={
($(\tikztostart)!-#1!(\tikztotarget)$) --  ($(\tikztotarget)!-#1!(\tikztostart)$) \tikztonodes
}
}
}
\begin{document}
\begin{figure}\centering
\begin{tikzpicture}
\draw [very thick] (0,0) to[extended line=1cm] (0,1);
\end{tikzpicture}
\caption{This is a test caption.}
\end{figure}
\end{document}

-
-#1cm or other units are required to use lengths otherwise it will use fraction of the path length. Ah nevermind you supplied it in the command sorry. –  percusse Dec 3 '12 at 4:32
@percusse Yes and no: Yes, fractions will be used when no unit is given. And no, I wouldn't define the to path with #1cm because than a) one has to use extended line=1 (without the unit) and b) only cm are possible. I see this even as an advantage over shorten >. –  Qrrbrbirlbel Dec 3 '12 at 4:37
I've updated the comment :) –  percusse Dec 3 '12 at 4:37