我有以下零件表:
\begin{table}[!h]
\centering
\begin{adjustbox}{width=1\textwidth}
\small
\begin{tabular}{|l||l|}
\hline
\textbf{Element Name} & \textbf{Description} \\
\hline
SemiMajorAxis & The length of the semi-major axis $a$, $b$ and $c$ of the 3D \\\hline
\end{tabular}
\end{adjustbox}
\caption[A description of the XML elements containing the ellipsoid information]{A description of the XML elements containing the information of the ellipsoid.}
\label{tab:XML_defs}
\end{table}
我想将名称“元素名称”和“描述”对齐到单元格的中心而不影响其余行。
答案1
你需要更换
\textbf{Element Name} &
\textbf{Description}
和
\multicolumn{1}{|c||}{\textbf{Element Name}} &
\multicolumn{1}{c|}{\textbf{Description}}
不要使用\adjustbox
将表格塞进文本块的宽度,而是考虑使用tabularx
环境而不是tabular
环境,并使用类型的列X
作为第二列。X
列中的文本可以根据需要换行。您可能还想考虑通过删除所有垂直线并更谨慎地使用水平线来使表格看起来更“开放”。在下面的屏幕截图中,第二个表格是借助包的线条绘制宏绘制的booktabs
。
\documentclass{article}
\usepackage{tabularx,booktabs}
\begin{document}
\begin{table}[!h]
\begin{tabularx}{\textwidth}{|l||X|}
\hline
\multicolumn{1}{|c||}{\textbf{Element Name}} &
\multicolumn{1}{c|}{\textbf{Description}} \\
\hline
SemiMajorAxis & The length of the semi-major axis $a$, $b$ and $c$ of the 3D \\
\hline
\end{tabularx}
\caption[A description of the XML elements containing the ellipsoid information]{A description of the XML elements containing the information of the ellipsoid.}
\label{tab:XML_defs}
\bigskip\bigskip
\begin{tabularx}{\textwidth}{lX}
\toprule
\textbf{Element Name} & \textbf{Description} \\
\addlinespace
SemiMajorAxis & The length of the semi-major axis $a$, $b$ and $c$ of the 3D \\
\bottomrule
\end{tabularx}
\caption{Another, more ``open'' form of the same table}
\end{table}
\end{document}
答案2
您可以使用makecell
包:它的\thead
命令(和一些其他命令)允许对其内容和换行符进行通用格式设置。默认情况下,它是垂直和水平居中的。您可以使用\setcellgapes
和\makegapedcells
命令为单元格提供一些垂直填充。为了整齐地交叉垂直双规则和水平规则,最好使用\hhline
s:
\documentclass{article}
\usepackage{adjustbox, array, hhline}
\usepackage{makecell}
\renewcommand\theadfont{\normalfont\bfseries}
\setcellgapes{4pt}
\usepackage[showframe]{geometry}
\begin{document}
\vspace*{1cm}
\begin{table}[!h]
\centering\makegapedcells
\begin{tabular}{|l||l|}
\hline
\thead{Element Name} & \thead{Description} \\
\hhline{|-||-|}
SemiMajorAxis & The length of the semi-major axis $a$, $b$ and $c$ of the 3D \\\hline
\end{tabular}%
\caption[A description of the XML elements containing the ellipsoid information]{A description of the XML elements containing the information of the ellipsoid.}
\label{tab:XML_defs}
\end{table}
\end{document}