
Это может оказаться очень проблемным постом, поэтому заранее прошу прощения.
Я пытаюсь нарисовать рисунок с помощью tikz для рукописи, и когда я использовал его в первый раз, он работал очень хорошо. Но теперь я добавил несколько функций в свой файл "command", и с тех пор, когда я запускаю свой документ: никаких ошибок не обнаружено, но рисунок просто не отображается: вместо этого появляется полностью пустая страница, и я не понимаю, почему...
Вот мой сокращенный код, показывающий проблему:
\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}