这可能是一篇非常有问题的帖子,所以提前致歉。
我正在尝试使用 tikz 为手稿绘制一个图形,第一次使用时效果很好。但现在我在“命令”文件中添加了一些函数,从那时起,当我运行我的文档时:没有检测到错误,但图形没有显示出来:相反,有一个完整的空白页,我不明白为什么...
下面是我简化的代码,显示了该问题:
\documentclass[a4paper,11pt,twoside]{book}
\include{formatAndDefs}
\begin{document}
\pagenumbering{roman}
\setcounter{page}{0}
\bibliographystyle{StyleThese}
\begin{vcenterpage}
\noindent\rule[2pt]{\textwidth}{0.5pt}
\begin{tikzpicture}[
scale = 0.675
]
\fill[cyan!25] plot[domain=0:8, samples=100] (\x, {gauss(\x)})|- (0,0);
\draw[very thick, orange!60] plot[domain=0:9.5, samples=100] (\x, {gauss(\x)});
\fill[gray!25] (0,-0.5) -- (0,0) -- (9.5,0) -- (9.5,-0.5) -- (0,-0.5);
\fill[pattern = north east lines] (-0.5,-0.5) -- (0,-0.5) -- (0,4.5) -- (-0.5,4.5) -- (-0.5,-0.5);
\draw[red, dashed, thick, Stealth-Stealth] (-0.25,0) --node[fill=white,scale=0.75]{$h$} (-0.25,{gauss(0)});
\draw[red, dashed, thick, Stealth-Stealth] (0,-0.225) --node[fill=gray!25,scale=0.55]{$R$} (7,-0.27);
\draw[black, dashed, thick, Stealth-Stealth] (0,{gauss(0)}) --node[above,scale=0.65]{$L$} (7,0);
\node[below left, scale = 0.85] at (9,3) {$\boxed{\epsilon \approx \frac{L-R}{R}}$};
\end{tikzpicture}
\noindent\rule[2pt]{\textwidth}{0.5pt}
\end{vcenterpage}
\end{document}
问题是,我不得不分享我的自定义命令文件……因为它对于解决问题很重要。创建的函数显示在文件的“一些高斯函数”部分中。
%!TEX root = Main.tex
%%%%%% FIRST PART%%%%%%%%%%%%
\usepackage{amsmath}
\usepackage{breqn}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[left=1.5in,right=1.3in,top=1.1in,bottom=1.1in,includefoot,includehead,headheight=13.6pt]{geometry}
\renewcommand{\baselinestretch}{1.05}
% List of abbreviations
% Do not try putting acronyms in section titles, that would cause infinite loop of pdftex compilation
\usepackage[printonlyused,withpage]{acronym}
% My pdf code
\usepackage{ifpdf}
\graphicspath{{.}{images/}}
% Links in pdf
% Table of contents for each chapter
\usepackage[nottoc, notlof, notlot]{tocbibind}
\usepackage{minitoc}
\usepackage{fancyhdr} % Fancy Header and Footer
%%% Fancy Header %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Fancy Header Style Options
\pagestyle{fancy} % Sets fancy header and footer
\fancyfoot{} % Delete current footer settings
\fancyhead[LE,RO]{\bfseries\thepage} % Page number (boldface) in left on even
% pages and right on odd pages
\fancyhead[RE]{\bfseries\nouppercase{\leftmark}} % Chapter in the right on even pages
\fancyhead[LO]{\bfseries\nouppercase{\rightmark}} % Section in the left on odd pages
\let\headruleORIG\headrule
\renewcommand{\headrule}{\color{black} \headruleORIG}
\renewcommand{\headrulewidth}{1.0pt}
\usepackage{colortbl}
\arrayrulecolor{black}
\fancypagestyle{plain}{
\fancyhead{}
\fancyfoot{}
\renewcommand{\headrulewidth}{0pt}
}
%%% Clear Header %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Clear Header Style on the Last Empty Odd pages
\makeatletter
\def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else%
\hbox{}%
\thispagestyle{empty}% % Empty header styles
\newpage%
\if@twocolumn\hbox{}\newpage\fi\fi\fi}
\makeatother
\let\minitocORIG\minitoc
\renewcommand{\minitoc}{\minitocORIG \vspace{1.5em}}
\usepackage{subfigure}
\usepackage{multirow}
\renewcommand{\epsilon}{\varepsilon}
% centered page environment
\newenvironment{vcenterpage}
{\newpage\vspace*{\fill}\thispagestyle{empty}\renewcommand{\headrulewidth}{0pt}}
{\vspace*{\fill}}
% Hyperref code
\ifpdf
\usepackage[pagebackref,hyperindex=true]{hyperref}
\else
\usepackage[dvipdfm,pagebackref,hyperindex=true]{hyperref}
\fi
% nicer backref links
\renewcommand*{\backref}[1]{}
\renewcommand*{\backrefalt}[4]{%
\ifcase #1 %
(Non cité.)%
\or
(Cité en page~#2.)%
\else
(Cité en pages~#2.)%
\fi}
\renewcommand*{\backrefsep}{, }
\renewcommand*{\backreftwosep}{ et~}
\renewcommand*{\backreflastsep}{ et~}
% Change this to change the informations included in the pdf file
% See hyperref documentation for information on those parameters
\hypersetup
{
bookmarksopen=true,
pdftitle="Titre du manuscript",
pdfauthor="Votre nom", %auteur du document
pdfsubject="Description rapide du sujet du manuscrit", %sujet du document
%pdftoolbar=false, %barre d'outils non visible
pdfmenubar=true, %barre de menu visible
pdfhighlight=/O, %effet d'un clic sur un lien hypertexte
colorlinks=true, %couleurs sur les liens hypertextes
pdfpagemode=UseNone, %aucun mode de page
pdfpagelayout=SinglePage, %ouverture en simple page
pdffitwindow=true, %pages ouvertes entierement dans toute la fenetre
linkcolor=linkcol, %couleur des liens hypertextes internes
citecolor=citecol, %couleur des liens pour les citations
urlcolor=linkcol %couleur des liens pour les url
}
%%%%%SECOND PART%%%%%%%%%%%%
%%%%%%%%Geometry
\usepackage{geometry}
\usepackage{layout}
\geometry{hmargin = 2.5cm}
\usepackage{parskip}
%%%Axis
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
%%%%%%%%SPECIAL%%%%%%%%%%%%%
\def\doubleunderline#1{\underline{\underline{#1}}}
\DeclareMathOperator{\e}{e}
\renewcommand{\textbf}[1]{\begingroup\bfseries\mathversion{bold}#1\endgroup}
%%%%%%%%Sections & Drawings
\usepackage{multicol} % Colonnes
\usepackage{enumitem}
\usepackage{pgf, tikz, adjustbox}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{calc}
\usetikzlibrary{spy}
\usetikzlibrary{patterns, matrix, positioning}
\usetikzlibrary{arrows.meta,
patterns.meta
}
%%%%%%%%Some Gaussian functions
\pgfmathdeclarefunction{gauss}{1}{
\pgfmathparse{3*exp(-(#1/3.85)^2)}
}
% Second function
\pgfmathdeclarefunction{gaussian}{2}
{%
\pgfmathparse{(1/(#1 * sqrt(2 * pi))) * exp((-1 / 2) * (((x - #2)/#1) ^ 2))}%
}
\pgfmathsetmacro{\mean}{7}
\pgfmathsetmacro{\std}{0.3}
\newcommand\encircle[1]{%
\tikz[baseline=(X.base)]
\node (X) [draw, thick, shape=circle, inner sep=0] {\strut #1};}
%%%%%%%%BOXES
\usepackage[most]{tcolorbox}
\usepackage{wrapfig}
\tcbuselibrary{skins}
我提前为这个令人困惑的设置道歉,希望有人能帮助我解决这个问题。
谢谢你,
答案1
空间很重要。你的高斯函数定义中有一个伪空间:
\pgfmathdeclarefunction{gauss}{1}{ %<------- here is a space (matters)
\pgfmathparse{3*exp(-(#1/3.85)^2)} %<---- here too (probably harmless)
}
你应该把它改成
\pgfmathdeclarefunction{gauss}{1}{%
\pgfmathparse{3*exp(-(#1/3.85)^2)}}
你可以看看如果对样本使用不同的数字会发生什么情况:
\documentclass[a4paper,11pt,twoside]{book}
\usepackage{tikz,xcolor,amsmath,amssymb}
\pgfmathdeclarefunction{gauss}{1}{
\pgfmathparse{3*exp(-(#1/3.85)^2)}
}
\usetikzlibrary{patterns}
\usetikzlibrary{arrows.meta,patterns.meta}
\begin{document}
\foreach\samples in {10,20,...,100}{%
\fbox{\begin{tikzpicture}
%\fill[cyan!25] plot[domain=0:8, samples=100] (\x, {gauss(\x)})|- (0,0);
\draw[very thick, orange!60] plot[domain=0:9.5, samples=\samples] (\x, {gauss(\x)});
\fill[gray!25] (0,-0.5) -- (0,0) -- (9.5,0) -- (9.5,-0.5) -- (0,-0.5);
\fill[pattern = north east lines] (-0.5,-0.5) -- (0,-0.5) -- (0,4.5) -- (-0.5,4.5) -- (-0.5,-0.5);
\draw[red, dashed, thick, Stealth-Stealth] (-0.25,0) --node[fill=white,scale=0.75]{$h$} (-0.25,{gauss(0)});
\draw[red, dashed, thick, Stealth-Stealth] (0,-0.225) --node[fill=gray!25,scale=0.55]{$R$} (7,-0.27);
\draw[black, dashed, thick, Stealth-Stealth] (0,{gauss(0)}) --node[above,scale=0.65]{$L$} (7,0);
\node[below left, scale = 0.85] at (9,3) {$\boxed{\epsilon \approx \frac{L-R}{R}}$};
\end{tikzpicture}}\par}
\end{document}
这些空间会向上凸起并将您的图片推出页面:
答案2
太长了,无法评论,示例可以简化为
图片中的前两行文字会导致内容消失。虽然我不知道为什么。
\documentclass[a4paper,11pt,twoside]{book}
\usepackage{tikz,xcolor,amsmath,amssymb}
\pgfmathdeclarefunction{gauss}{1}{
\pgfmathparse{3*exp(-(#1/3.85)^2)}
}
\usetikzlibrary{patterns}
\usetikzlibrary{arrows.meta,patterns.meta}
\begin{document}
\begin{tikzpicture}
\fill[cyan!25] plot[domain=0:8, samples=100] (\x, {gauss(\x)})|- (0,0);
\draw[very thick, orange!60] plot[domain=0:9.5, samples=100] (\x, {gauss(\x)});
\fill[gray!25] (0,-0.5) -- (0,0) -- (9.5,0) -- (9.5,-0.5) -- (0,-0.5);
\fill[pattern = north east lines] (-0.5,-0.5) -- (0,-0.5) -- (0,4.5) -- (-0.5,4.5) -- (-0.5,-0.5);
\draw[red, dashed, thick, Stealth-Stealth] (-0.25,0) --node[fill=white,scale=0.75]{$h$} (-0.25,{gauss(0)});
\draw[red, dashed, thick, Stealth-Stealth] (0,-0.225) --node[fill=gray!25,scale=0.55]{$R$} (7,-0.27);
\draw[black, dashed, thick, Stealth-Stealth] (0,{gauss(0)}) --node[above,scale=0.65]{$L$} (7,0);
\node[below left, scale = 0.85] at (9,3) {$\boxed{\epsilon \approx \frac{L-R}{R}}$};
\end{tikzpicture}
\end{document}
@hpekristiansen 对此进行了进一步阐述:
\documentclass[tikz, border=1cm]{standalone}
\pgfmathdeclarefunction{gauss}{1}{
\pgfmathparse{3*exp(-(#1/3.85)^2)} }
\begin{document}
\begin{tikzpicture}
\fill plot[samples=100] (\x, {gauss(\x)});
\draw (0,0) -- (1,1);
\end{tikzpicture}
\end{document}