标签尺寸超出Tex容量

标签尺寸超出Tex容量

当我想通过 修改 ylabel 大小时tick label style={font=\Large},出现以下错误消息(没有 ylabel 大小,编译正常):

Package pgfplots notification 'compat/show suggested version=true': document ha
s been generated with the most recent feature set (\pgfplotsset{compat=1.18}).

! TeX capacity exceeded, sorry [input stack size=10000].
\@nomath ...e \@font@warning {Command \noexpand #1
                                                  invalid in math mode}\fi 
l.58     ]
          
If you really absolutely need more capacity,
you can ask a wizard to enlarge me.

 
Here is how much of TeX's memory you used:
 31676 strings out of 411566
 808668 string characters out of 2820184
 1852973 words of memory out of 3000000
 51354 multiletter control sequences out of 15000+600000
 512295 words of font info for 33 fonts, out of 8000000 for 9000
 1348 hyphenation exceptions out of 8191
 10000i,2n,14993p,7531b,715s stack positions out of 10000i,1000n,20000p,200000b,80000s
No pages of output.

我的代码:

\documentclass[border=2mm]{standalone}
\usepackage{pstricks-add}
\usepackage{pst-plot}
\usepackage{siunitx}
\usepackage{pgfplots}
\usepackage{pgf-spectra}

\usepgfplotslibrary{fillbetween}
% Preamble: 
\pgfplotsset{compat=newest}
\usetikzlibrary{calc}
\usetikzlibrary{math}
\tikzmath{
  function sinc2(\x) {
    if  abs(\x) < .001 then { % (|x| < .001) ~ (x = 0)
      return 1;
    } else {
      return (sin(\x r)/\x)*(sin(\x r)/\x);
    };
  };
}

\pgfplotsset{every axis/.append style={
    axis lines=middle,
    grid=both,
    minor tick num=1,
    grid style={line width=.1pt, draw=gray!10},
    major grid style={line width=.2pt,draw=gray!50},
    xtick={-3*pi, -2*pi, -pi, pi, 2*pi, 3*pi},
    xticklabels={$-3\frac{\lambda D\pi}{a}$, $-2\frac{\lambda D\pi}{a}$,  $-\frac{\lambda D\pi}{a}$,$\frac{\lambda D\pi}{a}$,  $2\frac{\lambda D\pi}{a}$, $3\frac{\lambda D\pi}{a}$},
                    label style={font=\tiny},
                    tick label style={font=\Large}  
                                        ytick=\empty
                    }}

%--------------------------------------------------------
\begin{document}
%--------------------------------------------------------
\begin{tikzpicture}
    \fill (-3,0) rectangle (3,6);
    \fill [white] (-0.05,1) rectangle (0.05,5);

\begin{scope}[xshift=7cm]
\draw (-3.5,0) rectangle (3.5,6);
\fill [red] (0,3) ellipse (1 and 0.2);
\fill [red] (1.6,3) ellipse (0.5 and 0.15);
\fill [red] (2.7,3) ellipse (0.5 and 0.13);
\fill [red] (-1.6,3) ellipse (0.5 and 0.15);
\fill [red] (-2.7,3) ellipse (0.5 and 0.13);

   % \fill [white] (-0.05,1) rectangle (0.05,5);
    
\end{scope}

\begin{axis}[xshift=11cm,
        width=20cm,
        height=8cm
    ]
    \addplot[domain=-4*pi:4*pi,samples=200,red] {sinc2(x))};
\end{axis}

\end{tikzpicture}
\end{document}

答案1

后面少了一个逗号{font=\Large}

另一方面,我认为您应该使用\dfrac(需要amsmath)而不是\Large

比较输出

\dfrac勾选标签内

在此处输入图片描述

拥有font=\Large\frac

在此处输入图片描述

固定代码(带\Large\frac

\documentclass[border=2mm]{standalone}
\usepackage{amsmath}
\usepackage{pgfplots}

\usepgfplotslibrary{fillbetween}

% Preamble: 
\usetikzlibrary{calc}
\usetikzlibrary{math}
\tikzmath{
  function sinc2(\x) {
    if  abs(\x) < .001 then { % (|x| < .001) ~ (x = 0)
      return 1;
    } else {
      return (sin(\x r)/\x)*(sin(\x r)/\x);
    };
  };
}

\pgfplotsset{
  compat=newest,
  every axis/.append style={
    axis lines=middle,
    grid=both,
    minor tick num=1,
    grid style={line width=.1pt, draw=gray!10},
    major grid style={line width=.2pt,draw=gray!50},
    xtick={-3*pi, -2*pi, -pi, pi, 2*pi, 3*pi},
    xticklabels={
      $-3\frac{\lambda D\pi}{a}$,
      $-2\frac{\lambda D\pi}{a}$,
      $-\frac{\lambda D\pi}{a}$,
      $\frac{\lambda D\pi}{a}$,
      $2\frac{\lambda D\pi}{a}$,
      $3\frac{\lambda D\pi}{a}$,
    },
    label style={font=\tiny},
    tick label style={font=\Large},
    ytick=\empty,
  }
}

%--------------------------------------------------------
\begin{document}
%--------------------------------------------------------
\begin{tikzpicture}
    \fill (-3,0) rectangle (3,6);
    \fill [white] (-0.05,1) rectangle (0.05,5);

\begin{scope}[xshift=7cm]
\draw (-3.5,0) rectangle (3.5,6);
\fill [red] (0,3) ellipse (1 and 0.2);
\fill [red] (1.6,3) ellipse (0.5 and 0.15);
\fill [red] (2.7,3) ellipse (0.5 and 0.13);
\fill [red] (-1.6,3) ellipse (0.5 and 0.15);
\fill [red] (-2.7,3) ellipse (0.5 and 0.13);

   % \fill [white] (-0.05,1) rectangle (0.05,5);
    
\end{scope}

\begin{axis}[xshift=11cm,
        width=20cm,
        height=8cm
    ]
    \addplot[domain=-4*pi:4*pi,samples=200,red] {sinc2(x))};
\end{axis}

\end{tikzpicture}
\end{document}

我习惯于每行指定一个选项,缩进较少。这样更容易注释一个选项。任何选项后都应使用逗号,这样万一您添加了另一个选项(可能是导致问题的原因),就不会有忘记一个选项的风险。

我删除了所有不必要的包。你真的同时使用 PSTricks 和 PGFplots 吗?

相关内容