1

I display some nearly full page tikz(square BB's) and would like to crop the page to the image in the pdf because there is a lot of wasted space that reduces ability to show the image in higher detail.

I've only seen how to crop importing images/pdf's but nothing "inline" or it seems to do it to the entire document(I only want to do the page that the image is on).

I have a figure using p and would simply like to crop/fit the page dimensions to it(= a small margin of a few mm or so) and I do not want to have to hard code the crop dimensions or positions.

6
  • There is a program pdfcrop that should do exactly this... ctan.org/pkg/pdfcrop?lang=en; or you can generate the drawing with the class standalone.
    – Rmano
    Sep 23, 2019 at 11:14
  • @Rmano I do not have perl or GS installed and I see no reason why I have to go outside of latex to do it. I simply want to change the page dimensions to fit the generated figure. Standalone does it but that does it for every page. I want to do it per figure/tikzpicture.
    – user184375
    Sep 23, 2019 at 11:26
  • So I am not sure I have understand correctly your question, sorry. Can you post an MWE?
    – Rmano
    Sep 23, 2019 at 11:38
  • @Rmano I don't see how hard it is as I just want to crop a tikzpicture... like \crop{\begin{tikzpicture}...\end{tikzpicture}} and the page will have no extra space(maybe small margin) that is wasted outside the imagine. It is on it's own page. It is not difficult.
    – user184375
    Sep 23, 2019 at 13:43
  • 2
    If it's not difficult why are you asking it? And why aren't you putting up an MWE? Still, I don't understand. Do you want a) crop an external figure b) change the page margins to fill it (check \newgeometry from geometry package) or c) something else? A ` \begin{tikzpicture}...\end{tikzpicture}` is already cropped to its minimum bounding box (unless you have beziers curves near the borders, but that's another problem).
    – Rmano
    Sep 23, 2019 at 13:54

2 Answers 2

0

incgraph package could be an option. It defines commands and environments to include external or internal graphics on full paper size. It means that graphics are presented on an independent page which defined size or just resized to the graphic's dimensions. An example:

\documentclass[a4paper]{article}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{incgraph}

\begin{document}

\lipsum[1-6]

\begin{inctext}[paper=graphics,label={inctext1},bookmark={A huge ABC}]
\Huge Some important text.
\end{inctext}

\begin{inctext}[paper=graphics,landscape,label={inctext2},bookmark={Graph}]
\begin{tikzpicture}[scale=10]
\path[fill=yellow,draw=yellow!75!red] (0,0) circle (1cm);
\fill[red] (45:5mm) circle (1mm);
\fill[red] (135:5mm) circle (1mm);
\draw[line width=1mm,red] (215:5mm) arc (215:325:5mm);
\end{tikzpicture}
\end{inctext}

\lipsum[7-10]

\end{document}

enter image description here

5
  • Thanks, this does work. \thispagestyle{empty} adds space and is not needed. figure environment doesn't work(gives errors). I wonder if it can be made to work so one can create side by side figures(I guess not needed with tikz all that much but it would be nice to know why it is not working with figure).
    – user184375
    Sep 23, 2019 at 17:10
  • @Chieron figure is a floating object and incgraph doesn't know what to do with them. In any case if you provides us an example showing what you want to do we will better help you.
    – Ignasi
    Sep 24, 2019 at 8:33
  • you've already done it... but the only thing is that I might not always want to crop like that(it is a special case for creating animations). So I need to create a command that will use figure or incgraph.
    – user184375
    Sep 24, 2019 at 10:45
  • @Chieron let me insist that we need an e ample. And as you already accepte this answer, it would be better to open a new qüestions.
    – Ignasi
    Sep 24, 2019 at 11:56
  • You are making it far more complicated than it is... you already have an example. Add a figure around your tikzpicture... it breaks incgraph... I want both features. I will not always be using incgraph. It is for specific things I do some oof the time. I don't want to have to retype everything. Flip a switch and it should go from incgraph to figure and flip it back and it goes back. Hence a command should work.
    – user184375
    Sep 24, 2019 at 13:40
0

There are two ways i found of achieving something "related" to this question. To export the image from the document to a full scale pdf (which could then be included in the pdf, yes, those will be 3 steps, but, thats a result) First is the use of preview:

% A calendar of circles
% Author: Till Tantau (The PGF manual),
%   and Stefan Kottwitz (Modifications such as shaded circles and color)
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calendar,shadings}
\renewcommand*{\familydefault}{\sfdefault}
\colorlet{winter}{blue}
\colorlet{spring}{green!60!black}
\colorlet{summer}{orange}
\colorlet{fall}{red}

\usepackage[active, tightpage]{preview}
\setlength\PreviewBorder{10pt}%

% A counter, since TikZ is not clever enough (yet) to handle
% arbitrary angle systems.
\newcount\mycount
\begin{document}
    \begin{preview}
    \begin{tikzpicture}[transform shape,
    every day/.style={anchor=mid,font=\tiny}]
    \node[circle,shading=radial,outer color=blue!30,inner color=white,
    minimum width=15cm] {\textcolor{blue!80!black}{\Huge\the\year}};
    \foreach \month/\monthcolor in
    {1/winter,2/winter,3/spring,4/spring,5/spring,6/summer,
        7/summer,8/summer,9/fall,10/fall,11/fall,12/winter} {
        % Computer angle:
        \mycount=\month
        \advance\mycount by -1
        \multiply\mycount by 30
        \advance\mycount by -90
        \shadedraw[shading=radial,outer color=\monthcolor!30,middle color=white,
        inner color=white,draw=none] (\the\mycount:5.4cm) circle(1.4cm);
        % The actual calendar
        \calendar at (\the\mycount:5.4cm) [
        dates=\the\year-\month-01 to \the\year-\month-last]
        if (day of month=1) {\large\color{\monthcolor!50!black}\tikzmonthcode}
        if (Sunday) [red]
        if (all) {
            % Again, compute angle
            \mycount=1
            \advance\mycount by -\pgfcalendarcurrentday
            \multiply\mycount by 11
            \advance\mycount by 90
            \pgftransformshift{\pgfpointpolar{\mycount}{1.2cm}}};}
    \end{tikzpicture}
    \end{preview}
\end{document}

Used this blogpost: https://texblog.org/2012/09/12/cropping-the-output-file-to-its-content-in-latex/ And this texample: http://www.texample.net/tikz/examples/calendar-circles/

The package used is the preview package.

Result The second is to externalize the tikz pictures. Found here Script to automate externalizing TikZ graphics <- selected answer

Both work great i think. There are possibly easy ways to create macros for the first run: create the external PDFs, and a second run, adding the PDFs to the resulting PDF instead of generating the tikzpictures on the fly.

You must log in to answer this question.