alinhamento central dos cabeçalhos na tabela

alinhamento central dos cabeçalhos na tabela

Tenho a seguinte tabela de peças:

\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}

Gostaria de alinhar o nome "Nome do Elemento" e "Descrição" no centro da célula sem afetar o restante das linhas.

Responder1

Você precisa substituir

\textbf{Element Name} & 
\textbf{Description}

com

\multicolumn{1}{|c||}{\textbf{Element Name}} & 
\multicolumn{1}{c|}{\textbf{Description}}

Em vez de usar \adjustboxpara comprimir a tabela na largura do bloco de texto, considere usar um tabularxambiente em vez do tabularambiente e usar uma coluna do tipo Xpara a segunda coluna. O texto em uma Xcoluna pode ser quebrado, conforme necessário. Você também pode considerar dar à mesa uma aparência mais "aberta", eliminando todas as linhas verticais e usando linhas horizontais com mais moderação. Na captura de tela a seguir, a segunda tabela é desenhada com a ajuda das macros de desenho de linha do booktabspacote.

insira a descrição da imagem aqui

\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}

Responder2

Você pode usar o makecellpacote: seu \theadcomando (e alguns outros comandos) permitem uma formatação comum de seu conteúdo e quebras de linha. Por padrão, ele é centralizado vertical e horizontalmente. Você pode dar às células algum preenchimento vertical, com comandos \setcellgapese \makegapedcells. Para cruzar réguas duplas verticais e réguas horizontais com precisão, é melhor usar \hhlines:

\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}

insira a descrição da imagem aqui

informação relacionada