梅威瑟:
\documentclass{article}
\usepackage[a4paper,top=0.7in,bottom=0.4in,left=0.5in,right=0.5in,headheight=14.5pt]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[misc]{ifsym}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage{amssymb}
\begin{document}
\begin{tabular}{|c|c|c|c|c|c|}
\hline
$\theta$ & $0$ & $30$ & $45$ & $60$ & $90$ \\ \hline
$\sin$ & $0$ & $\dfrac{1}{2}$ & $\dfrac{1}{\sqrt{2}}$ & $\dfrac{\sqrt{3}}{2}$ & $1$ \\ \hline
$\cos$ & $1$ & $\dfrac{\sqrt{3}}{2}$ & $\dfrac{1}{\sqrt{2}}$ & $\dfrac{1}{2}$ & $0$ \\ \hline
$\tan$ & $0$ & $\dfrac{1}{\sqrt{3}}$ & $1$ & $\sqrt{3}$ & Not Defined \\ \hline
$\mathrm{cosec\,}$ & Not Defined & $2$ & $\sqrt{2}$ & $\dfrac{2}{\sqrt{3}}$ & $1$ \\ \hline
$\sec$ & $1$ & $\dfrac{2}{\sqrt{3}}$ & $\sqrt{2}$ & $2$ & Not Defined \\ \hline
$\cot$ & Not Defined & $\sqrt{3}$ & $1$ & $\dfrac{1}{\sqrt{3}}$ & $0$ \\ \hline
\end{tabular}
\end{document}
问题:
我正在寻找以下问题的答案,(i)列宽相等且行高相等(ii)文本必须在单元格中心对齐。
答案1
以下 MWE 生成具有相等行高和相等列宽的表格:
\documentclass{article}
\usepackage[a4paper,top=0.7in,bottom=0.4in,left=0.5in,right=0.5in,headheight=14.5pt]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\usepackage{array}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
\newcolumntype{P}[1]{%
>{\vbox to 5ex\bgroup\vfill\centering}%
p{#1}%
<{\egroup}}
\begin{document}
\begin{tabular}{|P{2cm}|*{5}{M{2cm}|}}
\hline
$\theta$ & $0$ & $30$ & $45$ & $60$ & $90$ \\
\hline
$\sin$ & $0$ & $\dfrac{1}{2}$ & $\dfrac{1}{\sqrt{2}}$ & $\dfrac{\sqrt{3}}{2}$ & $1$ \\
\hline
$\cos$ & $1$ & $\dfrac{\sqrt{3}}{2}$ & $\dfrac{1}{\sqrt{2}}$ & $\dfrac{1}{2}$ & $0$ \\
\hline
$\tan$ & $0$ & $\dfrac{1}{\sqrt{3}}$ & $1$ & $\sqrt{3}$ & Not Defined \\
\hline
$\mathrm{cosec\,}$ & Not Defined & $2$ & $\sqrt{2}$ & $\dfrac{2}{\sqrt{3}}$ & $1$ \\
\hline
$\sec$ & $1$ & $\dfrac{2}{\sqrt{3}}$ & $\sqrt{2}$ & $2$ & Not Defined \\
\hline
$\cot$ & Not Defined & $\sqrt{3}$ & $1$ & $\dfrac{1}{\sqrt{3}}$ & $0$ \\
\hline
\end{tabular}
\end{document}
因此,我使用了两种新定义的列类型M
和P
。M
垂直和水平居中其条目,而P
产生等高行。(注意:P
借用了 Alain Matthes 的回答)
输出结果如下:
如果您喜欢较窄的列,则可以将宽度规格(上例中为 2cm)更改为例如 1.25cm。这样,您将获得以下结果,其中“未定义”条目会自动换行: