將表格資料​​置於右對齊 tabularx 標題下方居中

將表格資料​​置於右對齊 tabularx 標題下方居中

我正在嘗試對齊下表,以便“21”位於其標題下方的中心。

\begin{table}[h]
\centering
\begin{tabularx}{1.09\textwidth}{|cll>{\raggedleft\arraybackslash}X|}
\hline
\textbf{ID}     & \textbf{Severity}     & \textbf{Vulnerability}       &
\textbf{Occurrences} \\
\hline
111111         & Lorem                 & Lorem ipsum dolor sit amet & 21 \\
\hline
\end{tabularx}
\caption{example}
\label{table:example}
\end{table}

在此輸入影像描述

我可以使用\centering而不是\raggedleft最後一列將數字置於標題下方居中,但標題最終會過於靠左,我希望標題如上圖所示。

在此輸入影像描述

無論如何我可以得到這兩者的組合嗎?標題向右對齊,如第一張圖所示,但數字在標題下方居中,如第二張圖所示。

答案1

我將使用X第三個單元格的類型列而不是第四個單元格:\begin{tabularx}{1.09\textwidth}{|clXc|}。然後\makecell[r]{\textbf{Occurrences}}您可以右對齊標題:

\documentclass{article}

\usepackage{tabularx}
\usepackage{makecell}

\begin{document}
\begin{table}[h]
\centering
\begin{tabularx}{1.09\textwidth}{|clXc|}
\hline
\textbf{ID}     & \textbf{Severity}     & \textbf{Vulnerability}       &
\makecell[r]{\textbf{Occurrences}} \\
\hline
111111         & Lorem                 & Lorem ipsum dolor sit amet & 21 \\
\hline
\end{tabularx}
\caption{example}
\label{table:example}
\end{table}
\end{document}

相關內容