マクロ値から tikzpicture のサンプルを設定する

マクロ値から tikzpicture のサンプルを設定する

tikzpicture ごとのサンプル数をグローバルに設定しようとしています:

\documentclass{standalone}
\usepackage{pgfplots}
\pgfmathdeclarefunction{gauss}{2}{%
  \pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}
%\samplesize = <number>% How do I get this one to work?
\begin{document}  
\section{Gaussian distribution}

\begin{tikzpicture}
\begin{axis}[
      hide y axis,
      axis lines*=center, 
      axis on top,
      no markers, 
      domain=2.5:25.5, 
      samples=\samplesize,
      xlabel=\empty, 
      ylabel=\empty,
      every axis x label/.style={at=(current axis.right of origin),anchor=west},
      every axis y label/.style={at=(current axis.above origin),anchor=south},
      height=5cm, width=12cm,
      xmin = 4, xmax=24,
      xtick={14}, ytick=\empty,
      enlargelimits=false, 
      clip=false,
      grid=major
  ]
  \addplot [fill=cyan!20, draw=cyan!80, domain=4:7] {gauss(14,3.41696)} \closedcycle;
  \addplot [very thick,cyan!50!black] {gauss(14,3.416969)};
\end{axis}
\end{tikzpicture}
\end{document}

\valueこれを TeX プリミティブ カウンター、、、、などでは動作させることができませんでした\def\let\newcommand

答え1

例えば\newcommand

\newcommand\samplesize{100}

また、デフォルトでは、standaloneクラスはセクション見出し (その他) を処理しないようです。ただし、追加するとvarwidth=true機能します。 (ただし、これは\section完全なドキュメントからの単なる名残かもしれません。)

完全なコード:

\documentclass[varwidth=true]{standalone}
\usepackage{pgfplots}
\pgfmathdeclarefunction{gauss}{2}{%
  \pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}

\newcommand\samplesize{100}

\begin{document}  
\section{Gaussian distribution}

\begin{tikzpicture}
\begin{axis}[
      hide y axis,
      axis lines*=center, 
      axis on top,
      no markers, 
      domain=2.5:25.5, 
      samples=\samplesize,
      xlabel=\empty, 
      ylabel=\empty,
      every axis x label/.style={at=(current axis.right of origin),anchor=west},
      every axis y label/.style={at=(current axis.above origin),anchor=south},
      height=5cm, width=12cm,
      xmin = 4, xmax=24,
      xtick={14}, ytick=\empty,
      enlargelimits=false, 
      clip=false,
      grid=major
  ]
  \addplot [fill=cyan!20, draw=cyan!80, domain=4:7] {gauss(14,3.41696)} \closedcycle;
  \addplot [very thick,cyan!50!black] {gauss(14,3.416969)};
\end{axis}
\end{tikzpicture}
\end{document}

ここに画像の説明を入力してください

関連情報