我正在尝试调整下图的大小。我已经为一个文档制作了该图。现在我想在另一个文档中重复使用该代码,但我需要将图缩小。我尝试了许多调整大小的命令,甚至使用了 minipage(在代码的不同部分),但都不起作用。非常感谢您的帮助。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{pgf,tikz}
\usetikzlibrary{positioning,calc,chains,fit,shapes,arrows}
\begin{document}
\begin{figure}
\begin{center}
\definecolor{xdxdff}{rgb}{0.49019607843137253,0.49019607843137253,1}
\definecolor{ududff}{rgb}{0.30196078431372547,0.30196078431372547,1}
\definecolor{cqcqcq}{rgb}{0.7529411764705882,0.7529411764705882,0.7529411764705882}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1cm,y=1cm]
\draw [color=cqcqcq,, xstep=1cm,ystep=1cm] (-1.52,-1.25) grid (7.52,7.25);
\clip(-1.52,-1.25) rectangle (6.52,6.25);
\draw [line width=2pt] (3,3) circle (2.8cm);
\draw [->,line width=2pt] (3,3) -- (5.669424238929763,3.845088298708634);
\draw (3.58,4.02) node[anchor=north west] {$\sqrt n$};
\draw (1,6) node[anchor=north west] {$C$};
\draw[thick,->] (-1,3) -- (6.5,3) node[anchor=north west] {};
\draw[thick,->] (3,-1) -- (3,6.2) node[anchor=south east] {};
\begin{scriptsize}
\draw [fill=ududff] (3,3) circle (2.5pt);
\draw [fill=xdxdff] (5.669424238929763,3.845088298708634) circle (2.5pt);
\end{scriptsize}
\end{tikzpicture}
\end{center}
\end{figure}
\end{document}
答案1
我有一种预感,\scalebox
和\resizebox
——这两个宏都是由graphicx
包提供的——就是你要找的。前一个宏将其主要参数按一个因子缩放,相对于对象的“自然大小”。后一个宏将其主要参数缩放为绝对大小。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx,amsmath}
\usepackage{pgf,tikz}
\usetikzlibrary{positioning,calc,chains,fit,shapes,arrows}
\definecolor{xdxdff}{rgb}{0.490,0.490,1}
\definecolor{ududff}{rgb}{0.302,0.302,1}
\definecolor{cqcqcq}{rgb}{0.753,0.753,0.753}
\newcommand\mypic{%
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45, x=1cm, y=1cm]
\draw [color=cqcqcq,, xstep=1cm, ystep=1cm] (-1.52,-1.25) grid (7.52,7.25);
\clip(-1.52,-1.25) rectangle (6.52,6.25);
\draw [line width=2pt] (3,3) circle (2.8cm);
\draw [->,line width=2pt] (3,3) -- (5.669,3.845);
\draw (3.58,4.02) node[anchor=north west] {$\sqrt n$};
\draw (1,6) node[anchor=north west] {$C$};
\draw[thick,->] (-1,3) -- (6.5,3) node[anchor=north west] {};
\draw[thick,->] (3,-1) -- (3,6.2) node[anchor=south east] {};
\begin{scriptsize}
\draw [fill=ududff] (3,3) circle (2.5pt);
\draw [fill=xdxdff] (5.669,3.845) circle (2.5pt);
\end{scriptsize}
\end{tikzpicture}}
\begin{document}
\begin{figure}
\centering
\mypic % no scaling, i.e., display pic at its "natural" size
\scalebox{0.25}{\mypic} % scale down to 1/4 of natural size
\resizebox{5cm}{!}{\mypic} % "!" means: vertical scale same as horiz. scale
\end{figure}
\end{document}