我想在图形环境中缩放 tikzpicture。生成缩放图形的代码:
\documentclass[11pt,a4paper]{article}
\usepackage{ifthen}
\usepackage{tikz}
\usepackage{tikzscale}
\tikzstyle{ball} = [circle,shading=ball, ball color=blue!60!white]
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[scale=0.5]
\pgflowlevelsynccm
\foreach \a in {1,...,6}
{
\node[style=ball] (r\a) at (1.5*\a,0) {\textcolor{yellow}{$\mu_\a$}};
\draw[very thick] (r\a)--(1.5*\a,1.75);
\draw[very thick] (r\a)--(1.5*\a,-1.75);
\ifthenelse{\a = 6}
{}
{\draw[very thick] (r\a)--(1.5+1.5*\a,0);}
}
\draw[line width=5mm,draw=green] (0.5,-1) rectangle (10,1);
\end{tikzpicture}
\caption{M1} \label{fig:M1}
\end{figure}
\end{document}
有没有办法解决?
另外,是否可以使用类似方法根据文本宽度重新调整 tikzpicture 的大小
0.5\textwidth
?
答案1
对于重新缩放,一般来说,您可以使用resizebox
(来自graphicx
包)的,它也适用于tikzpicture
。第一个参数是宽度,第二个参数是高度,或者!
按比例缩放。使用resizebox
您不需要坐标变换,这似乎会导致您的示例中的重叠。
梅威瑟:
\documentclass[11pt,a4paper]{article}
\usepackage{ifthen}
\usepackage{tikz}
%\usepackage{tikzscale}
\tikzstyle{ball} = [circle,shading=ball, ball color=blue!60!white]
\begin{document}
\begin{figure}
\centering
\resizebox{0.3\textwidth}{!}{
\begin{tikzpicture}
%\pgflowlevelsynccm
\foreach \a in {1,...,6}
{
\node[style=ball] (r\a) at (1.5*\a,0) {\textcolor{yellow}{$\mu_\a$}};
\draw[very thick] (r\a)--(1.5*\a,1.75);
\draw[very thick] (r\a)--(1.5*\a,-1.75);
\ifthenelse{\a = 6}
{}
{\draw[very thick] (r\a)--(1.5+1.5*\a,0);}
}
\draw[line width=5mm,draw=green] (0.5,-1) rectangle (10,1);
\end{tikzpicture}
}
\caption{M1} \label{fig:M1}
\end{figure}
\end{document}
结果: