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.

  • I think the answer is in post : tex.stackexchange.com/questions/32127/standalone-tikz-pictures – Stan Feb 7 '18 at 7: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 7 '18 at 7:48
  • @DavidCarlisle make what work but complicated? – Tiina Feb 7 '18 at 8:16
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}
  • are you suggesting using input instead of include – Tiina Feb 7 '18 at 8:38
  • @Tiina, yes. i assume, that included file should not start on new page (this happens with \include). – Zarko Feb 7 '18 at 8:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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