6

I am trying to create a table, but the content in the table cell is quite long, so I decided to create a new line for the cells.

But I am not sure how to do that, could someone help me on that? Here is my code:

\begin{table}[h!]
\caption{Multirow table}
\begin{center}
\begin{tabular}{ |c|c|c| } 
\hline
Observation(Species name)  & Likelihood (Limnodynastes peronii Distribution Model)  &Likelihood (Rhinella marina Distribution Model)\\
  \hline
     Observation 1 (Limnodynastes peronii) &0.0712 &0.2699\\
   \hline
    Observation 2 (Rhinella marina) &0.30 &0.013 \\
  \hline
\end{tabular}
\end{center}
\end{table}
1

2 Answers 2

7

One of possible solutions is using \multicolumn with proper parameters. In the second column lines are manually broken, in the third -- automatically, which does not look nice. However, the general idea should be clear. And p{4cm} should be rather replaced by a more suitable value.

\documentclass{article}

\begin{document   

\begin{table}[h!]
\caption{Multirow table}
\begin{center}
\begin{tabular}{ |c|c|c| } 
\hline
Observation(Species name)  & \multicolumn{1}{p{4cm}|}{Likelihood\newline (Limnodynastes peronii\newline Distribution Model) } &\multicolumn{1}{p{4cm}|}{Likelihood (Rhinella marina Distribution Model)}\\
  \hline
     Observation 1 (Limnodynastes peronii) &0.0712 &0.2699\\
   \hline
    Observation 2 (Rhinella marina) &0.30 &0.013 \\
  \hline
\end{tabular}
\end{center}
\end{table}

\end{document}


\begin{table}[h!]
\caption{Multirow table}
\begin{center}
\begin{tabular}{ |c|c|c| } 
\hline
Observation(Species name)  & Likelihood (Limnodynastes peronii Distribution Model)  &Likelihood (Rhinella marina Distribution Model)\\
  \hline
     Observation 1 (Limnodynastes peronii) &0.0712 &0.2699\\
   \hline
    Observation 2 (Rhinella marina) &0.30 &0.013 \\
  \hline
\end{tabular}
\end{center}
\end{table}

enter image description here

1

Another alternative is to use stacks, I show your table twice to show the variety possible. In the first table, the stacks are top aligned (\Longunderstacks) whereas in the 2nd table they are vertically centered (\Centerstacks). In the 1st table, they are centered horizontally, whereas they are left aligned in the 2nd table.

The two "set up" lines are needed before entering tabular, namely \edef\tmp{\the\baselineskip}\setstackgap{L}{\tmp} when using stacks in tabular, because tabular redefines \baselineskip, which is the default inter-baseline spacing for long stacks.

\documentclass{article}
\usepackage[usestackEOL]{stackengine}
\edef\tmp{\the\baselineskip}
\setstackgap{L}{\tmp}
\begin{document}
\begin{table}[h!]
\caption{Multirow table}
\begin{center}
\begin{tabular}{ |c|c|c| } 
\hline
Observation(Species name)  & \Longunderstack{Likelihood\\
   (Limnodynastes peronii\\ Distribution Model)}  & 
  \Longunderstack{Likelihood\\ (Rhinella marina \\Distribution Model)}\\
  \hline
     Observation 1 (Limnodynastes peronii) &0.0712 &0.2699\\
   \hline
    Observation 2 (Rhinella marina) &0.30 &0.013 \\
  \hline
\end{tabular}
\leavevmode\bigskip\\
\begin{tabular}{ |c|c|c| } 
\hline
Observation(Species name)  & \Centerstack[l]{Likelihood\\
   (Limnodynastes peronii\\ Distribution Model)}  & 
  \Centerstack[l]{Likelihood\\ (Rhinella marina \\Distribution Model)}\\
  \hline
     Observation 1 (Limnodynastes peronii) &0.0712 &0.2699\\
   \hline
    Observation 2 (Rhinella marina) &0.30 &0.013 \\
  \hline
\end{tabular}
\end{center}
\end{table}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .