我怎样才能将 tikz 图片缩放到全宽?

我怎样才能将 tikz 图片缩放到全宽?

在我的原始版本中,图片被很好地缩放到页面的整个宽度。不幸的是,我没有截图。然后我将半径增加到 5(一切正常),再次减小,现在图片太小了:

在此处输入图片描述

有什么提示吗?

\documentclass[12pt]{article}

\usepackage{fancyhdr}
\usepackage{tikz}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{epstopdf}
\usepackage{mathtools}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{url}
\usepackage[parfill]{parskip}
\usepackage{enumerate}
\usepackage{framed}
\usepackage{xcolor}

\pagestyle{fancy}
\lhead{\textsf{x}}
\rhead{\textsf{x}}
\lfoot{\textsf{\tiny x \LaTeX \ | \today}}

\setlength{\headheight}{15pt} 

\begin{document}

$\blacksquare$ \textbf{x}

\begin{tikzpicture}[>=latex][transform canvas={scale=2.0}]
% Draw the lines at multiples of pi/6
\foreach \ang in {0,...,11} {
  \draw [lightgray] (0,0) -- (\ang*360/12:2.5);
}

% Draw the lines at multiples of pi/4
\foreach \ang in {0,...,7} {
  \draw [lightgray] (0,0) -- (\ang*360/8:2.5);
}

% Concentric circles and radius labels
\foreach \s in {0, 1, 2} {
  \draw [lightgray] (0,0) circle (\s + 0.5);
  \draw (0,0) circle (\s);
  \node [fill=white] at (\s, 0) [below] {\scriptsize $\s$};
}

% Add the labels at multiples of pi/4
\foreach \ang/\lab/\dir in {
  0 /0       /right,
  1 /{\pi/4} /{above right},
  2 /{\pi/2} /above,
  3 /{3\pi/4}/{above left},
  4 /{\pi}   /left,
  5 /{5\pi/4}/{below left},
  7 /{7\pi/4}/{below right},
  6 /{3\pi/2}/below} {
    \node [fill=white] at (\ang*360/8:2.6) [\dir] {\scriptsize $\lab$};
}
% The double-lined circle around the whole diagram
\draw [style=double] (0,0) circle (2.5);
\end{tikzpicture} 

\end{document}

示例来自这里. 相关问题12没有解决问题或者我错过了什么。

答案1

想法取自这个非常好的答案

\documentclass[12pt]{article}
\usepackage{fancyhdr}
\usepackage{tikz}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{epstopdf}
\usepackage{mathtools}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{url}
\usepackage[parfill]{parskip}
\usepackage{enumerate}
\usepackage{framed}
\usepackage{xcolor}
\pagestyle{fancy}
\lhead{\textsf{x}}
\rhead{\textsf{x}}
\lfoot{\textsf{\tiny x \LaTeX \ | \today}}
\setlength{\headheight}{15pt} 
\makeatletter
\usepackage{environ}
\newsavebox{\measure@tikzpicture}
\NewEnviron{scaletikzpicturetowidth}[1]{%
  \def\tikz@width{#1}%
  \def\tikzscale{1}\begin{lrbox}{\measure@tikzpicture}%
  \BODY
  \end{lrbox}%
  \pgfmathparse{#1/\wd\measure@tikzpicture}%
  \edef\tikzscale{\pgfmathresult}%
  \BODY
}
\makeatother
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\begin{center}
\begin{scaletikzpicturetowidth}{\textwidth}
\begin{tikzpicture}[scale=\tikzscale,>=latex]
\foreach \ang in {0,...,11} {
  \draw [lightgray] (0,0) -- (\ang*360/12:2.5);
}

% Draw the lines at multiples of pi/4
\foreach \ang in {0,...,7} {
  \draw [lightgray] (0,0) -- (\ang*360/8:2.5);
}

% Concentric circles and radius labels
\foreach \s in {0, 1, 2} {
  \draw [lightgray] (0,0) circle (\s + 0.5);
  \draw (0,0) circle (\s);
  \node [fill=white] at (\s, 0) [below] {\scriptsize $\s$};
}

% Add the labels at multiples of pi/4
\foreach \ang/\lab/\dir in {
  0 /0       /right,
  1 /{\pi/4} /{above right},
  2 /{\pi/2} /above,
  3 /{3\pi/4}/{above left},
  4 /{\pi}   /left,
  5 /{5\pi/4}/{below left},
  7 /{7\pi/4}/{below right},
  6 /{3\pi/2}/below} {
    \node [fill=white] at (\ang*360/8:2.6) [\dir] {\scriptsize $\lab$};
}
% The double-lined circle around the whole diagram
\draw [style=double] (0,0) circle (2.5);
\end{tikzpicture}
\end{scaletikzpicturetowidth}
\end{center}
\end{document}

在此处输入图片描述

相关内容