Latex table 单元格中包含换行文本

Latex table with wrapped text in cells

第二列中的文本显示在第一列中。我不知道为什么?有什么建议吗?

\begin{table*} 
\begin{tabular}{|p{8cm}|p{8cm}|} 
\hline \textbf{Heading 1}\\Text \ 
& \textbf{Heading 2}\ Text \ 
\hline 
\end{tabular} 
\end{table*}

Latex 表格是横向格式化的:& 分隔 cells/columns,\ 表示一行单元格的结尾。 将第一行指定为

A & B \

第二行为

C & D \

所以你的案例应该被编码:

\documentclass{article}

\begin{document}

\begin{table*} 
\begin{tabular}{|p{4cm}|p{4cm}|} 
\hline \textbf{Heading 1} & \textbf{Heading 2}\
  Text col 1 with plenty of extra text
  &Text col 2 with plenty of extra text\ 
\hline 
\end{tabular} 
\end{table*}

\end{document}

(出于显示目的,我已经减小了单元格的宽度。)

如果您想要在给定的单元格中换行,只需在输入文件中保留一个空行即可。这里有两种不同的文本处理方式。

\documentclass{article}

\begin{document}

\begin{table*} 
\begin{tabular}{|p{4cm}|p{4cm}|} 
\hline \textbf{Heading 1} & \textbf{Heading 2}\
  Text col 1 with plenty of extra text.

  And more lines of text in column one.

  Yet more lines.
  &Text col 2 with plenty of extra text.\ 
\hline 
\end{tabular} 
\end{table*}

\begin{table*} 
\begin{tabular}{|p{4cm}|p{4cm}|} 
\hline \textbf{Heading 1} 

  Text col 1 with plenty of extra text.

  And more lines of text in column one.

  Yet more lines.
  &\textbf{Heading 2} 

    Text col 2 with plenty of extra text.\ 
\hline 
\end{tabular} 
\end{table*}

\end{document}

两个表现在都产生: