將文字換行到表格儲存格中

將文字換行到表格儲存格中

我使用 TexLive 2022 使用文件類別編寫 Latex IEEEtran

我想將文字包裝在表格的單元格之一(“參與者數量”)中,如下所示:

期待

\documentclass[journal]{IEEEtran}
\usepackage{tabualarx,caption}
\begin{document}

\begin{table}[ht]

\renewcommand{\arraystretch}{1.25}
\captionof{table}{Participation}
\label{tab:example_MRT} 
\noindent\begin{tabularx}{\linewidth} { |
  c |
  >{\raggedright\arraybackslash}X |
}
  \hline
  \textbf{The number of participants} & \textbf{Destination} \\
  \hline
  $1$  & A \\
  \hline
  $2$ & B \\
  \hline
  $3$ & C\\
  \hline
  $4$ & D\\

  \hline
\end{tabularx}
\end{table}

\end{document}

然而,結果如下。

結果

需要增加什麼代碼才能將「參加人數」這兩個字換成兩行?

謝謝。

答案1

您可以\makecellmakecell包裝中使用

\documentclass[journal]{IEEEtran}
\usepackage{tabularx}
\usepackage{caption}
\usepackage{makecell}
\begin{document}

\begin{table}[ht]

\renewcommand{\arraystretch}{1.25}
\captionof{table}{Participation}
\label{tab:example_MRT} 
\noindent\begin{tabularx}{\linewidth} { |
  c |
  >{\raggedright\arraybackslash}X |
}
  \hline
  \textbf{\makecell{The number of\\participants}} & \textbf{Destination} \\
  \hline
  $1$  & A \\
  \hline
  $2$ & B \\
  \hline
  $3$ & C\\
  \hline
  $4$ & D\\

  \hline
\end{tabularx}
\end{table}

\end{document}

結果

與 無關但caption不相容IEEEtran,並且您\captionof破壞了表格標題設定。

相關內容