
Tengo la siguiente tabla de partes:
\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}
Me gustaría alinear el nombre "Nombre del elemento" y "Descripción" en el centro de la celda sin afectar el resto de las filas.
Respuesta1
Necesitas reemplazar
\textbf{Element Name} &
\textbf{Description}
con
\multicolumn{1}{|c||}{\textbf{Element Name}} &
\multicolumn{1}{c|}{\textbf{Description}}
En lugar de usar \adjustbox
para abarrotar la tabla al ancho del bloque de texto, considere usar un tabularx
entorno en lugar del tabular
entorno y usar una columna de tipo X
para la segunda columna. El texto de una X
columna se puede ajustar según sea necesario. También puedes considerar darle a la mesa un aspecto más "abierto", eliminando todas las líneas verticales y usando las líneas horizontales con menor frecuencia. En la siguiente captura de pantalla, la segunda tabla se dibuja con la ayuda de las macros de dibujo lineal del booktabs
paquete.
\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}
Respuesta2
Puede utilizar el makecell
paquete: su \thead
comando (y algunos otros comandos) permiten un formato común de su contenido y saltos de línea. Por defecto está centrado tanto vertical como horizontalmente. Puedes darle a las celdas algo de relleno vertical, con \setcellgapes
y \makegapedcells
comandos. Para intersecar claramente reglas dobles verticales y reglas horizontales, es mejor usar \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}