
Ich habe folgende Teiletabelle:
\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}
Ich möchte die Namen „Elementname“ und „Beschreibung“ in der Mitte der Zelle ausrichten, ohne die restlichen Zeilen zu beeinträchtigen.
Antwort1
Sie müssen ersetzen
\textbf{Element Name} &
\textbf{Description}
mit
\multicolumn{1}{|c||}{\textbf{Element Name}} &
\multicolumn{1}{c|}{\textbf{Description}}
Anstatt \adjustbox
die Tabelle in die Breite des Textblocks zu quetschen, sollten Sie eine tabularx
Umgebung anstelle der tabular
Umgebung verwenden und X
für die zweite Spalte eine Spalte vom Typ verwenden. Text in einer X
Spalte kann nach Bedarf umbrochen werden. Sie können der Tabelle auch ein „offeneres“ Aussehen verleihen, indem Sie alle vertikalen Linien entfernen und horizontale Linien sparsamer verwenden. Im folgenden Screenshot wird die zweite Tabelle mithilfe der Linienzeichnungsmakros des booktabs
Pakets gezeichnet.
\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}
Antwort2
Sie können das Paket verwenden makecell
: dessen \thead
Befehl (und einige andere Befehle) ermöglichen eine gemeinsame Formatierung des Inhalts und Zeilenumbrüche. Standardmäßig ist es sowohl vertikal als auch horizontal zentriert. Sie können Zellen mit \setcellgapes
und \makegapedcells
Befehlen eine vertikale Polsterung zuweisen. Für eine saubere Überschneidung vertikaler Doppellinien und horizontaler Linien ist es besser, \hhline
s zu verwenden:
\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}