12

I'm trying to draw in tikz.

The aim is to create a document with a first page with the title and other infos. Each of the other page is a wiremap a of type of cable.

I use python to generate the tex code. And I need to start a new page between each wiremap (between each tikzpicture).

So I tried to use a simple newpage, but MikTeX says to me this error:

! Missing \endgroup inserted.
<inserted text>
            \endgroup
l.12 \newpage

?

My TeX file is:

\documentclass[a4paper,class=article,border=0pt]{standalone}
\usepackage{tikz}
%
\begin{document}
%
\begin{tikzpicture}
\clip (0,0) rectangle (21,29.7);
\draw[red] (0,0) -- (21,29.7);
\draw[red] (1,0) -- (0,1);
\draw[blue] (0,0) rectangle (21,29.7);
\draw[green] (1,1) rectangle (20,28.7);
\end{tikzpicture}
\newpage
\begin{tikzpicture}
\clip (0,0) rectangle (21,29.7);
\draw[blue] (1,1) rectangle (20,28.7);
\end{tikzpicture}
%
\end{document}
4
  • 7
    You need the option tikz or multi: \documentclass[a4paper,class=article,border=0pt,tikz]{standalone} Sep 16, 2013 at 17:08
  • 1
    @Ulrike Fischer today it's the third time that when I'm trying to write a comment, at the same moment the answer in my mind is written by someone faster than me! :-)
    – TheVal
    Sep 16, 2013 at 17:09
  • 1
    @UlrikeFischer It is great. This should be written as an answer.
    – hengxin
    Aug 4, 2015 at 3:26
  • 1
    @UlrikeFischer In such case, the tikz pictures are automatically appearing in separated pages, which means the command \newpage is not needed.
    – wayne
    Jun 16, 2016 at 8:38

3 Answers 3

4

I provide a simple method to control page breaks in the standalone class.

All pictures in the same page

As a MWE I take the following code, based on the question, where three pictures are generated in the same page.

enter image description here

\documentclass[a4paper,class=article,border=0pt]{standalone}
\usepackage{tikz}
\begin{document}
%
\begin{tikzpicture}
\clip (0,0) rectangle (21,29.7);
\draw[red] (0,0) -- (21,29.7);
\draw[red] (1,0) -- (0,1);
\draw[blue] (0,0) rectangle (21,29.7);
\draw[green] (1,1) rectangle (20,28.7);
\end{tikzpicture}
%
\begin{tikzpicture}
\clip (0,0) rectangle (21,29.7);
\draw[blue] (1,1) rectangle (20,28.7);
\end{tikzpicture}
%
\begin{tikzpicture}
\clip (0,0) rectangle (21,29.7);
\draw[red] (1,1) rectangle (20,28.7);
\end{tikzpicture}
%
\end{document}

Each picture in a different page

Taking @Ulrike Fischer's solution, which is just adding the option tikz to the document class, i.e., changing the line \documentclass[a4paper,class=article,border=0pt]{standalone} by \documentclass[a4paper,class=article,border=0pt,tikz]{standalone} each picture appears in a different page.

enter image description here

Total Control of Page Breaks

If we want to arbitrarily insert page breaks between the pictures. For example, to put one picture in the first page and two pictures together in the last page. We can generate a dummy environment, e.g., standalonepage and group the pictures that belong to the same page. As in the example before.

enter image description here

\documentclass[a4paper,class=article,border=0pt]{standalone}
\usepackage{tikz}
%
\newenvironment{standalonepage}{}{} %Dummy environment that contains pictures in the same page
\standaloneenv{standalonepage} %The dummy environment is make known to the stand alone class
\begin{document}

%First Page
\begin{standalonepage}
  \begin{tikzpicture}
    \clip (0,0) rectangle (21,29.7);
    \draw[red] (0,0) -- (21,29.7);
    \draw[red] (1,0) -- (0,1);
    \draw[blue] (0,0) rectangle (21,29.7);
    \draw[green] (1,1) rectangle (20,28.7);
  \end{tikzpicture}
\end{standalonepage}

%Second Page
\begin{standalonepage}
  \begin{tikzpicture}
    \clip (0,0) rectangle (21,29.7);
    \draw[blue] (1,1) rectangle (20,28.7);
  \end{tikzpicture}

  \begin{tikzpicture}
    \clip (0,0) rectangle (21,29.7);
    \draw[red] (1,1) rectangle (20,28.7);
  \end{tikzpicture}
\end{standalonepage}

\end{document}
3

An alternative solution for this kind of document could be incgraph. Its documentation abstract says:

incgraph provides tools for including graphics on full paper size. The graphics can be centered for a given paper format or the paper may be resized to the graphics dimensions. The main use case for the package incgraph is to transform one or many scans or taken pictures to a PDF document. It can also be applied for full paper size LaTeX created graphics. The package incgraph provides a tool box with basic macros and a convenience user interface which wraps the well-known includegraphics. Also, bookmarking is especially supported.

As an alternative to standalone in this particular case offers the advantage of having the whole document (title page and figures) in a unique .tex file.

As it's shown in following example, TikZ figures can be included and they keep it's own size or can be included into a formal page.

\documentclass[a4paper]{article}
\usepackage{tikz}
\usepackage{incgraph}
%
\title{Cable catalogue}
\author{Anonymous}

\begin{document}

\maketitle

%
\begin{inctext}
\begin{tikzpicture}
\draw[red] (0,0) -- (21,29.7);
\draw[red] (1,0) -- (0,1);
\draw[blue] (0,0) rectangle (21,29.7);
\draw[green] (1,1) rectangle (20,28.7);
\end{tikzpicture}
\end{inctext}

\begin{inctext}[currentpaper]
\begin{tikzpicture}
\draw[blue] (1,1) rectangle (5,8);
\end{tikzpicture}
\end{inctext}

\begin{inctext}[border=1cm]
\begin{tikzpicture}
\draw[blue] (1,1) rectangle (5,8);
\end{tikzpicture}
\end{inctext}

\begin{inctext}[border=3mm]
\begin{tikzpicture}
\draw[blue] circle (3cm);
\end{tikzpicture}
\end{inctext}

\incgraph{frog.jpg}
\end{document}

enter image description here

2

The following code simulates your case. Compile the following with pdflatex -shell-escape main.tex.

% main.tex
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{figure.tex}
\documentclass[tikz,multi]{standalone}

\begin{document}

\begin{tikzpicture}
\clip (0,0) rectangle (21,29.7);
\draw[red] (0,0) -- (21,29.7);
\draw[red] (1,0) -- (0,1);
\draw[blue] (0,0) rectangle (21,29.7);
\draw[green] (1,1) rectangle (20,28.7);
\end{tikzpicture}

\begin{tikzpicture}
\clip (0,0) rectangle (21,29.7);
\draw[blue] (1,1) rectangle (20,28.7);
\end{tikzpicture}

\end{document}
\end{filecontents*}

\usepackage{graphicx}
\immediate\write18{pdflatex figure}


\title{My title}
\author{I am}
\date{\today}

\newcommand{\Insert}[2][1]{\includegraphics[scale=#1,page=#2]{figure}\newpage}

\begin{document}
\maketitle

\Insert[0.5]{1}
\Insert[0.5]{2}
\end{document}
1
  • Thank you for your answer. But the page don't fill the whole a4paper. If I change the scale to 1.0 instead of 0.5, the picture isn't centered. Best Regards. Doom
    – doom
    Sep 20, 2013 at 8:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .