表のヘッダーを中央揃えにする

表のヘッダーを中央揃えにする

次の部品表があります:

\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環境の代わりに環境を使用し、 2 番目の列にtabular型の列を使用することを検討してください。列内のテキストは、必要に応じて折り返されます。また、すべての垂直線を取り除き、水平線を控えめに使用することで、テーブルをより「オープン」な外観にすることも検討してください。次のスクリーンショットでは、2 番目のテーブルはパッケージの線描画マクロを使用して描画されています。XXbooktabs

ここに画像の説明を入力してください

\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。垂直の二重線と水平線をきれいに交差させるには、 s を\makegapedcells使用することをお勧めします。\hhline

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

ここに画像の説明を入力してください

関連情報