1

I try to create a PDF which is 156 pt x 85 pt large, with text at sizes 9 pt and 11 pt, using the following .tex file:

%!TEX TS-program = xelatex
\documentclass[border=0pt]{standalone}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[no-math]{fontspec}
\usepackage{tikz}
\newcommand{\FigureWidthPt}{156}
\newcommand{\FigureHeightPt}{85}
\newcommand{\fontSizeNine}{9}
\newcommand{\fontSizeEleven}{11}
\begin{document}
\begin{tikzpicture}[]
\draw[red, line width=0.0pt, fill=none, opacity=1.0]
    (-\FigureWidthPt/2 pt, -\FigureHeightPt/2 pt) 
    rectangle 
    +(\FigureWidthPt pt, \FigureHeightPt pt);
\draw[inner sep=0, outer sep=0, anchor=north west]
    (-\FigureWidthPt/2 pt, \FigureHeightPt/2 pt) node[color=black]
    {\fontsize{\fontSizeNine pt}{\fontSizeNine pt + 2 pt}\selectfont
    test nine
    };
\draw[inner sep=0, outer sep=0, anchor=north west]
    (-\FigureWidthPt/2 pt, \FigureHeightPt/2 pt - 20 pt) node[color=black]
    {\fontsize{\fontSizeEleven pt}{\fontSizeEleven pt + 2 pt}\selectfont
    test 11
    };
\end{tikzpicture}
\end{document}

However, when opening up the PDF with Adobe Acrobat or Illustrator, the artboard is 155.62 pt x 84.88 pt large (155 pt x 84 pt with size read with "Get Info"), and the fonts are read as 8.97 pt and 10.96 pt, respectively.

Is it possible to get these point-perfect e.g. by change of default units in tikz, or by some other means?

I tried opening tikzpicture with \begin{tikzpicture}[x=1pt, y=1pt] without change.

  • To add information, decided to cross-check with Inkscape as a sanity check. It gives 155.62000 pt x 84.88000 pt for the outline, and 8.966400 pt for the text created with \fontSizeNine, and 10.95890 pt for the text created with \fontSizeEleven. At least there is no difference between programs here. And seems like the outline has a precision of 2 digits after decimal point, while font sizes have a precision of 4 digits after decimal points. – fermionic Nov 26 '22 at 10:39
  • This then leads to a hacky solution, where the following definitions \newcommand{\FigureWidthPt}{156.39}, \newcommand{\FigureHeightPt}{85.12}, \newcommand{\fontSizeNine}{9.0336}, \newcommand{\fontSizeEleven}{11.0411} lead to the desired result (still not sure why we need 156.39 and not 156.44). That is, after creating the figure with the initial, desired dimensions and font sizes, we recreate it with compensated dimensions after measuring the imprecision. – fermionic Nov 26 '22 at 10:43
  • I might add that seemingly the font size imprecision does not depend on 1. the figure size, 2. the font family. For example, the default latex font is substituted when opened up in an Adobe or Inkscape program (except for Acrobat), and the result is independent of the substituted family. Likewise, I tried a variant of the above .tex file with fontspec and the MyriadPro font (which is on Adobe programs), with identical font size result. – fermionic Nov 26 '22 at 10:52
  • Isn't there a difference between pt in LaTeX and pt outside it? In LaTeX, 1 inch = 72.27 pts and outside it 1 inch = 72 pts. Your problem might come from this difference. – Daniel N Nov 26 '22 at 13:24

2 Answers2

0

2 factors here.

  • If you want to match Adobe's pt, you need to use bp instead of pt unit in TeX. Refer to Why does a TeX point differ from a Desktop Publishing point?.

  • If you use \draw then TikZ will consider a "point" to be put at the coordinate, even if no line is actually drawn. (presumably.)

    For example in the following code

    \documentclass[border=0pt]{standalone}
    \usepackage{tikz}
    \newcommand{\FigureWidthPt}{156}
    \newcommand{\FigureHeightPt}{85}
    \begin{document}
    \begin{tikzpicture}
    \draw[
    red, line width=0.0pt, fill=none, opacity=1.0]
        (-\FigureWidthPt/2 pt, -\FigureHeightPt/2 pt) 
        rectangle 
        +(\FigureWidthPt pt, \FigureHeightPt pt);
    

    \draw (-\FigureWidthPt/2 pt, \FigureHeightPt/2 pt); % try commenting out this line or add line width=0pt

    \end{tikzpicture} \end{document}

    commenting out the marked line makes the frame slightly smaller.

  • Nevertheless, an easy way to force the TikZ image to have a particular size is the use as bounding box key (source https://tex.stackexchange.com/a/94723/250119 Zero-width text node in tikz)

    \path[use as bounding box] (-\FigureWidthPt/2 bp, -\FigureHeightPt/2 bp) rectangle +(\FigureWidthPt bp, \FigureHeightPt bp);
    
user202729
  • 7,143
  • Thank you for the answer and information. This is exactly the type of answer I was hoping was true : ) Using bp instead of pt solves both the outline and font sizes, apart from the extra width from the point, as you point out. I will accept but just add the full modified .tex file below for clarity. – fermionic Nov 26 '22 at 14:42
0

For completeness, the below modified .tex file has the correct outline size and font sizes. As user202729 and Daniel N point out, using bp instead of pt creates point sizes compatible with Adobe and Inkscape ("Desktop Publishing Point").

%!TEX TS-program = xelatex
\documentclass[border=0]{standalone}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[no-math]{fontspec}
\usepackage{tikz}
\newcommand{\FigureWidthPt}{156}
\newcommand{\FigureHeightPt}{85}
\newcommand{\fontSizeNine}{9}
\newcommand{\fontSizeEleven}{11}
\begin{document}
\begin{tikzpicture}[]
\path[use as bounding box] 
    (-\FigureWidthPt/2 bp, -\FigureHeightPt/2 bp) 
    rectangle +(\FigureWidthPt bp, \FigureHeightPt bp);
\draw[inner sep=0, outer sep=0, anchor=north west]
    (-\FigureWidthPt/2 bp, \FigureHeightPt/2 bp) node[color=black]
    {\fontsize{\fontSizeNine bp}{\fontSizeNine bp + 2 bp}\selectfont
    test nine
    };
\draw[inner sep=0, outer sep=0, anchor=north west]
    (-\FigureWidthPt/2 bp, \FigureHeightPt/2 bp - 20 bp) node[color=black]
    {\fontsize{\fontSizeEleven bp}{\fontSizeEleven bp + 2 bp}\selectfont
    test 11
    };
\end{tikzpicture}
\end{document}