如何垂直对齐表格中的标题内容(电场),并最终增加其行高?
\documentclass{article}
\usepackage{array}
\usepackage{amsmath}
\usepackage{microtype}
\usepackage{xcolor}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
\newcolumntype{N}{@{}m{0pt}@{}}
\newcommand{\tr}[1]{#1 &\\[22pt]}
\begin{document}
\begin{center}
\begin{tabular}{ |M{4cm}|M{4cm}|N }
\hline
\multicolumn{3}{|c|}{Electric Field} \\
\hline
\tr{Point charge & $\vec{E} = \dfrac{1}{4 \pi \epsilon_0} \cdot \dfrac{q}{r^3} \times \vec{r}$}
\hline
\tr{Electric dipole & $\vec{E} = \dfrac{1}{2 \pi \epsilon_0} \cdot \dfrac{\vec{p}}{r^3}$}
\hline
\tr{Charged ring & $\vec{E} = \dfrac{1}{4 \pi \epsilon_0} \cdot \dfrac{q\vec{z}}{\sqrt{(r^{2}+z^{2})^3}}$}
\hline
\end{tabular}
\end{center}
\end{document}
答案1
以下 MWE 包含两个建议:第一个使用不可见规则来仅增加第一行的行高,而第二个是使用包中的和 的替代方法\toprule
,\midrule
同时避免所有垂直线:\bottomrule
booktabs
\documentclass{article}
\usepackage{array}
\usepackage{amsmath}
\usepackage{microtype}
\usepackage{xcolor}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
\newcolumntype{N}{@{}m{0pt}@{}}
\newcommand{\tr}[1]{#1 &\\[22pt]}
\usepackage{booktabs}
\begin{document}
\begin{center}
\begin{tabular}{ |M{4cm}|M{4cm}|N }
\hline
\multicolumn{3}{|c|}{\rule{0pt}{2em}Electric Field\rule[-1em]{0pt}{2em}} \\
\hline
\tr{Point charge & $\vec{E} = \dfrac{1}{4 \pi \epsilon_0} \cdot \dfrac{q}{r^3} \times \vec{r}$}
\hline
\tr{Electric dipole & $\vec{E} = \dfrac{1}{2 \pi \epsilon_0} \cdot \dfrac{\vec{p}}{r^3}$}
\hline
\tr{Charged ring & $\vec{E} = \dfrac{1}{4 \pi \epsilon_0} \cdot \dfrac{q\vec{z}}{\sqrt{(r^{2}+z^{2})^3}}$}
\hline
\end{tabular}
\end{center}
\begin{center}
\begin{tabular}{M{4cm}M{4cm}N }
\toprule
\multicolumn{3}{c}{\rule{0pt}{2em}Electric Field\rule[-1em]{0pt}{2em}} \\
\midrule
\tr{Point charge & $\vec{E} = \dfrac{1}{4 \pi \epsilon_0} \cdot \dfrac{q}{r^3} \times \vec{r}$}
\tr{Electric dipole & $\vec{E} = \dfrac{1}{2 \pi \epsilon_0} \cdot \dfrac{\vec{p}}{r^3}$}
\tr{Charged ring & $\vec{E} = \dfrac{1}{4 \pi \epsilon_0} \cdot \dfrac{q\vec{z}}{\sqrt{(r^{2}+z^{2})^3}}$}
\bottomrule
\end{tabular}
\end{center}
\end{document}
有关如何更改行高的更多信息,您还可以查看此处:表格中的列和行填充和这里:增加 LaTeX 表格行高
答案2
一个简单的解决方案是使用cellspace
,它允许您使用以字母为前缀的说明符S
(或者C
如果您使用siunitx
)定义列中单元格顶部和底部的最小垂直间距。您不必\tr
为间距定义此命令:
\documentclass{article}
\usepackage{array}
\usepackage{amsmath}
\usepackage{microtype}
\usepackage{xcolor}
\usepackage{cellspace}
\setlength{\cellspacetoplimit}{6pt}
\setlength{\cellspacebottomlimit}{6pt}
\newcolumntype{M}[1]{>{\centering\arraybackslash}S{m{#1}}}
\newcolumntype{N}{@{}m{0pt}@{}}
\newcommand{\tr}[1]{#1 &\\}
\begin{document}
\begin{center}
\begin{tabular}{ |M{4cm}|M{4cm}|N }
\hline
\multicolumn{3}{|Sc|}{Electric Field} \\
\hline
Point charge & $\vec{E} = \dfrac{1}{4 \pi \epsilon_0} \cdot \dfrac{q}{r^3} \times \vec{r}$ & \\
\hline
Electric dipole & $\vec{E} = \dfrac{1}{2 \pi \epsilon_0} \cdot \dfrac{\vec{p}}{r^3}$ \\
\hline
Charged ring & $\vec{E} = \dfrac{1}{4 \pi \epsilon_0} \cdot \dfrac{q\vec{z}}{\sqrt{(r^{2}+z^{2})^3}}$ & \\
\hline
\end{tabular}
\end{center}
\end{document}
答案3
您可以使用该bigstrut
包或者定义您自己的支柱作为\mystrut{<length in pt>}
示例。
\documentclass{article}
\usepackage{array}
\usepackage{amsmath}
\usepackage{microtype}
\usepackage{xcolor}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
\newcommand{\mystrut}[1]{$\vcenter{\hbox{\rule{0pt}{#1pt}}}$}
\begin{document}
\begin{center}
\begin{tabular}{|M{4cm}|>{$}M{4cm}<{$}|}
\hline
\multicolumn{2}{|c|}{Electric Field\mystrut{30}} \\ \hline
Point charge\mystrut{30} & \vec{E} = \dfrac{1}{4\pi \epsilon_0} \cdot \dfrac{q}{r^3} \times \vec{r} \\ \hline
Electric dipole\mystrut{30} & \vec{E} = \dfrac{1}{2\pi \epsilon_0} \cdot \dfrac{\vec{p}}{r^3} \\ \hline
Charged ring\mystrut{30} & \vec{E} = \dfrac{1}{4\pi \epsilon_0} \cdot\dfrac{q\vec{z}}{\sqrt{(r^{2}+z^{2})^3}} \\ \hline
\end{tabular}
\end{center}
\end{document}