我用 TikZ 制作了很多图片,但是当我打印其中一些图片时(例如y = tan x
),纸上会出现多余的线条,而这些线条在构造和 PDF 模式下并不存在。编辑:我认为没有必要发布整个代码。这里是它,还有打印结果(你可以找到它这里)。
\documentclass[12pt]{beamer}
\usepackage{fontspec}
\usepackage{xltxtra}
\usepackage{xgreek}
\usepackage{graphicx}
\usepackage{mathtools}
\usepackage{amscd}
\usepackage{amsthm}
\usepackage[mathup=sym]{unicode-math}
\usepackage{tikz}
\usepackage{makeidx}
\usepackage{graphicx}
\usepackage{pgf,tikz}
\usepackage{tkz-tab}
\usetikzlibrary{shapes,snakes,arrows,backgrounds}
\usetikzlibrary{scopes,svg.path,shapes.geometric,shadows}
\usepackage{color, colortbl}
\usepackage{fancyhdr}
\usepackage{tcolorbox}
\usepackage{shadowtext}
\usepackage{etoolbox}
\setmathfont[Scale=MatchUppercase]{STIX Two Math}
\usetheme{Warsaw}
\usecolortheme{beaver}
\setbeamertemplate{page number in head/foot}[appendixframenumber]
\useoutertheme[headline=authortitle]{miniframes}
\usepackage{hyperref}
\usepackage{ragged2e}
\definecolor{ballblue}{rgb}{0.13, 0.67, 0.8}
\definecolor{Red}{RGB}{168, 4, 4}
\setsansfont[Mapping=tex-text]{DejaVu Sans}
\begin{document}
\begin{tikzpicture}[scale=0.7]
\draw[thick,->] (-5.1,0) -- (5.1,0)node[pos=1,right]{
$x$};
\draw[thick,->] (0,-4) -- (0,4)node[pos=1,left]{$y$};
\node[below right](o) at (-0.1,0.1){$0$};
\begin{scope}
\clip (-5.1,-4) rectangle (5.1,4);
\draw[dashed](-1.57,-4)--(-1.57,-0.8);
\draw[dashed](-1.57,-0.1)--(-1.57,4);
\draw[dashed](1.57,-4)--(1.57,4);
\draw[dashed](4.71,-4)--(4.71,4);
\draw[dashed](-4.71,-4)--(-4.71,4);
\draw[ultra thick, Red, domain={-1.5 }:{1.5}, samples=200] plot(\x,{tan(((\x))*180/pi)});
\draw[ultra thick, Red, domain={-4.7 }:{-1.7}, samples=200] plot(\x,{tan(((\x))*180/pi)});
\draw[ultra thick, Red, domain={1.6 }:{4.7}, samples=200] plot(\x,{tan(((\x))*180/pi)});
\end{scope}
\node[below]() at (-3.14,0){$-π$};
\node[below]() at (3.14,0){$π$};
\node[below]() at (-1.8,0.1){$-\dfrac{π}{2}$};
\node[below left]() at (4.9,0.1){$\frac{3π}{2}$};
\node[below right]() at (1.32,0.1){$\dfrac{π}{2}$};
\end{tikzpicture}
\end{document}
答案1
- 您使用了 unicode 数学字体,但未声明它们。因此,刻度标签在 pdf 查看器中也是不完整且错误的。例如:
\documentclass{beamer}
\usefonttheme{professionalfonts} % <---
\usepackage{unicode-math} % <---
\setsansfont{Verdana} % <---
\setmathfont{XITS Math} % <---
- 但是,如果对于刻度标签,您使用标准数学符号
\pi
,则不需要上述字体声明,并且可以在 pdfLaTeX、XeLaTeX 以及 LuaLaTeX 中编译 MWE,就像在下面的 MWE 中所做的那样。 - 文档中的
beamer
内容通常位于框架中。为什么不将图像插入到框架中? pgfplots
使用 preamble 包(基于 tikz)绘制图像更简单。例如:
\documentclass{beamer}
% in case that you like to compile only with XeLaTeX or LuaLaTeX,
% uncomment the the following code lines:
% \usefonttheme{professionalfonts} % <---
%\usepackage{unicode-math} % <---
% \setsansfont{Verdana} % <---
% \setmathfont{XITS Math} % <---
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{frame} % <---
\begin{center}
\begin{tikzpicture}
\begin{axis}[
height=88mm,
axis lines = middle,
axis on top,
xlabel=$x$,
ylabel=$y$,
label style={anchor=north east}, % <---
ticklabel style={font=\footnotesize,% <---
fill=white, inner sep=2pt},
xmin=-300, xmax=330,
xtick={-270,-90,90,270}, % <---
xticklabels={$-\frac{3\pi}{2}$,$-\frac{\pi}{2}$, % <---
$\frac{\pi}{2}$, $\frac{3\pi}{2}$}, % <---
ymin=-2.2, ymax=2.2,
ytick=\empty,
restrict y to domain=-10:10, % <---
domain=-270:270, % <---
samples=181,
no marks % <---
]
\draw[very thin, densely dashed] % <--- moved before *addšlpt*
(-270,-2.2) -- (-270,2.2)
(-90,-2.2) -- (-90,2.2)
(90,-2.2) -- (90,2.2)
(270,-2.2) -- (270,2.2);
\addplot +[red,very thick] {tan(x)}; % <---
\end{axis}
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}
- 在您有许多类似图像的情况下,您可以将轴定义的公共部分移到
\pgfplotsset
序言中,并在本地仅写入特定于图像的内容。 - 添加字体声明后,您的 MWE 也会起作用,并在 pdf 查看器和纸张上产生相同的结果:
\documentclass{beamer}
\usefonttheme{professionalfonts} % <---
\usepackage{unicode-math} % <---
\setsansfont{Verdana} % <---
\setmathfont{XITS Math} % <---
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}[scale=0.7]
\draw[thick,->] (-5.1,0) -- (5.1,0)node[pos=1,right]{
$x$};
\draw[thick,->] (0,-4) -- (0,4)node[pos=1,left]{$y$};
\node[below right](o) at (-0.1,0.1){$0$};
\begin{scope}
\clip (-5.1,-4) rectangle (5.1,4);
\draw[dashed](-1.57,-4)--(-1.57,-0.8);
\draw[dashed](-1.57,-0.1)--(-1.57,4);
\draw[dashed](1.57,-4)--(1.57,4);
\draw[dashed](4.71,-4)--(4.71,4);
\draw[dashed](-4.71,-4)--(-4.71,4);
\draw[ultra thick, red, domain={-1.5 }:{1.5}, samples=200] plot(\x,{tan(((\x))*180/pi)});
\draw[ultra thick, red, domain={-4.7 }:{-1.7}, samples=200] plot(\x,{tan(((\x))*180/pi)});
\draw[ultra thick, red, domain={1.6 }:{4.7}, samples=200] plot(\x,{tan(((\x))*180/pi)});
\end{scope}
\node[below]() at (-3.14,0){$-π$};
\node[below]() at (3.14,0){$π$};
\node[below]() at (-1.8,0.1){$-\dfrac{π}{2}$};
\node[below left]() at (4.9,0.1){$\dfrac{3π}{2}$}; % <---
\node[below right]() at (1.32,0.1){$\dfrac{π}{2}$};
\end{tikzpicture}
\end{document}
然而,我认为结果并不像使用时那么好pgfplots
:
- 这两个例子中,纸上和 PDF 查看器中的结果是相同的。
- 两个 MWE 中都标记了代码行,与所讨论的 MWE 相比,这些代码行有添加或更改。