具有多行、多列和段落列类型的表格

具有多行、多列和段落列类型的表格

我想用 Latex 制作下表: 在此处输入图片描述

但第三列中的文本从下一行开始,从而导致列换行问题。

我应该如何更改代码才能修复此问题?

您可以在下面找到我编写的代码:

\documentclass[11pt,a4paper]{report}
\usepackage{array,multirow}
\begin{document}
\begin{table}[ht]
\caption{Multi-row table}
\begin{center}
\begin{tabular}{|c|c|p{3cm}|}
\hline
\multicolumn{3}{|c|}{\textbf{Responses}}\\ \hline
\multirow{2}{*}{1xx Info} & 100 trying \\ & 180 Ringing & The request has been received and is being handled.\\
\hline
\multirow{2}{*}{2xx Success} & 200 OK \\ & 202 Accepted & The request has been successfully received. \\
\hline
\end{tabular}
\end{center}
\label{tab:multicol}
\end{table}
\end{document}

谢谢

答案1

相同代码,略作修改

\documentclass[11pt,a4paper]{report}
\usepackage{array,multirow}
\begin{document}
\begin{table}[ht]
\caption{Multi-row table}
\begin{center}
\begin{tabular}{|c|p{2cm}|p{3cm}|}
\hline
\multicolumn{3}{|c|}{\textbf{Responses}}\\ \hline
\multirow{3}{*}{1xx Info} & 100 trying \qquad 180 Ringing& The request has been received and is being handled\\ \hline
\multirow{3}{*}{2xx Success} & 200 OK 202 Accepted & The request has been successfully received. \\
\hline
\end{tabular}
\end{center}
\label{tab:multicol}
\end{table}
\end{document}

桌子

答案2

我希望这就是你想要的。我使用了 egreg 在某处定义的“特殊单元格”。此命令为你提供了表格单元格内换行符的简单语法。最后,你会发现一个booktabs在垂直间距方面可能看起来更漂亮的表格版本。

% arara: pdflatex

\documentclass[11pt,a4paper]{report}
\usepackage[english]{babel}
\usepackage{array,multirow}
\usepackage{caption}
\newcommand{\specialcell}[2][c]{%
    \begin{tabular}[#1]{@{}c@{}}#2\end{tabular}}
\usepackage{microtype}
\usepackage{booktabs}

\begin{document}
\begin{table}[ht]
    \centering
    \caption{Multi-row table}\label{tab:multicol}
    \begin{tabular}{|c|c|p{4.6cm}|}
        \hline
        \multicolumn{3}{|c|}{\textbf{Responses}} \\
        \hline
        \multirow{2}{*}{1xx Info} & \specialcell[t]{$100$ trying\\$180$ ringing} & The request has been received and is being handled. \\
        \hline
        \multirow{2}{*}{2xx Success} & \specialcell[t]{$200$ OK\\$202$ Accepted}& The request has been successfully received. \\
        \hline
    \end{tabular}
\end{table}
\begin{table}
    \centering
    \caption{Multi-row table}\label{tab:multicol}
    \begin{tabular}{ccp{4.6cm}}
        \toprule
        \multicolumn{3}{c}{\textbf{Responses}} \\
        \midrule
        \multirow{2}{*}{1xx Info} & \specialcell[t]{$100$ trying\\$180$ ringing} & The request has been received and is being handled. \\
        \addlinespace
        \multirow{2}{*}{2xx Success} & \specialcell[t]{$200$ OK\\$202$ Accepted}& The request has been successfully received. \\
        \bottomrule
    \end{tabular}
\end{table}
\end{document}

在此处输入图片描述

如果您想要保留p{3cm},您可能需要将前两个单元格放入里面,\multicolumn{3}{*}{...}或者完全将其删除。

相关内容