I want to scale a tikzpicture within the figure environment.
The code that produces the scaled figure:
\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}
This produces a tikz picture that is correctly scaled, but now overlaps with the caption:
Is there any way around this?
Also, is it possible to rescale the tikzpicture with respect to the textwidth with something like
0.5\textwidth
?
Best Answer
For rescaling in general you can use a
resizebox
(from thegraphicx
package), which also works fortikzpicture
. The first argument is the width, the second the height, or!
to scale proportionally. With aresizebox
you don't need coordinate transformation, which seems to cause the overlap in your example.MWE:
Result: