5

I want to make the following table in Latex: enter image description here

but the text in the third column begins in the next line, causing the issue with the column line break.

How should I change the code in order to fix this issue?

Below you can find the code I have written:

\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}

Thank you

cmhughes
  • 100,947
Maria
  • 53
  • Welcome! How do you want this to look like? Just two rows? Then increase the value to p{4cm} or more. – LaRiFaRi Apr 19 '16 at 13:11
  • Thanks!I did but the problem insists. Actually, I want the text of the third column to begin in the same row as "100 trying" and not in "180 Ringing" asit does now. – Maria Apr 19 '16 at 13:16

2 Answers2

3

Same code slightly modified

\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}

table

murugan
  • 1,669
2

I hope this is what you want. I used the "special cell" which has been defined by egreg somewhere. This command gives you an easy syntax for line breaks inside a table cell. In the end, you find a booktabs version of your table which might look nicer regarding the vertical spacing.

% 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}

enter image description here

If you want to stay with p{3cm}, you might want to put the first two cells inside a \multicolumn{3}{*}{...} or you get rid of it completely.

LaRiFaRi
  • 43,807