When exporting a tikzpicture to its own pdf file for publications, I want to be able to specify the exact size and resolution of the exported pdf file. Specifically 8.5 cm wide and 600 dpi images.
MWE:
\documentclass[12pt]{standalone}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,arrows.meta,external}
\tikzexternalize
\begin{document}
\resizebox{8.5cm}{!}{
\begin{tikzpicture}
%some drawing here
\end{tikzpicture}
}
\end{document}
Then use pdflatex -shell-escape TikzFigure.pdf
to create the figure.
Best Answer
Resolution
TikZ is by nature a vector graphics system and the generated PDF file keeps this property. Of course, bitmap images can be included and used in the TikZ graphics. But TeX is not an program with capabilities for image processing. It only can include bitmap images and can do some transformations (e.g. scale, rotate). But it cannot change the image data. Therefore, the image resolution cannot be changed.
Scale to final width
The following hacks into internals of
pgf
to access the picture box, before it is typeset. At the beginning of\pgfsys@typesetpicturebox
, the picture box\pgfpic
has size zero and the origin of the picture is the reference point of the box. The dimensions of the picture are provided by other registers\pgf@picminx
,\pgfpicminy
, ... They can be used to calculate the actual with and then the scale factor. The box is then resized by the scale factor and the registers are updated according to the scale factor.Example:
The
.log
file contains the calculated scale factor: 4.22034