gnuplot pdfcairo与latex字体大小匹配

gnuplot pdfcairo与latex字体大小匹配,latex,gnuplot,cairo,Latex,Gnuplot,Cairo,我使用带有pdfcairo终端的gnuplot 5.0绘制了一个pdf图形,然后使用latex将该图形插入到pdf文件中。然而,我发现gunplot中的字体大小与latex中的字体大小不同,尽管我将它们设置为相同 为了使gnuplot和latex中的字体大小一致,我必须将gnuplot中的fontscale设置为0.75,如下代码所示 gnuplot代码:以蓝色绘制“A”(Helvetica,尺寸12,fontscale 0.75) 乳胶代码:插入原尺寸的前一个图形,并在前一个“a”旁边写一个黑

我使用带有pdfcairo终端的gnuplot 5.0绘制了一个pdf图形,然后使用latex将该图形插入到pdf文件中。然而,我发现gunplot中的字体大小与latex中的字体大小不同,尽管我将它们设置为相同

为了使gnuplot和latex中的字体大小一致,我必须将gnuplot中的fontscale设置为0.75,如下代码所示

gnuplot代码:以蓝色绘制“A”(Helvetica,尺寸12,fontscale 0.75)

乳胶代码:插入原尺寸的前一个图形,并在前一个“a”旁边写一个黑色的“a”(Helvetica,尺寸12)

\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}
现在我们可以看到,在gnuplot设置“fontscale 0.75”下,这两个“A”的大小完全相同。我不明白为什么gnuplot中应该使用“fontscale 0.75”,而不是“fontscale 1”? 这是开罗的问题吗?有没有优雅的方法来处理这个字体大小的问题


简短回答:gnuplot使用72dpi,而cairo使用96dpi。(96/72=4/3)

注意:出于同样的原因,如果使用pngcairo,还应使用“fontscale 0.75”来获得正确的字体大小


替代方案:cairolatex@user8153

我认为这可能是因为cairo渲染。为了设置字体大小,Gnuplot使用提供的大小调用函数,在您的情况下为12。但是,这将转换为开罗单位:

以点为单位的字体大小,按PANGO_比例缩放。(即 10*PANGO_SCALE的大小值为10点字体。转换 点和设备单元之间的系数取决于系统配置 对于屏幕显示,逻辑DPI为96 通用,在这种情况下,10点字体对应10*(96/72) =13.3像素字体

此外,从函数
pango\u cairo\u font\u map\u set\u resolution
的文档中:

/**
 * pango_cairo_font_map_set_resolution:
 * @fontmap: a #PangoCairoFontMap
 * @dpi: the resolution in "dots per inch". (Physical inches aren't actually
 *   involved; the terminology is conventional.)
 *
 * Sets the resolution for the fontmap. This is a scale factor between
 * points specified in a #PangoFontDescription and Cairo units. The
 * default value is 96, meaning that a 10 point font will be 13
 * units high. (10 * 96. / 72. = 13.3).
 *
 * Since: 1.10
 **/

因此,总而言之,所提供的大小似乎是为了渲染目的乘以
96/72=4/3
,从而有效地生成大小为16而不是12的字体。然后应用的
0.75
比例因子将恢复此值。

并不是对您的问题的回答,但如果您希望匹配此值字体大小(以及文本呈现的所有其他方面)在您的图形中,您可以使用
cairolatex
终端,该终端将文本呈现留给latex。@user8153感谢您的建议。因为我也在其他地方使用图形,所以我需要在图形中显示文本。如果您愿意,您也可以使用
cairolatex
终端来执行此操作——您可以生成一个
独立的
latex文件然后在其上运行pdflatex,这可以从gnuplot脚本中执行。例如:
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”
其优点是,您可以获得各种Latex功能,并与其他Latex生成的文本保持一致。@user8153不错,我以前不知道这一点。谢谢。谢谢。我终于明白了。它可以将字体大小(以点为单位,以像素为单位)转换为开罗单位(以像素为单位),例如,10pt*(1/72英寸/英寸)*(96像素/英寸)=13.3像素,如您的答案所示。但是,。因此,这种不一致性导致字体大小更大,系数为4/3。
/**
 * pango_cairo_font_map_set_resolution:
 * @fontmap: a #PangoCairoFontMap
 * @dpi: the resolution in "dots per inch". (Physical inches aren't actually
 *   involved; the terminology is conventional.)
 *
 * Sets the resolution for the fontmap. This is a scale factor between
 * points specified in a #PangoFontDescription and Cairo units. The
 * default value is 96, meaning that a 10 point font will be 13
 * units high. (10 * 96. / 72. = 13.3).
 *
 * Since: 1.10
 **/