我目前正在将大型 LaTeX 文档从一种布局移动到另一个布局。我对这个 tikzpicture 图形有问题,尽管 LaTeX 编译没有任何问题,但它并没有出现在最终的 PDF 中:
% **************************************************
\documentclass[
paper=A4, % paper size
twoside=true, % onesite or twoside printing
openright, % doublepage cleaning ends up right side
parskip=full, % spacing value / method for paragraphs
chapterprefix=true, % prefix for chapter marks
11pt, % font size
headings=normal, % size of headings
bibliography=totoc, % include bib in toc
listof=totoc, % include listof entries in toc
titlepage=on, % own page for each title page
captions=tableabove, % display table captions above the float env
draft=false, % value for draft version
]{scrreprt}
\usepackage{colortbl}
\usepackage[most]{tcolorbox}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,shapes,decorations,automata,backgrounds,petri,topaths,calc,mindmap,trees,positioning,chains,arrows}
\usepackage{relsize}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\usepackage{algorithm2e}
\usepackage{amssymb}
\usepackage{float}
\usepackage{multirow}
\usepackage{pbox}
\usepackage[page,toc,titletoc,title]{appendix}
% Gaussian plot with #1 = mean and #2 = standard deviation
\pgfmathdeclarefunction{gauss}{2}{
\pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}
}
\begin{document}
\textbf{MWE} \\
Here we go...
\begin{figure}[!htb]
\begin{tikzpicture}
\begin{axis}[every axis plot post/.append style={mark=none,domain=-10:10,samples=100,smooth},
enlargelimits=upper,legend style={at={(1.02,0.825)},anchor=west}] % extend the axes a bit to the right and top
\addplot [line width=0.25mm, red,dotted] {gauss(0,1)};
\addplot [line width=0.25mm, blue,dashed] {gauss(0,2)};
\addplot [line width=0.25mm, green] {gauss(1,1)};
\addplot [line width=0.25mm, orange,dashdotted] {gauss(1,2)};
\addlegendentry{Gaussian with $\mu = 0$ and $\sigma = 1$}
\addlegendentry{Gaussian with $\mu = 0$ and $\sigma = 2$}
\addlegendentry{Gaussian with $\mu = 1$ and $\sigma = 1$}
\addlegendentry{Gaussian with $\mu = 1$ and $\sigma = 2$}
\end{axis}
\end{tikzpicture}
\caption{My label} \label{fig:MyLabel}
\end{figure}
\end{document}
答案1
问题出%
在函数定义的行尾。未受保护的行尾被解释为空格,每次使用该函数时\addplot
都会插入额外的空白,并且图表会被推离页面的右侧边界
% **************************************************
\documentclass[
paper=A4, % paper size
twoside=true, % onesite or twoside printing
openright, % doublepage cleaning ends up right side
parskip=full, % spacing value / method for paragraphs
chapterprefix=true, % prefix for chapter marks
11pt, % font size
headings=normal, % size of headings
bibliography=totoc, % include bib in toc
listof=totoc, % include listof entries in toc
titlepage=on, % own page for each title page
captions=tableabove, % display table captions above the float env
draft=false, % value for draft version
]{scrreprt}
\usepackage{colortbl}
\usepackage[most]{tcolorbox}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,shapes,decorations,automata,backgrounds,petri,topaths,calc,mindmap,trees,positioning,chains,arrows}
\usepackage{relsize}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\usepackage{algorithm2e}
\usepackage{amssymb}
\usepackage{float}
\usepackage{multirow}
\usepackage{pbox}
\usepackage[page,toc,titletoc,title]{appendix}
% Gaussian plot with #1 = mean and #2 = standard deviation
\pgfmathdeclarefunction{gauss}{2}{%
\pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}
\begin{document}
\textbf{MWE} \\
Here we go...
\begin{figure}[!htb]
\begin{tikzpicture}
\begin{axis}[every axis plot post/.append style={mark=none,domain=-10:10,samples=100,smooth},
enlargelimits=upper,legend style={at={(1.02,0.825)},anchor=west}] % extend the axes a bit to the right and top
\addplot [line width=0.25mm, red,dotted] {gauss(0,1)};
\addplot [line width=0.25mm, blue,dashed] {gauss(0,2)};
\addplot [line width=0.25mm, green] {gauss(1,1)};
\addplot [line width=0.25mm, orange,dashdotted] {gauss(1,2)};
\addlegendentry{Gaussian with $\mu = 0$ and $\sigma = 1$}
\addlegendentry{Gaussian with $\mu = 0$ and $\sigma = 2$}
\addlegendentry{Gaussian with $\mu = 1$ and $\sigma = 1$}
\addlegendentry{Gaussian with $\mu = 1$ and $\sigma = 2$}
\end{axis}
\end{tikzpicture}
\caption{My label} \label{fig:MyLabel}
\end{figure}
\end{document}