If you want to do exactly this, then put whatever you want to move in a scope, and provide the shift
option to said scope (the curly braces are necessary so the comma isn't thought to separate options). Something like
\begin{tikzpicture}
\begin{scope}[shift={(-5,0)}]
... graph goes here ...
\end{scope}
... other code goes here ...
\end{tikzpicture}
However, if your whole picture is wider than the text, this won't help. In that case, you should be able to use a negative horizontal space:
\hspace*{-5cm}%
\begin{tikzpicture}
... picture goes here ...
\end{tikzpicture}
However, if you want centering, you could check out some of the solutions to a similar problem with over-wide tables, such as surrounding it in a zero-width box.
You can use the <coordinate>!<number>!<second coordinate>
syntax; for example (3,3)!.25!(0,0)
means "the coordinate that is one quarter on the way from (3,3)
to (0,0)
". To place the label in the middle of the arrow, use the midway
option. An example:
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate (a) at (3,3);
\coordinate (b) at (3,0);
\coordinate (c) at (-3,3);
\node (O) at (0,0) {origin};
\draw[->,red] (3,3) -- ( $ (a)!.25!(0,0) $ ) node [midway, sloped, above] {12 m/s};
\draw[->,blue] (b) -- ( $ (b)!.8!(0,0) $ ) node [midway, sloped, above] {12 m/s};
\draw[->,magenta] (c) -- ( $ (c)!.5!(0,0) $ ) node [midway, sloped, above] {12 m/s};
\end{tikzpicture}
\end{document}
Even closer to waht you need, is the <coordinate>!<dimension>!<second coordinate>
syntax, which means "use the point that is distanced
<dimension>
from <coordinate>
on the straight line from <coordinate>
to <second coordinate>
". A little example:
:
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate (b) at (3,0);
\node (O) at (0,0) {origin};
\draw[->,magenta] (b) -- ( $ (b)!3cm!(0,0) $ ) node [midway, sloped, above] {12 m/s};
\end{tikzpicture}
\end{document}
And, of course, you can wrap this in a macro, as the following example suggests. The \arrowfromto[<attributes>]{<initial coordinate>}{<to coordinate>}{<distance>}{<label>}
macro will apply \draw
with the options given in the first optional argument, from <initial coordinate>
to a point that is <distance>
far away from it and on the straight line from <initial coordinate>
to the <to coordinate>, using a label given by
`:
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
% syntax
% \arrowfromto[<attributes>]{<initial coordinate>}{<to coordinate>}{<distance>}{<label>}
\newcommand\arrowfromto[5][blue]{%
\draw[#1] #2 -- ( $ #2!#4!#3 $ ) node [midway, sloped, above] {#5}}
\coordinate (a) at (3,3);
\node (O) at (0,0) {$O$};
\node (a) at (0,3) {$a$};
\node (b) at (3,3) {$b$};
\arrowfromto{(O)}{(a)}{5cm}{5cm};
\arrowfromto[-latex,red]{(a)}{(b)}{3cm}{3cm};
\arrowfromto[<->,green!80!black]{(b)}{(O)}{10mm}{10mm};
\end{tikzpicture}
\end{document}
Best Answer
I'm not sure of the usefulness of this approach, but
\tikzset
can alter most of tikz parameters from the point it appears on, so...