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 have two tikz pictures in external files (fig1.tex and fig2.tex):

fig1.tex

\documentclass[a4paper,class=minimal,border=0pt]{standalone}

\usepackage{tikz}
\usetikzlibrary{plotmarks}
\usetikzlibrary{arrows,shapes}
\usetikzlibrary{plothandlers}
\usetikzlibrary{positioning}
\usetikzlibrary{calc}


\begin{document}

\resizebox{18cm}{!}{ 
\begin{tikzpicture}
% \draw[help lines] (-3,-3) grid (10,10);  %%%% help grids line
%  axis
  \draw[rotate=90][->] (-1,0) -- (4,0)node[left] {\Large$\phi$} ;
  \draw[->] (-2,0) -- (7,0) node[above] {\Large$\lambda$};
  \draw(0,0) rectangle (5,2.5); 

%  node point
    \filldraw[color=blue] (0,0) circle (0.1);
    \node [below right]  at (0,0) {\large$E(0,0)$} ;
    \filldraw[color=blue] (5,0) circle (0.1);
    \node [below right]  at (5,0) {\large$E(0,1)$} ;
    \filldraw[color=blue] (0,2.5) circle (0.1);
    \node [below right]  at (0,2.5) {\large$E(1,0)$} ;
    \filldraw[color=blue] (5,2.5) circle (0.1);
    \node [below right]  at (5,2.5) {\large$E(1,1)$} ;

% p and q point
\draw[loosely dashed] (0,1.3) -- (2.1,1.3)  ;
\node [left]  at (0,1.3) {\Large$p$} ;
\draw[loosely dashed]  (2.1,0) -- (2.1,1.3) ;
\node [below] at (2.1,0) {\Large$q$};

% IPP point
\filldraw[color=red] (2,1.2) rectangle (2.2,1.4) ;
\node [right]  at (2.1,1.3) {\large$E(p,q)$} ;



\end{tikzpicture} } % end resizebox
\end{document} 
  • fig2.tex

example:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{through}
\usetikzlibrary{calc}


\begin{document}
\begin{tikzpicture}
% Works
\coordinate (A) at (1,2);
\coordinate (B) at (2,2);
% Works
\node [draw] at (2,2) [circle through={(B)}] {};
\node [draw] at (3,5) [circle through={(B)}] {};
\node [draw] at (A) [circle through={(2,2)}] {};

\end{tikzpicture}
\end{document}

now I am trying include them to my main.tex file:

  • main.tex

xxxx

\documentclass[11pt,DIV10,a4paper, titlepage,parskip=half,headings=normal,listof=totoc,bibliography=totoc,final]{scrreprt}
\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{external}
\usepackage{standalone}
\begin{document}
% Works
\begin{figure}[ht]
\centering
\includestandalone{try}
\caption{Geometry of ionospheric pirce point}\label{fig:figure2}
\end{figure}

\begin{figure}[ht]
\centering
\includestandalone{bivariate_interpolation}
\caption{Geometry of ionospheric pirce point}\label{fig:figure2}
\end{figure}

\end{document}

and I am using Makefile file to compile them:

  • Makefile

Generic make file for LaTeX: requires GNU make

TEXFILE = _main.tex

.PHONY: dvi ps pdf clean

pdf:    $(TEXFILE:.tex=.pdf)
ps: $(TEXFILE:.tex=.ps)
dvi:    $(TEXFILE:.tex=.dvi)

%.dvi: %.tex
    ( \
    latex $<; \
    latex $<; \
    latex $<; \
    bibtex $(TEXFILE:.tex=.aux); \
    bibtex $(TEXFILE:.tex=.aux); \
    bibtex $(TEXFILE:.tex=.aux); \
    makeglossaries $(TEXFILE:.tex=.acn); \
    latex $<; \
    latex $<; \
    latex $<; \
    )
%.ps: %.dvi
    dvips -q $< -o $(<:.dvi=.ps)

%.pdf: %.ps
    ps2pdf -dPDFSETTINGS=/prepress $<

    @rm -f \
    $(TEXFILE:.tex=.aux) \
    $(TEXFILE:.tex=.log) \
    $(TEXFILE:.tex=.idx) \
    $(TEXFILE:.tex=.lof) \
    $(TEXFILE:.tex=.lot) \
    $(TEXFILE:.tex=.nlo) \
    $(TEXFILE:.tex=.out) \
    $(TEXFILE:.tex=.dvi) \
    $(TEXFILE:.tex=.ps) \
    $(TEXFILE:.tex=.nav) \
    $(TEXFILE:.tex=.toc) \
    $(TEXFILE:.tex=.snm) \
    $(TEXFILE:.tex=.bbl) \
    $(TEXFILE:.tex=.blg) \
    $(TEXFILE:.tex=.ilg) \
    $(TEXFILE:.tex=.ind) \
    *~ 

