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.

I would like to insert figures which were created with TikZ to my LaTeX document.

I suppose that if I create the TikZ figure inside the document, that wouldn't be a problem - I'd just play with the scale value which comes right after \begin{tikzpicture}. However, sometimes the figure is too complicated for it to be written explicitly in the LaTeX document, so I create the figure in a different file and use \input{foo.tikz}. The problem with that is that I don't see how to scale it to fit the rest of the document.

share|improve this question

3 Answers 3

up vote 18 down vote accepted

You can set the every picture locally in a group around the input file to set any option which should be used for the tikzpicture in that file.

\begingroup
\tikzset{every picture/.style={scale=0.3}}%
\input{sometikzpic}%
\endgroup

However, if you have other tikzpictures inside nodes of the main picture they will also be affected (twice I mean). In this case, \tikzset{every picture/.style={scale=0.3,every picture/.style={}}} might work better.


Note that scale scales only coordinates. Text is not affected. You might want to scale the whole picture all together. For this use \scalebox{<factor>}{\input{<file>}} or
\resizebox{<width>}{!}{\input{<file>}}. This both macros come from graphics which is loaded already by tikz.

Also have a look at the standalone class, especially the new \includestandalone[<options>]{<file>} from v1.0beta which will include subfiles and scales them if requested, like \includegraphics does for images.

share|improve this answer
    
I actually much prefer this solution to mine. It can be used without modifying the tikz file. Will this override an explicitly set scale in the included file? Presumably not… –  Seamus Dec 17 '11 at 14:23
    
@Seamus: AFAIK, the every picture style is executed before the optional settings. So you will end up with two scale settings. I think both are then applied, i.e. multiplied which each other. –  Martin Scharrer Dec 17 '11 at 14:28
    
That did the trick. Thanks! Perhaps it's possible to scale it such as it fits the page's width? –  Shmuel Dec 17 '11 at 16:27
2  
@Shmuel: \resizebox{\textwidth}{!}{\input{<file>}} or \includestandalone[width=\textwidth]{<file>} with standalone v1.0beta1 –  Martin Scharrer Dec 17 '11 at 17:31

If inside foo.tex you set the scale to \tkzscl or some other user macro, you can then set it like so:

\def\tkzscl{0.3}
\input{foo}

This way, you can set the scale of the picture in the main file.

foo.tex should then look like this:

\begin{tikzpicture}[scale=\tkzscl]
\draw (0,0) -- (1,0);
\end{tikzpicture}

Or whatever…

share|improve this answer
    
I may use that sometimes, thanks! –  Shmuel Dec 17 '11 at 16:27

I know this has been answered, so here's a little trick to use these answers.

-1- Put this after your \usepackages and before your \begin{document}:

\newcommand{\inputTikZ}[2]{%  
     \scalebox{#1}{\input{#2}}  
}

-2- Use it like this to create a figure:

\begin{figure}  
\begin{centering}  
    \inputTikZ{0.5}{mytikzfile.tkz}  
\end{centering}  
\label{fig:myFig}  
\caption{some caption for the figure}  
\end{figure}  

In this way, the syntax is similar to \includegraphics[scale=...]{filename}

share|improve this answer
2  
instead of using the environment centering (which I do not know existed), use the command \centering and remove the enviroment. See center vs. centering. –  zeroth Sep 22 '12 at 7:14

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.