![使用 TeXgraph 更改比例](https://linux22.com/image/255383/%E4%BD%BF%E7%94%A8%20TeXgraph%20%E6%9B%B4%E6%94%B9%E6%AF%94%E4%BE%8B.png)
我在用着文字图创建图形和其他东西,有点懒,不想编写所有内容。我选择将代码导出tikz
到 以便使用tikzpicture
。如果我不需要缩放任何东西,结果会很棒,但是当涉及到缩放时,事情就不那么好了。
我尝试了内置的缩放选项tikzpicture
,但这不会缩放文本,因此显示效果不正确。然后我尝试使用命令\pgftransformscale
,这让情况有所改善,但它只给了我想要的效果,就与一起使用时的缩放而言\pgflowlevel
。但是位置不对,我不知道如何移动它。这里有一个简短的例子来说明我的意思。第一个是原始大小,第二个是较小的大小,比例因子为原来的一半
Soit le graphique suivant: \\
% TeXgraph version 1.97
\begin{tikzpicture}%
%\pgflowlevel{\pgftransformscale{0.5}}
\useasboundingbox (-5.5,-5.5)--(5.5,5.5);
%objet6 (Utilisateur)
%objet1 (Grille)
\pgfsetstrokecolor{rgb,1:red,0.7529;green,0.7529;blue,0.7529}
\pgfsetlinewidth{0.4pt}
\pgfsetroundjoin \pgfxyline(0,-5)(0,5)\pgfxyline(0.5,-5)(0.5,5)\pgfxyline(1,-5) (1,5)\pgfxyline(1.5,-5)(1.5,5)
\pgfxyline(2,-5)(2,5)\pgfxyline(2.5,-5)(2.5,5)\pgfxyline(3,-5)(3,5)\pgfxyline(3.5,-5)(3.5,5)
\pgfxyline(4,-5)(4,5)\pgfxyline(4.5,-5)(4.5,5)\pgfxyline(5,-5)(5,5)\pgfxyline(-0.5,-5)(-0.5,5)
\pgfxyline(-1,-5)(-1,5)\pgfxyline(-1.5,-5)(-1.5,5)\pgfxyline(-2,-5)(-2,5)\pgfxyline(-2.5,-5)(-2.5,5)
\pgfxyline(-3,-5)(-3,5)\pgfxyline(-3.5,-5)(-3.5,5)\pgfxyline(-4,-5)(-4,5)\pgfxyline(-4.5,-5)(-4.5,5)
\pgfxyline(-5,-5)(-5,5)\pgfxyline(-5,0)(5,0)\pgfxyline(-5,0.5)(5,0.5)\pgfxyline(-5,1)(5,1)
\pgfxyline(-5,1.5)(5,1.5)\pgfxyline(-5,2)(5,2)\pgfxyline(-5,2.5)(5,2.5)\pgfxyline(-5,3)(5,3)
\pgfxyline(-5,3.5)(5,3.5)\pgfxyline(-5,4)(5,4)\pgfxyline(-5,4.5)(5,4.5)\pgfxyline(-5,5)(5,5)
\pgfxyline(-5,-0.5)(5,-0.5)\pgfxyline(-5,-1)(5,-1)\pgfxyline(-5,-1.5)(5,-1.5)\pgfxyline(-5,-2)(5,-2)
\pgfxyline(-5,-2.5)(5,-2.5)\pgfxyline(-5,-3)(5,-3)\pgfxyline(-5,-3.5)(5,-3.5)\pgfxyline(-5,-4)(5,-4)
\pgfxyline(-5,-4.5)(5,-4.5)\pgfxyline(-5,-5)(5,-5)
%objet2 (Axes)
\pgfsetstrokecolor{rgb,1:red,0;green,0;blue,0}
\pgfxyline(-5,0)(5,0)\pgfxyline(0,-5)(0,5)
\pgfsetfillcolor{rgb,1:red,0;green,0;blue,0}
\pgfxyline(0,-0.1)(0,0.1)\pgfxyline(1,-0.1)(1,0.1)\pgfxyline(2,-0.1) (2,0.1)\pgfxyline(3,-0.1)(3,0.1)
\pgfxyline(4,-0.1)(4,0.1)\pgfxyline(5,-0.1)(5,0.1)
\pgfputat{\pgfxy(0.05,-0.2)}{\pgftext[top,left]{\small $0$}}
\pgfputat{\pgfxy(1,-0.2)}{\pgftext[top]{\small $1$}}
\pgfputat{\pgfxy(2,-0.2)}{\pgftext[top]{\small $2$}}
\pgfputat{\pgfxy(3,-0.2)}{\pgftext[top]{\small $3$}}
\pgfputat{\pgfxy(4,-0.2)}{\pgftext[top]{\small $4$}}
\pgfputat{\pgfxy(5,-0.2)}{\pgftext[top]{\small $5$}}
\pgfxyline(-1,-0.1)(-1,0.1)\pgfxyline(-2,-0.1)(-2,0.1)\pgfxyline(-3,-0.1)(-3,0.1)\pgfxyline(-4,-0.1)(-4,0.1)
\pgfxyline(-5,-0.1)(-5,0.1)
\pgfputat{\pgfxy(-1,-0.2)}{\pgftext[top]{\small $-1$}}
\pgfputat{\pgfxy(-2,-0.2)}{\pgftext[top]{\small $-2$}}
\pgfputat{\pgfxy(-3,-0.2)}{\pgftext[top]{\small $-3$}}
\pgfputat{\pgfxy(-4,-0.2)}{\pgftext[top]{\small $-4$}}
\pgfputat{\pgfxy(-5,-0.2)}{\pgftext[top]{\small $-5$}}
\pgfxyline(-0.1,0)(0.1,0)\pgfxyline(-0.1,1)(0.1,1)\pgfxyline(-0.1,2)(0.1,2)\pgfxyline(-0.1,3)(0.1,3)
\pgfxyline(-0.1,4)(0.1,4)\pgfxyline(-0.1,5)(0.1,5)
\pgfputat{\pgfxy(-0.2,0.05)}{\pgftext[right,bottom]{\small $0$}}
\pgfputat{\pgfxy(-0.2,1)}{\pgftext[right]{\small $1$}}
\pgfputat{\pgfxy(-0.2,2)}{\pgftext[right]{\small $2$}}
\pgfputat{\pgfxy(-0.2,3)}{\pgftext[right]{\small $3$}}
\pgfputat{\pgfxy(-0.2,4)}{\pgftext[right]{\small $4$}}
\pgfputat{\pgfxy(-0.2,5)}{\pgftext[right]{\small $5$}}
\pgfxyline(-0.1,-1)(0.1,-1)\pgfxyline(-0.1,-2)(0.1,-2)\pgfxyline(-0.1,-3)(0.1,-3)\pgfxyline(-0.1,-4)(0.1,-4)
\pgfxyline(-0.1,-5)(0.1,-5)
\pgfputat{\pgfxy(-0.2,-1)}{\pgftext[right]{\small $-1$}}
\pgfputat{\pgfxy(-0.2,-2)}{\pgftext[right]{\small $-2$}}
\pgfputat{\pgfxy(-0.2,-3)}{\pgftext[right]{\small $-3$}}
\pgfputat{\pgfxy(-0.2,-4)}{\pgftext[right]{\small $-4$}}
\pgfputat{\pgfxy(-0.2,-5)}{\pgftext[right]{\small $-5$}}
%D4 (Droite)
\pgfxyline(1,-5)(-5,1)
%D5 (Droite)
\pgfxyline(3,5)(-5,-3)
%objet5 (Droite)
\pgfxyline(-4,-5)(2.6667,5)
%bs (Point(s))
\pgfsetstrokecolor{rgb,1:red,0;green,0;blue,1}
\pgfsetfillcolor{rgb,1:red,0;green,0;blue,1}\pgfellipse[fillstroke]{\pgfxy(0,2)} {\pgfxy(0,0.0492)}{\pgfxy(-0.0492,0)}
\pgfellipse[fillstroke]{\pgfxy(0,1)}{\pgfxy(0,0.0492)}{\pgfxy(-0.0492,0)}
\pgfellipse[fillstroke]{\pgfxy(0,-4)}{\pgfxy(0,0.0492)}{\pgfxy(-0.0492,0)}
\pgfputat{\pgfxy(-4,1)}{\pgftext{\color{rgb,1:red,0;green,0;blue,0}\small $D4$}}\pgfstroke
\pgfputat{\pgfxy(-1,1.5)}{\pgftext{\color{rgb,1:red,0;green,0;blue,0}\small $D5$}}\pgfstroke
\pgfputat{\pgfxy(0.5,1)}{\pgftext{\color{rgb,1:red,0;green,0;blue,0}\small $D6$}}\pgfstroke
\end{tikzpicture}%
对于缩放的
Soit le graphique suivant: \\
% TeXgraph version 1.97
\begin{tikzpicture}%
\pgflowlevel{\pgftransformscale{0.5}}
\useasboundingbox (-5.5,-5.5)--(5.5,5.5);
%objet6 (Utilisateur)
%objet1 (Grille)
\pgfsetstrokecolor{rgb,1:red,0.7529;green,0.7529;blue,0.7529}
\pgfsetlinewidth{0.4pt}
\pgfsetroundjoin \pgfxyline(0,-5)(0,5)\pgfxyline(0.5,-5)(0.5,5)\pgfxyline(1,-5) (1,5)\pgfxyline(1.5,-5)(1.5,5)
\pgfxyline(2,-5)(2,5)\pgfxyline(2.5,-5)(2.5,5)\pgfxyline(3,-5)(3,5)\pgfxyline(3.5,-5)(3.5,5)
\pgfxyline(4,-5)(4,5)\pgfxyline(4.5,-5)(4.5,5)\pgfxyline(5,-5)(5,5)\pgfxyline(-0.5,-5)(-0.5,5)
\pgfxyline(-1,-5)(-1,5)\pgfxyline(-1.5,-5)(-1.5,5)\pgfxyline(-2,-5)(-2,5)\pgfxyline(-2.5,-5)(-2.5,5)
\pgfxyline(-3,-5)(-3,5)\pgfxyline(-3.5,-5)(-3.5,5)\pgfxyline(-4,-5)(-4,5)\pgfxyline(-4.5,-5)(-4.5,5)
\pgfxyline(-5,-5)(-5,5)\pgfxyline(-5,0)(5,0)\pgfxyline(-5,0.5)(5,0.5)\pgfxyline(-5,1)(5,1)
\pgfxyline(-5,1.5)(5,1.5)\pgfxyline(-5,2)(5,2)\pgfxyline(-5,2.5)(5,2.5)\pgfxyline(-5,3)(5,3)
\pgfxyline(-5,3.5)(5,3.5)\pgfxyline(-5,4)(5,4)\pgfxyline(-5,4.5)(5,4.5)\pgfxyline(-5,5)(5,5)
\pgfxyline(-5,-0.5)(5,-0.5)\pgfxyline(-5,-1)(5,-1)\pgfxyline(-5,-1.5)(5,-1.5)\pgfxyline(-5,-2)(5,-2)
\pgfxyline(-5,-2.5)(5,-2.5)\pgfxyline(-5,-3)(5,-3)\pgfxyline(-5,-3.5)(5,-3.5)\pgfxyline(-5,-4)(5,-4)
\pgfxyline(-5,-4.5)(5,-4.5)\pgfxyline(-5,-5)(5,-5)
%objet2 (Axes)
\pgfsetstrokecolor{rgb,1:red,0;green,0;blue,0}
\pgfxyline(-5,0)(5,0)\pgfxyline(0,-5)(0,5)
\pgfsetfillcolor{rgb,1:red,0;green,0;blue,0}
\pgfxyline(0,-0.1)(0,0.1)\pgfxyline(1,-0.1)(1,0.1)\pgfxyline(2,-0.1) (2,0.1)\pgfxyline(3,-0.1)(3,0.1)
\pgfxyline(4,-0.1)(4,0.1)\pgfxyline(5,-0.1)(5,0.1)
\pgfputat{\pgfxy(0.05,-0.2)}{\pgftext[top,left]{\small $0$}}
\pgfputat{\pgfxy(1,-0.2)}{\pgftext[top]{\small $1$}}
\pgfputat{\pgfxy(2,-0.2)}{\pgftext[top]{\small $2$}}
\pgfputat{\pgfxy(3,-0.2)}{\pgftext[top]{\small $3$}}
\pgfputat{\pgfxy(4,-0.2)}{\pgftext[top]{\small $4$}}
\pgfputat{\pgfxy(5,-0.2)}{\pgftext[top]{\small $5$}}
\pgfxyline(-1,-0.1)(-1,0.1)\pgfxyline(-2,-0.1)(-2,0.1)\pgfxyline(-3,-0.1)(-3,0.1)\pgfxyline(-4,-0.1)(-4,0.1)
\pgfxyline(-5,-0.1)(-5,0.1)
\pgfputat{\pgfxy(-1,-0.2)}{\pgftext[top]{\small $-1$}}
\pgfputat{\pgfxy(-2,-0.2)}{\pgftext[top]{\small $-2$}}
\pgfputat{\pgfxy(-3,-0.2)}{\pgftext[top]{\small $-3$}}
\pgfputat{\pgfxy(-4,-0.2)}{\pgftext[top]{\small $-4$}}
\pgfputat{\pgfxy(-5,-0.2)}{\pgftext[top]{\small $-5$}}
\pgfxyline(-0.1,0)(0.1,0)\pgfxyline(-0.1,1)(0.1,1)\pgfxyline(-0.1,2)(0.1,2)\pgfxyline(-0.1,3)(0.1,3)
\pgfxyline(-0.1,4)(0.1,4)\pgfxyline(-0.1,5)(0.1,5)
\pgfputat{\pgfxy(-0.2,0.05)}{\pgftext[right,bottom]{\small $0$}}
\pgfputat{\pgfxy(-0.2,1)}{\pgftext[right]{\small $1$}}
\pgfputat{\pgfxy(-0.2,2)}{\pgftext[right]{\small $2$}}
\pgfputat{\pgfxy(-0.2,3)}{\pgftext[right]{\small $3$}}
\pgfputat{\pgfxy(-0.2,4)}{\pgftext[right]{\small $4$}}
\pgfputat{\pgfxy(-0.2,5)}{\pgftext[right]{\small $5$}}
\pgfxyline(-0.1,-1)(0.1,-1)\pgfxyline(-0.1,-2)(0.1,-2)\pgfxyline(-0.1,-3)(0.1,-3)\pgfxyline(-0.1,-4)(0.1,-4)
\pgfxyline(-0.1,-5)(0.1,-5)
\pgfputat{\pgfxy(-0.2,-1)}{\pgftext[right]{\small $-1$}}
\pgfputat{\pgfxy(-0.2,-2)}{\pgftext[right]{\small $-2$}}
\pgfputat{\pgfxy(-0.2,-3)}{\pgftext[right]{\small $-3$}}
\pgfputat{\pgfxy(-0.2,-4)}{\pgftext[right]{\small $-4$}}
\pgfputat{\pgfxy(-0.2,-5)}{\pgftext[right]{\small $-5$}}
%D4 (Droite)
\pgfxyline(1,-5)(-5,1)
%D5 (Droite)
\pgfxyline(3,5)(-5,-3)
%objet5 (Droite)
\pgfxyline(-4,-5)(2.6667,5)
%bs (Point(s))
\pgfsetstrokecolor{rgb,1:red,0;green,0;blue,1}
\pgfsetfillcolor{rgb,1:red,0;green,0;blue,1}\pgfellipse[fillstroke]{\pgfxy(0,2)} {\pgfxy(0,0.0492)}{\pgfxy(-0.0492,0)}
\pgfellipse[fillstroke]{\pgfxy(0,1)}{\pgfxy(0,0.0492)}{\pgfxy(-0.0492,0)}
\pgfellipse[fillstroke]{\pgfxy(0,-4)}{\pgfxy(0,0.0492)}{\pgfxy(-0.0492,0)}
\pgfputat{\pgfxy(-4,1)}{\pgftext{\color{rgb,1:red,0;green,0;blue,0}\small $D4$}}\pgfstroke
\pgfputat{\pgfxy(-1,1.5)}{\pgftext{\color{rgb,1:red,0;green,0;blue,0}\small $D5$}}\pgfstroke
\pgfputat{\pgfxy(0.5,1)}{\pgftext{\color{rgb,1:red,0;green,0;blue,0}\small $D6$}}\pgfstroke
\end{tikzpicture}%
我想知道是否有办法移动渲染的对象,或者是否有另一种可以自行完成缩放的方法。
答案1
稍微改变一下比例,你就能得到一张合适的图片。因此,用下面的代码更改缩放图片的初始行。
\begin{tikzpicture}[baseline=(current bounding box.center),transform canvas={scale around={0.5:(5,-5)}}]% <- Changed
但我认为懒惰不是一个有效的借口,因为你已经体验过无法控制最终的图片,因此需要付出更多努力。事实上,通过以下方法做到这一点非常简单pgfplots
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\noindent Soit le graphique suivant:
\begin{tikzpicture}[mydot/.style={blue,inner sep=1pt,fill,circle}]
\begin{axis}[no marks,
xmin=-5,xmax=5,
ymin=-5,ymax=5,
grid=both,
axis lines=middle,
axis line style={-|},
xtick={-5,...,5},
ytick={-5,...,5},
minor tick num=1,
x=1cm,y=1cm
]
\addplot {x+2};
\addplot {1.5*x+1};
\addplot {-x-4};
\node[mydot] at (axis cs:0,1) {};
\node[mydot] at (axis cs:0,2) {};
\node[mydot] at (axis cs:0,-4) {};
\end{axis}
\end{tikzpicture}
\end{document}