如何设置 TikZ 图形大小和字体大小以匹配我的文档?

如何设置 TikZ 图形大小和字体大小以匹配我的文档?

经过一些配置噩梦之后,我设法将 GNU Octave 图(通过 gnuplot)打印出到 tikz-pgf 并将其显示在我的 LyX 文档中。

%& -shell-escape -enable-write18

\documentclass{article}

\usepackage{tikz}
\usepackage{gnuplot-lua-tikz}
\usetikzlibrary{shapes,arrows}

\begin{document}

\begin{tikzpicture}[gnuplot, scale = 1]

%% generated with GNUPLOT 4.6p0 (Lua 5.1; terminal rev. 99, script rev. 100)
%% Sun Jun 10 03:14:21 2012
\path (0.000,0.000) rectangle (8.000,6.000);
\gpcolor{color=gp lt color border}
\gpsetlinetype{gp lt border}
\gpsetlinewidth{0.50}
\draw[gp path] (1.012,0.985)--(1.263,0.985);
\draw[gp path] (7.447,0.985)--(7.196,0.985);
\gpcolor{rgb color={0.000,0.000,0.000}}
\node[gp node right,font={\fontsize{10pt}{12pt}\selectfont}] at (0.828,0.985) {0};
\gpcolor{color=gp lt color border}
\draw[gp path] (1.012,1.759)--(1.263,1.759);
\draw[gp path] (7.447,1.759)--(7.196,1.759);
\gpcolor{rgb color={0.000,0.000,0.000}}
\node[gp node right,font={\fontsize{10pt}{12pt}\selectfont}] at (0.828,1.759) {0.5};
\gpcolor{color=gp lt color border}
\draw[gp path] (1.012,2.534)--(1.263,2.534);
\draw[gp path] (7.447,2.534)--(7.196,2.534);
\gpcolor{rgb color={0.000,0.000,0.000}}
\node[gp node right,font={\fontsize{10pt}{12pt}\selectfont}] at (0.828,2.534) {1};
\gpcolor{color=gp lt color border}
\draw[gp path] (1.012,3.308)--(1.263,3.308);
\draw[gp path] (7.447,3.308)--(7.196,3.308);
\gpcolor{rgb color={0.000,0.000,0.000}}
\node[gp node right,font={\fontsize{10pt}{12pt}\selectfont}] at (0.828,3.308) {1.5};
\gpcolor{color=gp lt color border}
\draw[gp path] (1.012,4.082)--(1.263,4.082);
\draw[gp path] (7.447,4.082)--(7.196,4.082);
\gpcolor{rgb color={0.000,0.000,0.000}}
\node[gp node right,font={\fontsize{10pt}{12pt}\selectfont}] at (0.828,4.082) {2};
\gpcolor{color=gp lt color border}
\draw[gp path] (1.012,4.857)--(1.263,4.857);
\draw[gp path] (7.447,4.857)--(7.196,4.857);
\gpcolor{rgb color={0.000,0.000,0.000}}
\node[gp node right,font={\fontsize{10pt}{12pt}\selectfont}] at (0.828,4.857) {2.5};
\gpcolor{color=gp lt color border}
\draw[gp path] (1.012,5.631)--(1.263,5.631);
\draw[gp path] (7.447,5.631)--(7.196,5.631);
\gpcolor{rgb color={0.000,0.000,0.000}}
\node[gp node right,font={\fontsize{10pt}{12pt}\selectfont}] at (0.828,5.631) {3};
\gpcolor{color=gp lt color border}
\draw[gp path] (1.012,0.985)--(1.012,1.236);
\draw[gp path] (1.012,5.631)--(1.012,5.380);
\gpcolor{rgb color={0.000,0.000,0.000}}
\node[gp node center,font={\fontsize{10pt}{12pt}\selectfont}] at (1.012,0.677) {0};
\gpcolor{color=gp lt color border}
\draw[gp path] (2.085,0.985)--(2.085,1.236);
\draw[gp path] (2.085,5.631)--(2.085,5.380);
\gpcolor{rgb color={0.000,0.000,0.000}}
\node[gp node center,font={\fontsize{10pt}{12pt}\selectfont}] at (2.085,0.677) {0.5};
\gpcolor{color=gp lt color border}
\draw[gp path] (3.157,0.985)--(3.157,1.236);
\draw[gp path] (3.157,5.631)--(3.157,5.380);
\gpcolor{rgb color={0.000,0.000,0.000}}
\node[gp node center,font={\fontsize{10pt}{12pt}\selectfont}] at (3.157,0.677) {1};
\gpcolor{color=gp lt color border}
\draw[gp path] (4.230,0.985)--(4.230,1.236);
\draw[gp path] (4.230,5.631)--(4.230,5.380);
\gpcolor{rgb color={0.000,0.000,0.000}}
\node[gp node center,font={\fontsize{10pt}{12pt}\selectfont}] at (4.230,0.677) {1.5};
\gpcolor{color=gp lt color border}
\draw[gp path] (5.302,0.985)--(5.302,1.236);
\draw[gp path] (5.302,5.631)--(5.302,5.380);
\gpcolor{rgb color={0.000,0.000,0.000}}
\node[gp node center,font={\fontsize{10pt}{12pt}\selectfont}] at (5.302,0.677) {2};
\gpcolor{color=gp lt color border}
\draw[gp path] (6.375,0.985)--(6.375,1.236);
\draw[gp path] (6.375,5.631)--(6.375,5.380);
\gpcolor{rgb color={0.000,0.000,0.000}}
\node[gp node center,font={\fontsize{10pt}{12pt}\selectfont}] at (6.375,0.677) {2.5};
\gpcolor{color=gp lt color border}
\draw[gp path] (7.447,0.985)--(7.447,1.236);
\draw[gp path] (7.447,5.631)--(7.447,5.380);
\gpcolor{rgb color={0.000,0.000,0.000}}
\node[gp node center,font={\fontsize{10pt}{12pt}\selectfont}] at (7.447,0.677) {3};
\gpcolor{color=gp lt color border}
\draw[gp path] (1.012,5.631)--(1.012,0.985)--(7.447,0.985)--(7.447,5.631)--cycle;
\gpcolor{rgb color={0.000,0.000,0.000}}
\node[gp node center,font={\fontsize{12pt}{12pt}\selectfont}] at (4.229,0.215) {$\partial$};
\gpcolor{rgb color={0.000,0.000,1.000}}
\gpsetlinetype{gp lt plot 0}
\draw[gp path] (1.012,0.985)--(1.227,1.140)--(1.441,1.295)--(1.656,1.450)--(1.870,1.604)%
  --(2.085,1.759)--(2.299,1.914)--(2.514,2.069)--(2.728,2.224)--(2.943,2.379)--(3.157,2.534)%
  --(3.372,2.689)--(3.586,2.843)--(3.801,2.998)--(4.015,3.153)--(4.230,3.308)--(4.444,3.463)%
  --(4.659,3.618)--(4.873,3.773)--(5.088,3.927)--(5.302,4.082)--(5.517,4.237)--(5.731,4.392)%
  --(5.946,4.547)--(6.160,4.702)--(6.375,4.857)--(6.589,5.012)--(6.804,5.166)--(7.018,5.321)%
  --(7.233,5.476)--(7.447,5.631);
