Search code examples
textlatexword-wrap

How to wrap text in LaTeX tables?


I am creating a report using LaTeX, however, the cell data in the table is exceeding the width of the page.

How can I wrap the text so that it falls into the next line within the same cell of the table?

Is the solution somehow related to specifying the table's width? As the table is exceeding the page's width, would specifying the table's width make a difference?


Solution

  • Use p{width} for your column specifiers instead of l/r/c.

    \begin{tabular}{|p{1cm}|p{3cm}|}
      This text will be wrapped & Some more text \\
    \end{tabular}
    

    EDIT: (based on the comments)

    \begin{table}[ht]
        \centering
        \begin{tabular}{p{0.35\linewidth} | p{0.6\linewidth}}
          Column 1  & Column2 \\ \hline
          This text will be wrapped & Some more text \\
          Some text here & This text maybe wrapped here if its tooooo long \\
        \end{tabular}
        \caption{Caption}
        \label{tab:my_label}
    \end{table}
    

    we get:

    enter image description here