Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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:

enter image description here

How can I move the tikzpicture above the caption?

share|improve this question
    
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
1  
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
add comment

1 Answer

up vote 12 down vote accepted

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}
share|improve this answer
    
-#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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.