I plot a pdf figure using gnuplot 5.0 with pdfcairo terminal, and then insert this figure into a pdf file using latex. However, I found the font size in gunplot is different with the font size in latex, although I set them to be the same.
To make the font size consistent in gnuplot and latex, I have to set the fontscale in gnuplot as 0.75, as shown in the following codes.
gnuplot codes: plot an 'A' in blue (Helvetica, size 12, fontscale 0.75).
set terminal pdfcairo font 'Helvetica,12' size 1cm,1cm fontscale 0.75
set output 'test0.pdf'
set xrange [-1:1]
set yrange [-1:1]
unset xtics
unset ytics
unset border
set label 'A' at 0,0 textcolor 'blue'
p 1/0 notitle
Latex codes: insert the previous figure in original size, and write a black 'A' (Helvetica, size 12) next to the previous 'A'.
\documentclass[12pt]{standalone}
\usepackage{tikz}
\usepackage{helvet}
\usepackage{graphicx}
\begin{document}
\begin{tikzpicture}
\node at (0,0) {\includegraphics{test0.pdf}};
\node at (0.3, -0.025) {\textsf{A}};
\end{tikzpicture}
\end{document}
You can see the final pdf file here. Now we can see these two 'A' are exactly the same size under the gnuplot setting 'fontscale 0.75'. I don't understand why 'fontscale 0.75' should be used in gnuplot, not 'fontscale 1'? Is this a problem of cairo? And is there any elegant way to deal with this font size issue?
Short answer: gnuplot uses 72dpi, while cairo uses 96dpi. (96/72=4/3)
Note: For the same reason, if using pngcairo, 'fontscale 0.75' should also be used to get the right font size.
Alternative solution: cairolatex. @user8153
cairolatex
terminal, which leaves the text rendering to latex. – Leucopeniacairolatex
as well -- you generate astandalone
latex file and then run pdflatex over it, which you can do from within the gnuplot script. For example:set term cairolatex pdf standalone header "\\usepackage{amsmath}" font ",9" size 3.4167in,2in; set outp "test.tex"; plot sin(x); set outp; system "pdflatex test.tex"
The advantage is that you get the full range of Latex abilities and consistency with other, Latex-generated text. – Leucopenia