2

I'm making tables describing my models and I don't know how to put multiline equations inside a table. I tried using multirow, but the results are super weird, and I tried using align* inside a cell, but I got an error.

The closest thing I got to work is using a tabular inside a cell, but the layout is a bit weird: the text cells have a weird padding on top, while the equations cells have no padding.

\documentclass{report}
\usepackage[table,xcdraw]{xcolor}
\usepackage{multirow,rotating,lscape,amsmath}
\usepackage{booktabs,siunitx,ragged2e}
\begin{document}
    \begin{landscape}
    \begin{table}
    \centering
        \label{submodels-for-derived-variables}
        \begin{tabular}{|p{0.3\textwidth}|p{0.3\textwidth}|p{0.4\textwidth}|}
            \textbf{Modelled variable}
            & \textbf{Parameters}
            & \textbf{Formula}\\ 
            \hline
            Fire spread probability from cell \textit{a} to cell \textit{b}, \textit{plain} topography
            & Grass flammability parameter (\textit{f}), grass cell \textit{b} biomass (\textit{Bb})
            & $F_{\text{ab}} = \text{fB}_{b}$ \\ 
            \hline
            Fire spread probability from cell \textit{a} to cell \textit{b}, non-plain topography
            & Grass flammability parameter (f), grass biomass (Bb), slope between \textit{a} and \textit{b} (\textit{sab})
            & \begin{tabular}{lll}
                        $F_t =fB_b,$            & $s  >= 0.4,$ \\
                        $F_t =( s+0.6 )fB_b,$   &$s \in (-0.4,0.4)$\\
                        $F_t =0.2fB_b,$         &$s <= -0.4   $ \\
            \end{tabular}\\

            \hline
        \end{tabular}
    \end{table}
    \end{landscape}
\end{document}

table image

3 Answers 3

4

You could use the cool new tabularray package:

\documentclass{report}
\usepackage[table,xcdraw]{xcolor}
\usepackage{multirow,rotating,lscape,amsmath}
\usepackage{booktabs,siunitx,ragged2e}
\usepackage{tabularray}
\begin{document}
    \begin{landscape}
    \begin{table}
    \centering
        \begin{tblr}{vlines,hlines,colspec={X[l,valign=m]X[l,valign=m]Q[l,valign=m]}}
            \textbf{Modelled variable}
            & \textbf{Parameters}
            & \textbf{Formula}  \\ 
            Fire spread probability from cell \textit{a} to cell \textit{b}, \textit{plain} topography
            & Grass flammability parameter (\textit{f}), grass cell \textit{b} biomass (\textit{Bb})
            &  $F_{\text{ab}} = \text{fB}_{b}$ \\ 
            Fire spread probability from cell \textit{a} to cell \textit{b}, non-plain topography
            & Grass flammability parameter (f), grass biomass (Bb), slope between \textit{a} and \textit{b} (\textit{sab})
            & \begin{tblr}{@{}ll@{}}  
              $F_t =fB_b,$           &  $s  >= 0.4,$ \\
              $F_t =( s+0.6 )fB_b,$ &  $s \in (-0.4,0.4)$\\
              $F_t =0.2fB_b,$       &  $s <= -0.4   $ \\
            \end{tblr}\\
        \end{tblr}
    \end{table}
    \end{landscape}
\end{document}

enter image description here

3
  • You can also omit the valign and just write e.g. X[l,m]. For the underlined keys in the tabularray documentation one can usually just use the value without the key.
    – marv
    Commented Jan 31, 2022 at 3:28
  • is it tabularry or tabularray?
    – MOzSalles
    Commented Jan 31, 2022 at 15:15
  • how do I install this package? it doesn't seem to be inscluded in my miktex distribution
    – MOzSalles
    Commented Jan 31, 2022 at 15:42
2

Your alignment can be fixed by passing an optional argument to tabular. Here's a remake of your table using booktabs and tabularx:

enter image description here

\documentclass{article}

\usepackage[margin=1in,landscape]{geometry}
\usepackage{booktabs,amsmath,tabularx}

\begin{document}

\begin{table}
  \centering
  \begin{tabularx}{\linewidth}{ p{0.3\linewidth} p{0.3\linewidth} X }
    \toprule
    \textbf{Modelled variable} & 
      \textbf{Parameters} &
      \textbf{Formula} \\ 
    \midrule
    Fire spread probability from cell \textit{a} to cell \textit{b}, \textit{plain} topography & 
      Grass flammability parameter (\textit{f}), grass cell \textit{b} biomass (\textit{Bb}) & 
      $F_{\text{ab}} = \text{fB}_{b}$ \\ 
    \addlinespace
    Fire spread probability from cell \textit{a} to cell \textit{b}, non-plain topography & 
      Grass flammability parameter (f), grass biomass (Bb), slope between \textit{a} and \textit{b} (\textit{sab}) &
      \begin{tabular}[t]{ @{} l l @{} }
        $F_t = fB_b$,            & $s \geq 0.4$,        \\
        $F_t = (s + 0.6) fB_b$,  & $s \in (-0.4, 0.4)$, \\
        $F_t = 0.2 fB_b$,        & $s \leq -0.4$.
      \end{tabular} \\
    \bottomrule
  \end{tabularx}
\end{table}

\end{document}

Note the use of \begin{tabular}[t] to set the anchor point for the tabular to the [t]op.

Your original table is too wide for the page; the column widths add up to \textwidth, but there is horizontal padding around each column, as well as the vertical rule widths. In such cases where you want a full-width table, but you're not sure about the column width calculations, consider using tabularx (with at least one X-column).

2

With use of amsmath and tabularray (version 2021Q) package.

Edit: Writing of variables seems to be inconsistent. I try to write all of them in math mode. If this is not what you after, revert these changes to your notation (with \textit ...)

\documentclass{report}

\usepackage{pdflscape}
\usepackage{amsmath}
\usepackage{xcolor}
\usepackage{tabularray}

\begin{document}
\begin{landscape}
    \begin{table}
        \begin{tblr}{vlines,hlines,
                     colspec={X[l,m] X[l,m] X[l,m,$]},
                     row{1} = {font=\bfseries, mode=text, c}
                     }
Modelled variable 
    &   Parameters 
        &   Formula                         \\
Fire spread probability from cell $a$ to cell $b$, plain topography
    & Grass flammability parameter $(f)$, grass cell $b$ biomass $(B_b)$
        &   F_{\text{ab}} = fB_{b}   \\
Fire spread probability from cell $a$ to cell $b$, non-plain topography
    &   Grass flammability parameter $(f)$, grass biomass $(B_{b})$, slope between $a$ and $b$ $(\mathit{sab})$
        &   F_t = \begin{cases}
                f B_b,          &   s \geq 0.4,           \\
                (s + 0.6)fB_b,  &   s \in (-0.4,0.4)    \\
                0.2fB_b,        &   s \leq -0.4           \\
            \end{cases}                     \\
        \end{tblr}
    \end{table}
\end{landscape}
\end{document}

enter image description here

2
  • thank-you for fixing all the inconsistencies in my code! they were created by an amateur pandoc translation... I also didn't know about cases, so this fixes all my problems! why did you change lscape to pdflscape tho?
    – MOzSalles
    Commented Jan 31, 2022 at 15:08
  • @MOzSalles, pdflscape and lscape difer how the landscape is presented on the scree, pdflscape turn page so, that we can easy read, however meanwhile lscape not. In the printed document both produced the same (right) result.
    – Zarko
    Commented Jan 31, 2022 at 17:46

You must log in to answer this question.

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