Everything works correctly with fig1.tex, but when I am trying to compile it with fig2. tex I have an error:

! Package pgfkeys Error: I do not know the key '/tikz/circle through'

But when I am trying to compile my fig2.tex directly from console by using comments:

pdflatex -synctex=1 -interaction=nonstopmode "fig2".tex 

It works !

I don't have any ideas what I am doing wrong. I am using pgfv2.10 (opensuse) Can somebody help me? greetings

share|improve this question

1 Answer 1

up vote 4 down vote accepted

standalone strips off the preamble of the standalone files. Hence the tikz library through will not be available when you compile the second figure. To avoid this, you have to include all packages and libraries (that are used in sub files) in the preamble of main tex file. Putting \usetikzlibrary{through} in the preamble of main tex file works.

\documentclass[11pt,DIV10,a4paper, titlepage,parskip=half,headings=normal,listof=totoc,bibliography=totoc,final]{scrreprt}
%\usepackage{pgf}   % this is not needed 
\usepackage{tikz}
%% following lines need to be here also. ------------
\usetikzlibrary{external}
\usetikzlibrary{through}
\usetikzlibrary{plotmarks}
\usetikzlibrary{arrows,shapes}
\usetikzlibrary{plothandlers}
\usetikzlibrary{positioning}
\usetikzlibrary{calc}
%%--------------------------------------------------
\usepackage{standalone}
\usepackage{filecontents}
\begin{filecontents*}{fig1.tex}
\documentclass[a4paper,class=minimal,border=0pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{plotmarks}
\usetikzlibrary{arrows,shapes}
\usetikzlibrary{plothandlers}
\usetikzlibrary{positioning}
\usetikzlibrary{calc}
\begin{document}

\resizebox{18cm}{!}{
\begin{tikzpicture}
% \draw[help lines] (-3,-3) grid (10,10);  %%%% help grids line
%  axis
  \draw[rotate=90][->] (-1,0) -- (4,0)node[left] {\Large$\phi$} ;
  \draw[->] (-2,0) -- (7,0) node[above] {\Large$\lambda$};
  \draw(0,0) rectangle (5,2.5);

%  node point
    \filldraw[color=blue] (0,0) circle (0.1);
    \node [below right]  at (0,0) {\large$E(0,0)$} ;
    \filldraw[color=blue] (5,0) circle (0.1);
    \node [below right]  at (5,0) {\large$E(0,1)$} ;
    \filldraw[color=blue] (0,2.5) circle (0.1);
    \node [below right]  at (0,2.5) {\large$E(1,0)$} ;
    \filldraw[color=blue] (5,2.5) circle (0.1);
    \node [below right]  at (5,2.5) {\large$E(1,1)$} ;

% p and q point
\draw[loosely dashed] (0,1.3) -- (2.1,1.3)  ;
\node [left]  at (0,1.3) {\Large$p$} ;
\draw[loosely dashed]  (2.1,0) -- (2.1,1.3) ;
\node [below] at (2.1,0) {\Large$q$};

% IPP point
\filldraw[color=red] (2,1.2) rectangle (2.2,1.4) ;
\node [right]  at (2.1,1.3) {\large$E(p,q)$} ;
\end{tikzpicture} } % end resizebox
\end{document}
\end{filecontents*}
%
\begin{filecontents*}{fig2.tex}
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{through}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}
% Works
\coordinate (A) at (1,2);
\coordinate (B) at (2,2);
% Works
\node [draw] at (2,2) [circle through={(B)}] {};
\node [draw] at (3,5) [circle through={(B)}] {};
\node [draw] at (A) [circle through={(2,2)}] {};

\end{tikzpicture}
\end{document}
\end{filecontents*}
\begin{document}
% Works
\begin{figure}[ht]
\centering
\includestandalone{fig1}
\caption{Geometry of ionospheric pirce point}\label{fig:figure2}
\end{figure}

\begin{figure}[ht]
\centering
\includestandalone{fig2}
\caption{Geometry of ionospheric pirce point}\label{fig:figure2}
\end{figure}

\end{document} 
share|improve this answer
    
just great, it works :) thanks a lot –  kinga Nov 19 '13 at 23:32
    
Is it possible to somehow tell standalone to copy the preamble of the files being included? It is sometimes a hassle to keep copying all the \usetikzlibrary commands. –  Didac Busquets Jun 18 at 13:49
    
@DidacBusquets I don't think so. :( –  Harish Kumar Jun 18 at 22:22

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.