1

In a tex file, I need to draw a system diagram, so I put it in a separate tex like diagram.tex:

\documentclass[tikz]{standalone}
\usepackage{tikz}
\begin{document}
    \begin{tikzpicture}
        \draw (0,0) -- (1,1);
    \end{tikzpicture}
\end{document}

and then in main.tex:

\documentclass[10pt, a4paper]{article}
\usepackage[UTF8]{ctex}
\begin{document}
\section{sectionA}
\include{diagram} % I also tried input the same error. I wish diagram.tex figure could be inserted at this place.
\subsection{subsectionA}
\section{sectionB}
\end{document}

besides: running diagram.tex alone in latex gives:

! LaTeX Error: File `standalone.cls' not found.Type X to quit or <RETURN> to proceed,or enter new name. (Default extension: cls)Enter file name:! Emergency stop.<read > \usepackage

So the question would be how to insert a standalone tex file? And is it possible to run a standalone tex alone? I am also studying tikz, while demos I found are mostly using standalone.

Tiina
  • 491
  • I think the answer is in post : https://tex.stackexchange.com/questions/32127/standalone-tikz-pictures – Stan Feb 07 '18 at 07:18
  • it is possible (but unnecessarily complicated) to make that work but it is much simpler to just have the tikzpicture in a separate file (no \documentclass etc) then you can simply \input it. – David Carlisle Feb 07 '18 at 07:48
  • @DavidCarlisle make what work but complicated? – Tiina Feb 07 '18 at 08:16

1 Answers1

3
  • \documentclass[tikz]{standalone} load tikz, so it is not need to load it again with \usepackage{tikz}.

  • in main document you need to load

    • standalone for stripping out preamble in your diagra file
    • tikz with necessary tikz libraries

i.e. all packages used in included document.

so, your codes should be

\documentclass[tikz]{standalone}

\begin{document}
    \begin{tikzpicture}
        \draw (0,0) -- (1,1);
    \end{tikzpicture}
\end{document}

and

\documentclass[10pt, a4paper]{article}
\usepackage[UTF8]{ctex}
\usepackage{standalone} % <--- added
\usepackage{tikz}       % <--- added

\begin{document}
\section{sectionA}
    \input{diagram}     % <--- changed
\end{document}
Zarko
  • 296,517