3

I am trying to make a table with line breaks, centered vertical alignment and a piecewise function definition:

\documentclass[15pt]{extarticle}
\usepackage{tabularx}
\usepackage{gensymb}
\usepackage{amsmath}
\usepackage{makecell}
\usepackage{geometry}
 \geometry{
 a4paper,
 left=20mm,
 right=20mm,
 top=20mm,
 bottom=30mm,
}

\renewcommand\tabularxcolumn[1]{m{#1}}

\begin{document}

\begin{table}[h]
\centering
\begin{tabularx}{\textwidth}{|l c X X|} 
 \hline
 \textbf{Symbol} & \textbf{Unit} & \textbf{Equation} & \textbf{Explanation} \\ [0.5ex] 
 \hline
 $P(x,y)$ & mm & $F_p(x,y) F_t(x,y) P_{AWS,corr} \cdot \frac{dP}{dz} \cdot \newline \cdot (1 + (min(z_{Pmax}, z(x,y)) - z_{AWS})) / 10000$ & Total precipitation over each grid cell \\
 \hline
 $f_s(x,y)$ & - & \[\begin{cases} 
      1 & T(x,y)\leq T_{r/s} - 1~\degree C \\
      (T_{r/s} + 1 - T(x,y)) / 2 & \lvert T(x,y) - T_{r/s}\rvert < 1~\degree C \\
      0 & T(x,y)\geq T_{r/s} + 1~\degree C
   \end{cases}\] & Fraction of solid precipitation over each grid cell, it is linearly interpolated within $\pm 1~\degree$C of $T_{r/s}$ \\
\hline
 $C(x,y)$ & mm & $P(x,y)\cdot f_s(x,y)$ & Accumulation over each grid cell\\
 \hline
\end{tabularx}
\end{table}

\end{document}

Unfortunately the result looks like this: Table from MWE code

I would like to:

  • adapt the column width to avoid overlap of the two last columns
  • have consistent top/bottom margins in the table rows
  • if possible, vertically align the piecewise function to the other cells of its row (it is a bit too low)

I have tried to combine \setcellgapes{12pt} and \makegapedcells but they apparently dislike the tabularx environment?

Thanks a lot for any suggestions!

1
  • 2
    Tray with \begin{tabularx}{\textwidth}{|l c >{\hsize=1.2\hsize}X >{\hsize=0.8\hsize} X|} Also may help to reduce tabcolsep, for example \setlength\tabcolsep{3pt}. More late afternoon :-)
    – Zarko
    Oct 12, 2021 at 13:42

2 Answers 2

3

Let me spell-out my comment, where instead of a tabularx table (already consumed in the @Mico answer) is used tabularray (version 2021P) table:

\documentclass[15pt]{extarticle}
\usepackage[a4paper, 
            hmargin=20mm, vmargin={20mm, 30mm}
            ]{geometry}

\usepackage{tabularray}
\UseTblrLibrary{siunitx}

\usepackage{mathtools} % for \DeclarePairedDelimiter macro
\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}

\begin{document}
    \begin{table}[ht]
\begin{tblr}{hlines, vline{1,Z},
             colspec = {Q[l,m,$] Q[l,m] X[1.2,l,m,$] X[0.8,j,m]},
             row{1} = {font=\bfseries,rowsep = 3pt},
             row{2-Z} = {rowsep = 5pt},
             column{2-Y} = {colsep = 9pt}
             }
\text{Symbol}
        & Unit  & \text{Equation}
                    & Explanation   \\
%
P(x,y)  & mm    & F_p(x,y)F_t(x,y)P_{\mathit{AWS},\mathrm{corr}}\cdot \frac{dP}{dz}\cdot \smallskip
                  \cdot \bigl\{1 + [\min(z_{P_{\max}},z(x,y)) - z_{\mathit{AWS}}]\bigr\}/10000
                    & Total precipitation over each grid cell   \\
f_s(x,y)& --    &   \begin{cases}
                    1   & \text{if }T(x,y)\leq T_{r/s} - \qty{1}{\celsius} \\
                    (T_{r/s} + 1 - T(x,y))/2
                    & \text{if }\abs{T(x,y) - T_{r/s}} < \qty{1}{\celsius} \\
                    0   & \text{if }T(x,y)\geq T_{r/s} + \qty{1}{\celsius}
                    \end{cases}
                    & Fraction of solid precipitation over each grid cell. It is linearly interpolated within \qty{+-1}{\celsius} of $T_{r/s}$. \\
C(x,y)  & mm    & P(x,y)\cdot f_s(x,y)
                    & Accumulation over each grid cell \\
\end{tblr}
    \end{table}
\end{document}

enter image description here

1
  • This also addresses the vertical alignment of the piecewise function, great!
    – user975296
    Oct 13, 2021 at 7:41
2

Something like this?

enter image description here

\documentclass[15pt]{extarticle}
\usepackage{tabularx}
\renewcommand\tabularxcolumn[1]{m{#1}}

\usepackage{mathtools} % for \DeclarePairedDelimiter macro
\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}

\usepackage{geometry}
\geometry{a4paper, hmargin=20mm, top=20mm, bottom=30mm}
 
\usepackage{booktabs} % for \toprule, \midrule, \bottomrule, and \addlinespace macros
\usepackage{siunitx}  % for \qty and \celsius macros
\usepackage{ragged2e} % for \RaggedRight macro
\begin{document}

\begin{table}[ht!]

\begin{tabularx}{\textwidth}{@{} l c 
     >{\hsize=1.2\hsize\RaggedRight$}X<{$} % automatic math mode
     >{\hsize=0.8\hsize\RaggedRight}X @{} } 
 \toprule
 \textbf{Symbol} & \textbf{Unit} & \textbf{Equation} & \textbf{Explanation} \\ 
 \midrule
 $P(x,y)$ 
 & mm 
 & F_p(x,y) F_t(x,y) P_{\mathit{AWS},\mathrm{corr}} \cdot \frac{dP}{dz}  
 \cdot \newline 
 \cdot \{1 + [\min(z_{P\!\max}, z(x,y)) - z_{\mathit{AWS}}]\} / 10000 
 & Total precipitation over each grid cell \\
 \addlinespace %\hline
 $f_s(x,y)$ 
 & -- 
 &   \begin{cases} 
      1 & \text{if }T(x,y)\leq T_{r/s} - \qty{1}{\celsius} \\
      (T_{r/s} + 1 - T(x,y)) / 2 
        & \text{if }\abs{T(x,y) - T_{r/s}} < \qty{1}{\celsius} \\
      0 & \text{if }T(x,y)\geq T_{r/s} + \qty{1}{\celsius}
    \end{cases}
   & Fraction of solid precipitation over each grid cell. It is 
     linearly interpolated within \qty{+-1}{\celsius} of $T_{r/s}$. \\
 \addlinespace %\hline
 $C(x,y)$ 
 & mm 
 & P(x,y)\cdot f_s(x,y) 
 & Accumulation over each grid cell \\
 \bottomrule
\end{tabularx}
\end{table}

\end{document}

You must log in to answer this question.

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