I'm trying to make a text wrapped in a cell. I read that I can use p{width} if I want to make the text wrapped. The cell width change following the width that I set, but the text still not wrapped. Any idea?
This is my tex code :
\begin{table}
\centering
\caption{Contoh pesan dan topik untuk menghidupkan lampu}
\label{tab:nyalainLampu}
\begin{tabular}{| p{4cm} | p{10cm} |}
\hline
\textbf{Topik} & \texttt{sot/g/[idUser]/lampu/[idPerangkat]/on/ctl} \\
\hline
\textbf{Isi pesan} & \texttt{true} \\
\hline
\textbf{Perintah REST} & \texttt{PUT http://localhost:8080/api/LUQMANGWTA/lights/[idLokal]/state}\\
\hline
\textbf{Data yang dikirimkan} & \texttt{\{"on":true\}} \\
\hline
\textbf{Respon deCONZ} & \texttt{[\{"success":\{"/lights/[idLokal]/state/on":true\}\}]} \\
\hline
\end{tabular}
\end{table}
And this is the result :
Thank you.
Best Answer
Your table has two problems, not just one:
To get better line-breaking in the second column, I suggest you load the
url
package and replace all five instances of\texttt
with\url
. LaTeX will usually find pretty good line breaks for material encased in a\url
statement.The tabular material is too wide for the available text block (unless the sheet of paper is unusually wide and/or the page margins are unusually narrow). Instead of hard-coding the widths of the two columns of the
tabular
environment, I would use atabularx
environment (with width set totextwidth
) and anX
column type for the second column. That way, it's guaranteed that the table's width won't exceed the width of the text block.Addendum With a bit more cleaning up, and getting rid of clutter my omitting the vertical lines and most horizontal lines, one gets the following look: