我是一名物理学本科生,去年我开始使用 LaTeX 撰写报告。
在每次练习中,我都会在 Excel 中收集大量数据,通常需要将其表示出来(可能是为了使用最小二乘法计算某些东西,也可能只是为了将其可视化)。我喜欢 Excel 图表和表格格式,但我想将其集成到我的 LaTeX 代码中(而不是将其导入为 PDF)。
哪些软件包/工具具有这样的功能?(它不一定必须与 Excel 集成,我可以将我的数据导出为 CSV 或其他格式)。
答案1
我向物理专业的学生推荐以下套件。
对于编写问题解决方案,我谦虚地推荐曼迪包,由我编写并维护。它由三个包组成。第一个包,mandi
仅通过使用量的名称,就可以用正确的单位排版物理量。标量和矢量量都受支持,SI 基本单位和派生单位以及 SI 中可能不使用的替代单位也受支持。(请注意,mandi
目前与不兼容,siunitx
因为这两个包定义了多个具有相同名称的命令。)第二个包mandistudent
,除其他外,还提供问题和解决方案环境以及对程序列表的支持,重点是Web 虚拟 Python(又名 GlowScript)和虚拟Python第三个,mandiexp
提供 Chabay 和 Sherwood 的排版表达式的宏物质与互动但当然也可以不使用特定的文本。我已经使用这些材料近十年了。
对于现场进行数值计算,比如在你的书面解决方案中,我建议数值包。它先解析并预处理LaTeX
格式的方程式,然后再将其传递给浮点处理器进行评估。
许多人使用其他工具来绘制图表,但我更喜欢pfgplots
在我的文档中使用和执行它们,因为我喜欢尽可能少的文件。
由于您是物理学专业的学生,因此这里有一张狭义相对论中洛伦兹因子与速度(以光速为单位)的关系图。 提供了许多参数和设置,pgfplots
我鼓励您使用源代码中一些注释掉的行来尝试它们。请注意,我鼓励您使用引擎LuaLaTeX
。
% !TEX program = lualatexmk
% !TEX encoding = UTF-8 Unicode
\documentclass[border=0pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
declare function = {%
gamma(\x) = 1/sqrt(1-\x^2);%
%myx = 0.866;% pick a particular value
myx = 0.986013;% pick a particular value
},%
title style={font=\sffamily},%
title=Lorentz Factor vs. Speed,%
label style={font=\sffamily},%
%xlabel style={font=\sffamily},%
%ylabel style={font=\sffamily},%
xlabel=speed \(\frac{v}{c}\),%
ylabel={Lorentz factor \( \gamma \)},%
%ylabel style={align=center},ylabel={Lorentz\\ factor \( \gamma \)},%
tick label style={%
font=\scriptsize,%
/pgf/number format/precision=1,%
/pgf/number format/fixed,%
/pgf/number format/fixed zerofill,%
},%
%xticklabel style={%
% /pgf/number format/precision=3,
% /pgf/number format/fixed,
% /pgf/number format/fixed zerofill,
%},%
%yticklabel style={%
% /pgf/number format/precision=3,
% /pgf/number format/fixed,
% /pgf/number format/fixed zerofill,
%},%
%xticklabel style={font=\tiny},%
%yticklabel style={font=\tiny},%
xtick={0,0.2,...,1},%
ytick={1,2,...,10},%
extra x ticks={myx},%
extra tick style={%
tick label style={%
font=\tiny,%
/pgf/number format/precision=3,%
/pgf/number format/fixed,%
/pgf/number format/fixed zerofill,%
color=red,%
},%
xticklabel shift={8pt},%
yticklabel shift={12pt},%
},%
%extra x tick style={%
%every tick label/.style={font=\tiny},%
%/pgf/number format/precision=3,%
%/pgf/number format/fixed,%
%/pgf/number format/fixed zerofill,%
%xticklabel shift={8pt},%
%},%
extra y ticks={gamma(myx)},%
extra y tick style={%
tick label style={rotate=90},%
% every tick label/.style={font=\tiny},%
% /pgf/number format/precision=3,%
% /pgf/number format/fixed,%
% /pgf/number format/fixed zerofill,%
% yticklabel shift={25pt},%
},%
xmin=0,%
xmax=1.05,%
ymin=0,%
ymax=10,%
%domain=0:0.999, samples=200,% this affects actual plotting
]%
%-- main plot
%\addplot[blue, very thin, smooth] {1/sqrt(1-x^2)};
\addplot[blue, very thin, smooth, domain=0:0.999, samples=200] {gamma(x)};
\addplot[blue, mark=*, mark size=0.5pt] ({myx},{gamma(myx)});
%-- vertical asymptote
\draw[red, very thin, densely dashed] (1,0) -- (1,\pgfkeysvalueof{/pgfplots/ymax});
%-- horizontal asymptote
%\draw[red, very thin, densely dashed] (0,1) -- (\pgfkeysvalueof{/pgfplots/xmax},1);
%-- particular value
%\draw[red, very thin] (0,2.294) -- (0.9,2.294);
%\draw[red, very thin] (0.9,0) -- (0.9,2.294);
\draw[red, very thin] (0,{gamma(myx)}) -- (myx,{gamma(myx)});
\draw[red, very thin] (myx,0) -- (myx,{gamma(myx)});
\end{axis}
\end{tikzpicture}
\end{document}
这里是另一个例子,展示如何绘制一个函数(在本例中为二次函数)和一条切线,你可以通过改变一个变量来选择一点,如上面的洛伦兹因子图所示。
% !TEX program = lualatexmk
% !TEX encoding = UTF-8 Unicode
\documentclass[border=0pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
declare function = {%
f(\x) = \x^2; % function
df(\x) = 2*\x;% derivative
myx = 2.5; % pick a particular value
dx = 0.001; % increment
},%
title style={font=\sffamily},%
title=A Quadratic Function,%
label style={font=\sffamily},%
axis lines=left,%
xlabel={\( x \)},%
ylabel={\( f(x) \)},%
tick label style={%
font=\scriptsize,%
/pgf/number format/precision=1,%
/pgf/number format/fixed,%
/pgf/number format/fixed zerofill,%
},%
xtick={-5,-4,...,5},%
ytick={0,2,...,20},%
xmin=-5, xmax=5.5,%
ymin=0, ymax=20.5,%
extra x ticks={myx},%
extra y ticks={f(myx)},%
extra tick style={%
tick style=red,%
tick label style={%
font=\tiny,%
color=red,%
/pgf/number format/precision=3,%
/pgf/number format/fixed,%
/pgf/number format/fixed zerofill,%
},%
xticklabel shift={8pt},%
yticklabel shift={16pt},%
},%
extra y tick style={%
tick label style={rotate=90},%
},%
]%
%-- main plot
\addplot[blue, very thin, smooth, domain=-5:5, samples=100] {f(x)};
\addplot[blue, mark=*, mark size=0.5pt] ({myx},{f(myx)});
%-- particular value
\draw[red, very thin] (-5,{f(myx)}) -- (myx,{f(myx)});
\draw[red, very thin] (myx,0) -- (myx,{f(myx)});
%-- tangent line
\draw[green, thick, shorten >=-1cm, shorten <=-1cm] ({myx-dx},{f(myx-dx)}) -- ({myx+dx},{f(myx+dx)});
\end{axis}
\end{tikzpicture}
\end{document}
最后,这是在文档中包含图表的一个例子。第一个是在原地创建的,第二个是单独创建的并作为图形导入的。该图是上面的 Lorentz 因子图。对于这个例子,它被简单命名plot.pdf
并位于与文档相同的文件夹中。
% !TEX program = lualatexmk
% !TEX encoding = UTF-8 Unicode
\documentclass{article}
\usepackage{float}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
Let's create a plot of the Lorentz factor as a function of speed.
Let's begin by creating the plot in situ.
\begin{figure}[H]
\centering
\begin{tikzpicture}
\begin{axis}[%
declare function = {%
gamma(\x) = 1/sqrt(1-\x^2);%
%myx = 0.866;% pick a particular value
myx = 0.986013;% pick a particular value
},%
title style={font=\sffamily},%
title=Lorentz Factor vs. Speed,%
label style={font=\sffamily},%
%xlabel style={font=\sffamily},%
%ylabel style={font=\sffamily},%
xlabel=speed \(\frac{v}{c}\),%
ylabel={Lorentz factor \( \gamma \)},%
%ylabel style={align=center},ylabel={Lorentz\\ factor \( \gamma \)},%
tick label style={%
font=\scriptsize,%
/pgf/number format/precision=1,%
/pgf/number format/fixed,%
/pgf/number format/fixed zerofill,%
},%
%xticklabel style={%
% /pgf/number format/precision=3,
% /pgf/number format/fixed,
% /pgf/number format/fixed zerofill,
%},%
%yticklabel style={%
% /pgf/number format/precision=3,
% /pgf/number format/fixed,
% /pgf/number format/fixed zerofill,
%},%
%xticklabel style={font=\tiny},%
%yticklabel style={font=\tiny},%
xtick={0,0.2,...,1},%
ytick={1,2,...,10},%
extra x ticks={myx},%
extra tick style={%
tick label style={%
font=\tiny,%
/pgf/number format/precision=3,%
/pgf/number format/fixed,%
/pgf/number format/fixed zerofill,%
color=red,%
},%
xticklabel shift={8pt},%
yticklabel shift={12pt},%
},%
%extra x tick style={%
%every tick label/.style={font=\tiny},%
%/pgf/number format/precision=3,%
%/pgf/number format/fixed,%
%/pgf/number format/fixed zerofill,%
%xticklabel shift={8pt},%
%},%
extra y ticks={gamma(myx)},%
extra y tick style={%
tick label style={rotate=90},%
% every tick label/.style={font=\tiny},%
% /pgf/number format/precision=3,%
% /pgf/number format/fixed,%
% /pgf/number format/fixed zerofill,%
% yticklabel shift={25pt},%
},%
xmin=0,%
xmax=1.05,%
ymin=0,%
ymax=10,%
%domain=0:0.999, samples=200,% this affects actual plotting
]%
%-- main plot
%\addplot[blue, very thin, smooth] {1/sqrt(1-x^2)};
\addplot[blue, very thin, smooth, domain=0:0.999, samples=200] {gamma(x)};
\addplot[blue, mark=*, mark size=0.5pt] ({myx},{gamma(myx)});
%-- vertical asymptote
\draw[red, very thin, densely dashed] (1,0) -- (1,\pgfkeysvalueof{/pgfplots/ymax});
%-- horizontal asymptote
%\draw[red, very thin, densely dashed] (0,1) -- (\pgfkeysvalueof{/pgfplots/xmax},1);
%-- particular value
%\draw[red, very thin] (0,2.294) -- (0.9,2.294);
%\draw[red, very thin] (0.9,0) -- (0.9,2.294);
\draw[red, very thin] (0,{gamma(myx)}) -- (myx,{gamma(myx)});
\draw[red, very thin] (myx,0) -- (myx,{gamma(myx)});
\end{axis}
\end{tikzpicture}
\caption{Plot of Lorentz factor as a function of speed..}
\label{plot:1}
\end{figure}
Figure \ref{plot:1} is a great graph. Notice the asymptotic behavior as speed
approaches \(1\) (light's speed).
\newpage
Now let's import the graph from a file. Figure \ref{plot:2} was created externally and
imported as an image.
\begin{figure}[H]
\centering
\includegraphics{plot.pdf}
\caption{Plot of Lorentz factor as a function of speed.}
\label{plot:2}
\end{figure}
As you can see, the two plots are identical.
\end{document}
输出有两页。