为了我的数学总结,我试图制作一个表格,其中包含所有三角函数的函数图(类似于下图,但包括反函数)。由于我的空间仅限于 12 页,我希望其中一些垂直对齐以节省一些空间,就像图中一样。我对 Latex 还不太熟悉,我尝试使用 来做到这一点tabular
。但是这些图有点太靠右了 - 我希望它们完全居中。我该怎么做?
我的另一个问题是,如果我尝试绘制诸如tan
、csc
、sec
、arcsin
、等函数arccos
,它们要么产生错误,要么搞乱一切。我该如何绘制这些函数?
我也找不到任何总结了所有三角函数的模板,我觉得这很奇怪,因为我认为我不是第一个需要它的人。是否有一个秘密的地方可以共享此类文件?
下面是三个函数的代码(我包含了两次余弦,以便有东西可以显示):
\documentclass{article}
\usepackage[utf8]{inputenc}
\title{testtt}
\usepackage{amsmath} \usepackage{amsfonts} \usepackage{amssymb}
\usepackage{amsthm} \usepackage{latexsym} \usepackage{mathtools}
\usepackage{tikz}
\begin{document}
\newcommand*{\xMin}{-9}
\newcommand*{\xMax}{9}
\newcommand*{\yMin}{-3}
\newcommand*{\yMax}{3}
\begin{tabular}{ c c }
\begin{tikzpicture}[>=stealth,scale=0.4]
\draw[very thin,color=gray,scale={pi/2}] ({\xMin*((1)/(2))+0.01},-6/pi+0.01) grid ({\xMax*(1/2)-0.01},7/pi-0.01);
\draw node at ({pi},0) [below] {${\pi}$};
\draw node at ({2*pi},0) [below] [xshift=1pt] {${2\pi}$};
\draw node at ({-pi},0) [below] [xshift=-2pt] {${-\pi}$};
\draw node at ({-2*pi},0) [below] [xshift=-2pt] {${-2\pi}$};
\draw node at (0,1) [left] {$1$};
\draw node at (0,2) [left] {$2$};
\draw node at (0,-1) [left] {$-1$};
\draw node at (0,-2) [left] {$-2$};
\draw [->] [thick] ({\xMin*(pi/4)},0) -- ({\xMax*(pi/4)+0.5},0)
node [right] {$x$};
\draw [->] [thick] (0,-3) -- (0,3.5)
node [above] {$y$};
\draw [-,thin,black,domain={-2*pi}:{2*pi},samples=100]
plot (\x, {sin(\x*180/pi)}) node[above] {$f(x) = \sin(x)$};
\end{tikzpicture} &
\begin{tikzpicture}[>=stealth,scale=0.4]
\draw[very thin,color=gray,scale={pi/2}] ({\xMin*((1)/(2))+0.01},-6/pi+0.01) grid ({\xMax*(1/2)-0.01},7/pi-0.01);
\draw node at ({pi},0) [below] {${\pi}$};
\draw node at ({2*pi},0) [below] [xshift=1pt] {${2\pi}$};
\draw node at ({-pi},0) [below] [xshift=-2pt] {${-\pi}$};
\draw node at ({-2*pi},0) [below] [xshift=-2pt] {${-2\pi}$};
\draw node at (0,1) [left] {$1$};
\draw node at (0,2) [left] {$2$};
\draw node at (0,-1) [left] {$-1$};
\draw node at (0,-2) [left] {$-2$};
\draw [->] [thick] ({\xMin*(pi/4)},0) -- ({\xMax*(pi/4)+0.5},0)
node [right] {$x$};
\draw [->] [thick] (0,-3) -- (0,3.5)
node [above] {$y$};
\draw [-,thin,black,domain={-2*pi}:{2*pi},samples=100]
plot (\x, {cos(\x*180/pi)}) node[above] {$f(x) = \cos(x)$};
\end{tikzpicture} \\
\begin{tikzpicture}[>=stealth,scale=0.4]
\draw[very thin,color=gray,scale={pi/2}] ({\xMin*((1)/(2))+0.01},-6/pi+0.01) grid ({\xMax*(1/2)-0.01},7/pi-0.01);
\draw node at ({pi},0) [below] {${\pi}$};
\draw node at ({2*pi},0) [below] [xshift=1pt] {${2\pi}$};
\draw node at ({-pi},0) [below] [xshift=-2pt] {${-\pi}$};
\draw node at ({-2*pi},0) [below] [xshift=-2pt] {${-2\pi}$};
\draw node at (0,1) [left] {$1$};
\draw node at (0,2) [left] {$2$};
\draw node at (0,-1) [left] {$-1$};
\draw node at (0,-2) [left] {$-2$};
\draw [->] [thick] ({\xMin*(pi/4)},0) -- ({\xMax*(pi/4)+0.5},0)
node [right] {$x$};
\draw [->] [thick] (0,-3) -- (0,3.5)
node [above] {$y$};
\draw [-,thin,black,domain={-2*pi}:{2*pi},samples=100]
plot (\x, {cos(\x*180/pi)}) node[above] {$f(x) = \cos(x)$};
\end{tikzpicture}
\end{tabular}
\end{document}
答案1
我主张使用该pgfplots
包来制作此类图形。
它允许您使用以下内容,例如
\begin{tikzpicture}
\begin{axis}
\addplot[timtam]expression[domain=-3.5:3.5]{sin(x)};
\end{axis}
\end{tikzpicture}
这里有几个演示;请根据需要进行调整。作为参考,另请参阅PGFPlots 中带有三角标签的轴, 例如。
选项 1:使用小页面和单独的图
% arara: pdflatex
\documentclass{article}
\usepackage{geometry}
\usepackage{pgfplots}
\pgfplotsset{
% framing the graphs
framed/.style={
axis background/.style ={draw=blue,fill=yellow!20,rounded corners=3ex}},
% line style
timtam/.style={
color=red,mark=none,line width=1pt},
% every axis
every axis/.append style={
axis x line=middle, % put the x axis in the middle
axis y line=middle, % put the y axis in the middle
axis line style={->}, % arrows on the axis
xlabel={$x$}, % default put x on x-axis
ylabel={$y$}, % default put y on y-axis
scale only axis, % otherwise width won't be as intended: http://tex.stackexchange.com/questions/36297/pgfplots-how-can-i-scale-to-text-width
xtick={-3.14159265359,-1.57079632679,1.57079632679,3.14159265359},
xticklabels={$-\pi$,$-\pi/2$,$\pi/2$,$\pi$},
xmin=-3.5, xmax=3.5,
ymin=-2.3, ymax=2.3,
trig format=rad, % use radians
framed,
grid=both,
width=\textwidth,
},
% not needed in the below, but you might like them for future
asymptote/.style={
color=red,mark=none,line width=1pt,dashed},
soldot/.style={
color=red,only marks,mark=*},
holdot/.style={
color=red,fill=white,only marks,mark=*},
}
% arrow style
\tikzset{>=stealth}
\begin{document}
\begin{minipage}{.33\textwidth}
\begin{tikzpicture}
\begin{axis}
\addplot[timtam]expression[domain=-3.5:3.5]{sin(x)};
\end{axis}
\end{tikzpicture}
\end{minipage}
\begin{minipage}{.33\textwidth}
\begin{tikzpicture}
\begin{axis}
\addplot[timtam]expression[domain=-3.5:3.5]{cos(x)};
\end{axis}
\end{tikzpicture}
\end{minipage}
\begin{minipage}{.33\textwidth}
\begin{tikzpicture}
\begin{axis}
\addplot[timtam]expression[domain=-4.5:-1.58]{tan(x)};
\addplot[timtam]expression[domain=-1.56:1.55]{tan(x)};
\addplot[timtam]expression[domain=1.58:4.5]{tan(x)};
\end{axis}
\end{tikzpicture}
\end{minipage}%
\vspace{1cm}
\begin{minipage}{.33\textwidth}
\begin{tikzpicture}
\begin{axis}
\addplot[timtam]expression[domain=-3.5:-3.2]{1/sin(x)};
\addplot[timtam]expression[domain=-3.1:-0.1]{1/sin(x)};
\addplot[timtam]expression[domain=0.1:3.1]{1/sin(x)};
\addplot[timtam]expression[domain=3.2:4.5]{1/sin(x)};
\end{axis}
\end{tikzpicture}
\end{minipage}
\begin{minipage}{.33\textwidth}
\begin{tikzpicture}
\begin{axis}
\addplot[timtam]expression[domain=-4.5:-1.58]{1/cos(x)};
\addplot[timtam]expression[domain=-1.56:1.56]{1/cos(x)};
\addplot[timtam]expression[domain=1.58:4.5]{1/cos(x)};
\end{axis}
\end{tikzpicture}
\end{minipage}
\begin{minipage}{.33\textwidth}
\begin{tikzpicture}
\begin{axis}
\addplot[timtam]expression[domain=-3.5:-3.2]{cot(x)};
\addplot[timtam]expression[domain=-3.1:-0.1]{cot(x)};
\addplot[timtam]expression[domain=0.1:3.1]{cot(x)};
\addplot[timtam]expression[domain=3.2:4.5]{cot(x)};
\end{axis}
\end{tikzpicture}
\end{minipage}%
\end{document}
选项 2:与选项 1 类似,但带有标题
如果您想添加标题,我们可以使用以下内容,例如;您会看到上面的新部分是
title style={at={(axis cs:0,-3.2)}}, %<------ NEW BIT
然后,在代码中,我使用了\begin{axis}[title={$y=\sin(x)$}]
。
% arara: pdflatex
\documentclass{article}
\usepackage{geometry}
\usepackage{pgfplots}
\pgfplotsset{
% framing the graphs
framed/.style={
axis background/.style ={draw=blue,fill=yellow!20,rounded corners=3ex}},
% line style
timtam/.style={
color=red,mark=none,line width=1pt},
% every axis
every axis/.append style={
axis x line=middle, % put the x axis in the middle
axis y line=middle, % put the y axis in the middle
axis line style={->}, % arrows on the axis
xlabel={$x$}, % default put x on x-axis
ylabel={$y$}, % default put y on y-axis
scale only axis, % otherwise width won't be as intended: http://tex.stackexchange.com/questions/36297/pgfplots-how-can-i-scale-to-text-width
xtick={-3.14159265359,-1.57079632679,1.57079632679,3.14159265359},
xticklabels={$-\pi$,$-\pi/2$,$\pi/2$,$\pi$},
xmin=-3.5, xmax=3.5,
ymin=-2.3, ymax=2.3,
trig format=rad, % use radians
framed,
grid=both,
width=\textwidth,
title style={at={(axis cs:0,-3.2)}}, %<------ NEW BIT
},
% not needed in the below, but you might like them for future
asymptote/.style={
color=red,mark=none,line width=1pt,dashed},
soldot/.style={
color=red,only marks,mark=*},
holdot/.style={
color=red,fill=white,only marks,mark=*},
}
% arrow style
\tikzset{>=stealth}
\begin{document}
\begin{minipage}{.33\textwidth}
\begin{tikzpicture}
\begin{axis}[title={$y=\sin(x)$}]
\addplot[timtam]expression[domain=-3.5:3.5]{sin(x)};
\end{axis}
\end{tikzpicture}
\end{minipage}
\begin{minipage}{.33\textwidth}
\begin{tikzpicture}
\begin{axis}[title={$y=\cos(x)$}]
\addplot[timtam]expression[domain=-3.5:3.5]{cos(x)};
\end{axis}
\end{tikzpicture}
\end{minipage}
\begin{minipage}{.33\textwidth}
\begin{tikzpicture}
\begin{axis}[title={$y=\tan(x)$}]
\addplot[timtam]expression[domain=-4.5:-1.58]{tan(x)};
\addplot[timtam]expression[domain=-1.56:1.55]{tan(x)};
\addplot[timtam]expression[domain=1.58:4.5]{tan(x)};
\end{axis}
\end{tikzpicture}
\end{minipage}%
\vspace{1cm}
\begin{minipage}{.33\textwidth}
\begin{tikzpicture}
\begin{axis}[title={$y=\csc(x)$}]
\addplot[timtam]expression[domain=-3.5:-3.2]{1/sin(x)};
\addplot[timtam]expression[domain=-3.1:-0.1]{1/sin(x)};
\addplot[timtam]expression[domain=0.1:3.1]{1/sin(x)};
\addplot[timtam]expression[domain=3.2:4.5]{1/sin(x)};
\end{axis}
\end{tikzpicture}
\end{minipage}
\begin{minipage}{.33\textwidth}
\begin{tikzpicture}
\begin{axis}[title={$y=\sec(x)$}]
\addplot[timtam]expression[domain=-4.5:-1.58]{1/cos(x)};
\addplot[timtam]expression[domain=-1.56:1.56]{1/cos(x)};
\addplot[timtam]expression[domain=1.58:4.5]{1/cos(x)};
\end{axis}
\end{tikzpicture}
\end{minipage}
\begin{minipage}{.33\textwidth}
\begin{tikzpicture}
\begin{axis}[title={$y=\cot(x)$}]
\addplot[timtam]expression[domain=-3.5:-3.2]{cot(x)};
\addplot[timtam]expression[domain=-3.1:-0.1]{cot(x)};
\addplot[timtam]expression[domain=0.1:3.1]{cot(x)};
\addplot[timtam]expression[domain=3.2:4.5]{cot(x)};
\end{axis}
\end{tikzpicture}
\end{minipage}%
\end{document}
选项 3:使用 groupplot
输出与选项 2 相同,但输入可能更令人满意;请注意,这需要groupplots
在下方代码中注释的库。
% arara: pdflatex
\documentclass{article}
\usepackage{geometry}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots} %<------------ NEW BIT
\pgfplotsset{
% framing the graphs
framed/.style={
axis background/.style ={draw=blue,fill=yellow!20,rounded corners=3ex}},
% line style
timtam/.style={
color=red,mark=none,line width=1pt},
% every axis
every axis/.append style={
axis x line=middle, % put the x axis in the middle
axis y line=middle, % put the y axis in the middle
axis line style={->}, % arrows on the axis
xlabel={$x$}, % default put x on x-axis
ylabel={$y$}, % default put y on y-axis
scale only axis, % otherwise width won't be as intended: http://tex.stackexchange.com/questions/36297/pgfplots-how-can-i-scale-to-text-width
xtick={-3.14159265359,-1.57079632679,1.57079632679,3.14159265359},
xticklabels={$-\pi$,$-\pi/2$,$\pi/2$,$\pi$},
xmin=-3.5, xmax=3.5,
ymin=-2.3, ymax=2.3,
trig format=rad, % use radians
framed,
grid=both,
width=\textwidth,
title style={at={(axis cs:0,-3.2)}},
},
% not needed in the below, but you might like them for future
asymptote/.style={
color=red,mark=none,line width=1pt,dashed},
soldot/.style={
color=red,only marks,mark=*},
holdot/.style={
color=red,fill=white,only marks,mark=*},
}
% arrow style
\tikzset{>=stealth}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
group style={
group name=my plots,
group size=3 by 2,
},
width=.33\textwidth,
]
\nextgroupplot[title={$y=\sin(x)$}]
\addplot[timtam]expression[domain=-3.5:3.5]{sin(x)};
\nextgroupplot[title={$y=\cos(x)$}]
\addplot[timtam]expression[domain=-3.5:3.5]{cos(x)};
\nextgroupplot[title={$y=\tan(x)$}]
\addplot[timtam]expression[domain=-4.5:-1.58]{tan(x)};
\addplot[timtam]expression[domain=-1.56:1.55]{tan(x)};
\addplot[timtam]expression[domain=1.58:4.5]{tan(x)};
\nextgroupplot[title={$y=\csc(x)$}]
\addplot[timtam]expression[domain=-3.5:-3.2]{1/sin(x)};
\addplot[timtam]expression[domain=-3.1:-0.1]{1/sin(x)};
\addplot[timtam]expression[domain=0.1:3.1]{1/sin(x)};
\addplot[timtam]expression[domain=3.2:4.5]{1/sin(x)};
\nextgroupplot[title={$y=\sec(x)$}]
\addplot[timtam]expression[domain=-4.5:-1.58]{1/cos(x)};
\addplot[timtam]expression[domain=-1.56:1.56]{1/cos(x)};
\addplot[timtam]expression[domain=1.58:4.5]{1/cos(x)};
\nextgroupplot[title={$y=\cot(x)$}]
\addplot[timtam]expression[domain=-3.5:-3.2]{cot(x)};
\addplot[timtam]expression[domain=-3.1:-0.1]{cot(x)};
\addplot[timtam]expression[domain=0.1:3.1]{cot(x)};
\addplot[timtam]expression[domain=3.2:4.5]{cot(x)};
\end{groupplot}
\end{tikzpicture}
\end{document}
如果您需要对图形进行编号/引用,那么我建议使用命令\caption
,或许使用subfigure
包。