Search code examples
latexword-wrap

How do we wrap text in a longtable in Overleaf?


I am using the following syntax on Overleaf. However, the first header is spilling off into the second column. I tried using p{0.75\linewidth} as well, but it did not work. Any suggestions?

\documentclass[12pt]{article}
\begin{center}
\begin{table}[h!]
\caption{Table 17}
\begin{tabular}{|m{5cm}|m{1.25cm}|m{1cm}|m{1.25cm}|m{1cm}|m{1.25cm}|m{1cm}|m{1.25cm}|m{1cm}|}
\hline
\multicolumn{1}{|p{5cm}|}{\multirow{2}{*}{\textbf{Land Use/Land Cover Categories}}} & \multicolumn{2}{|c|}{\textbf{1977}} & \multicolumn{2}{|c|}{\textbf{1993}} & \multicolumn{2}{|c|}{\textbf{2006}} & \multicolumn{2}{|c|}{\textbf{2014}} \\
\cline{2-9}
 \multicolumn{1}{|c|}{} & \textbf{Area (km2)} & \textbf{Area (\%)} & \textbf{Area (km2)} & \textbf{Area (\%)} & \textbf{Area (km2)} & \textbf{Area (\%)} & \textbf{Area (km2)} & \textbf{Area (\%)} \\
 \hline
Dense forest & 149.84 & 10.10 & 164.83 & 11.11 & 55.49 & 3.74 & 71.10 & 4.79\\
\hline
Open forest & 107.11 & 7.22 & 110.77 & 7.47 & 99.51 & 6.71 & 112.52 & 7.59\\
\hline
\end{tabular}
\end{table}
\end{center}

Solution

  • I tried to arrange it, but it would be crucial to know your full header before (MWE).

    \documentclass[12pt]{article}
    \usepackage{multirow}
    
    \begin{document}
    
    \begin{table}%[h!]
    \caption{Table 17}
    \begin{tabular}{|p{2.75cm}|p{1.25cm}|p{1cm}|p{1.25cm}|p{1cm}|p{1.25cm}|p{1cm}|p{1.25cm}|p{1cm}|}
    \hline
    \multirow{2}{*}{\parbox{2.75cm}{\textbf{Land Use/\\Land Cover\\Categories}}} & %
    \multicolumn{2}{|c|}{\textbf{1977}} & \multicolumn{2}{|c|}{\textbf{1993}} & %
    \multicolumn{2}{|c|}{\textbf{2006}} & \multicolumn{2}{|c|}{\textbf{2014}}\\
    \cline{2-9}
     & \textbf{Area (km2)} & \textbf{Area (\%)} & \textbf{Area (km2)} & \textbf{Area (\%)} & %
    \textbf{Area (km2)} & \textbf{Area (\%)} & \textbf{Area (km2)} & \textbf{Area (\%)}\\
    \hline
    Dense forest & 149.84 & 10.10 & 164.83 & 11.11 & 55.49 & 3.74 & 71.10 & 4.79\\
    \hline
    Open forest & 107.11 & 7.22 & 110.77 & 7.47 & 99.51 & 6.71 & 112.52 & 7.59\\
    \hline
    \end{tabular}
    \end{table}
    
    \end{document}
    

    This code must be tuned accordingly with page margins (yours are not known) and so on but, for now, it outputs this table:

    screenshot of output