%% coordinates of the plot area
\gpdefrectangularnode{gp plot 1}{\pgfpoint{1.012cm}{0.985cm}}{\pgfpoint{7.447cm}{5.631cm}}
\end{tikzpicture}
%% gnuplot variables


\end{document}

在此处输入图片描述

现在我有两个问题:

  • 如何缩放整个图像,使其宽度与我的 LyX 文本宽度相匹配?
  • 如何根据 LyX 文本字体大小的倍数设置图形的字体大小?

非常感谢您的帮助。

答案1

你可以尝试这个

\documentclass{article}

\usepackage{tikz}
\usepackage{lipsum}

\begin{document}

\lipsum[1]
\noindent\begin{tikzpicture}[ xscale = \textwidth/8cm]
\path[draw] (0.000,0.000) rectangle (8.000,6.000);

\end{tikzpicture}

\lipsum[1]

\end{document}

在此处输入图片描述

答案2

有些软件包可能会对你有所帮助。我最近发现并喜欢的一个用于扩展的软件包是adjustbox因为它还允许像最大宽度,例如,仅当图像过大时才缩放。但是,为了在缩放时保持字体大小,我建议使用tikzscale

关于适配库有一些限制,但您可能想尝试一下。

使用 rpapas 示例,它将看起来像这样:

\documentclass{article}

\usepackage{tikz}
\usepackage{lipsum}
\usepackage{tikzscale}
\begin{document}

\lipsum[1]
\noindent\resizebox{\linewidth}{!}{\input{linewidth.tikz}}

\lipsum[1]

\end{document}

线宽.tikz

\begin{tikzpicture}
\path[draw] (0,0) rectangle (8,6);
\node at (4,3){cheese};    
\end{tikzpicture}

这样做的一个缺点是(据我所知) tikz 图片必须放在外部文件中并且必须具有扩展名.tikz,但是您不需要知道图片的边界框。

相关内容