![表格的 Latex 代码不起作用](https://linux22.com/image/454459/%E8%A1%A8%E6%A0%BC%E7%9A%84%20Latex%20%E4%BB%A3%E7%A0%81%E4%B8%8D%E8%B5%B7%E4%BD%9C%E7%94%A8.png)
这是我的乳胶代码 -
\documentclass{article}
\usepackage[utf8]{inputenc}
\title{test}
\author{Ved}
\date{September 2022}
\begin{document}
\maketitle
\section{Introduction}
\begin{table}[]
\begin{tabular}{|c|l|}
\hline
\begin{tabular}[c]{@{}c@{}}Overall order \\ of reaction\end{tabular} &
\multicolumn{1}{c|}{\begin{tabular}[c]{@{}c@{}}Units of rate constant (Remember \\ that time can be given in any units)\end{tabular}} \\ \hline
0 & \begin{tabular}[c]{@{}l@{}}\[\\ \frac{mol}{dm^{3} \times time} =mol\ dm^{-3} \ time^{-1}\\ \]\end{tabular} \\ \hline
1 & \begin{tabular}[c]{@{}l@{}}\[\\ \frac{1}{time} =time^{-1}\\ \]\end{tabular} \\ \hline
2 & \begin{tabular}[c]{@{}l@{}}\[\\ \frac{dm^{3}}{mol\times time} =dm^{3} \ mol^{-1} \ time^{-1}\\ \]\end{tabular} \\ \hline
3 & \begin{tabular}[c]{@{}l@{}}\[\\ \frac{dm^{6}}{mol^{2} \times time} =dm^{6} \ mol^{-2} \ time^{-1}\\ \]\end{tabular} \\ \hline
n &
\begin{tabular}[c]{@{}l@{}}\[\\ (\text{concentration})^{1-n} \times time^{-1}\]\\ can also be written as - \\ \[\left(\frac{mol}{dm^{3}}\right)^{1-n} \times time^{-1}\\ \]\end{tabular} \\ \hline
\end{tabular}
\end{table}
\end{document}
答案1
@samcarter_is_at_topanswers.xyz 答案的一个小版本。更改的是
- 表格样式,
- 软件包
amsmath
并作为库siunitx
加载tabularray
- 所有关于表格样式的说明都收录在表格序言中
tabularray
它可以与本地安装的软件包版本 2022C 以及现在在 Overleaf 上安装的软件包版本(已测试)配合良好。
\documentclass{article}
%--------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%
\usepackage{lipsum} % for dummy text
%---------------------------------------------------------------%
\usepackage{tabularray}
\UseTblrLibrary{amsmath, siunitx}
\begin{document}
\begin{table}[htbp]
\centering
\begin{tblr}{
hlines, vlines,
colspec = {Q[c, m, mode=math] Q[l, m, mode=dmath]},
row{1} = {mode=text},
row{2-Z}= {rowsep=5pt}
}
{Overall order\\ of reaction}
& {Units of rate constant\\ (Remember that time can be given in any units)} \\
0 & \frac{\unit{mol}}{\unit{dm^{3}} \times \text{time}} =\unit{mol. dm^{-3}} \text{time}^{-1} \\
1 & \frac{1}{\text{time}} =\text{time}^{-1} \\
2 & \frac{\unit{dm^{3}}}{\unit{mol}\times \text{time}} =\unit{dm^{3}.mol^{-1}}\text{time}^{-1} \\
3 & \frac{\unit{dm^{6}}}{\unit{mol^{2}} \times \text{time}} =\unit{dm^{6}.mol^{-2}}\text{time}^{-1} \\
n & \begin{aligned}
& (\text{concentration})^{1-n} \times \text{time}^{-1} \text{ can also be written}\\
& \text{as }\left(\frac{\unit{mol}}{\unit{dm^{3}}}\right)^{1-n} \times \text{time}^{-1}
\end{aligned} \\
\end{tblr}
\end{table}
\end{document}
(红线表示页面边框)
答案2
主要问题是您不能\[...\]
在单元格内使用。您可以改用$\displaystyle ...$
,但我认为使用该包会获得更好的结果tabularray
。
\text{...}
您也在代码中使用,但是amsmath
您的序言中缺少该包。
最后,您可能需要查看一下软件包,siunitx
以便正确地将您的单位设置为直立字体。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{siunitx}
\title{test}
\author{Ved}
\date{September 2022}
\usepackage{tabularray}
\begin{document}
\maketitle
\section{Introduction}
\begin{table}[htbp]
\begin{tblr}{
colspec={Q[c]X[mode=dmath]},
vlines,
hlines,
cells={valign=m}
}
Overall order of reaction & \SetCell{mode=text} Units of rate constant (Remember that time can be given in any units)\\
0 & \frac{\unit{mol}}{\unit{dm^{3}} \times \text{time}} =\unit{mol. dm^{-3}} \text{time}^{-1} \\
1 & \frac{1}{\text{time}} =\text{time}^{-1} \\
2 & \frac{\unit{dm^{3}}}{\unit{mol}\times \text{time}} =\unit{dm^{3}.mol^{-1}}\text{time}^{-1} \\
3 & \frac{\unit{dm^{6}}}{\unit{mol^{2}} \times \text{time}} =\unit{dm^{6}.mol^{-2}}
\text{time}^{-1} \\
n & (\text{concentration})^{1-n} \times \text{time}^{-1} $ can also be written as $ \displaystyle \left(\frac{\unit{mol}}{\unit{dm^{3}}}\right)^{1-n} \times \text{time}^{-1} \\
\end{tblr}
\end{table}
\end{document}