6

I want to format a cases environment inside a table such that the braces have some offset from the horizontal lines. By default this distance is zero, and if the rowheight is adjusted using \extrarowheight the braces simply scale proportionally. I was not able to achieve better results using \array.

Does anybody have an idea how to typeset this correctly?

enter image description here

\documentclass[12pt]{article}

\usepackage[a4paper, top = 0.1cm, left = 0.1cm, right = 0.1cm, bottom = 0.1cm, bindingoffset=0cm]{geometry} \usepackage[utf8]{inputenc} \usepackage{mathtools} \usepackage{multirow}

\newcommand{\ROC}{\text{ROC}}

\begin{document}

\begin{tabular}{@{}c|c|c@{}} $F(z)$ & $\ROC(f)$ & $f[.]$\\hline \multirow{2}{}{$\dfrac{z}{z-p}$} & $|z| > |p|$ & $f[k] = \begin{cases}\hphantom{-}0, \quad &k<0\\hphantom{-}p^k, \quad &k\ge 0\end{cases}$\\cline{2-3} & $0 < |z| < |p|$ & $f[k] = \begin{cases}-p^k, \quad &k<0\\hphantom{-}0, \quad &k\ge 0\end{cases}$\\hline \multirow{2}{}{\shortstack{$\dfrac{Az}{z-p} + \dfrac{\overline{A}z}{z-p}$\$=2z\dfrac{z\text{Re}(A)-\text{Re}(A\overline{p})}{z^2 - 2z\text{Re}(p)+|p|^2}$}} & $|z| > |p|$ & $f[k] = \begin{cases}\hphantom{-}0, & k<0\\hphantom{-}2|A||p|^k\cos(\Omega k+\varphi), &k\ge 0 \end{cases}$\\cline{2-3} & $0<|z|<|p|$ & $f[k] = \begin{cases}-2|A||p|^k\cos(\Omega k+\varphi), & k<0\\hphantom{-} 0, &k\ge 0 \end{cases}$ \end{tabular}

\end{document}

Skydiver
  • 977
  • Off-topic: You may replace top = 0.1cm, left = 0.1cm, right = 0.1cm, bottom = 0.1cm with margin=1mm. – Mico Nov 25 '20 at 06:27

4 Answers4

10

With use of makegapedcells defined in the makecell package:

enter image description here

\documentclass[12pt]{article}
\usepackage[a4paper, margin= .1cm, 
            bindingoffset=0cm]{geometry}
\usepackage{mathtools}
\usepackage{makecell, multirow}

\newcommand{\ROC}{\text{ROC}}

\begin{document} [ \setcellgapes{3pt} \makegapedcells \begin{array}{@{}c|c|c@{}} F(z) & \ROC(f) & f[.] \
\hline \multirow{4.4}{}{$\dfrac{z}{z-p}$} & |z| > |p| & f[k] = \begin{cases} \hphantom{-}0, \quad & k<0 \ \hphantom{-}p^k, \quad & k\ge 0 \end{cases} \ \cline{2-3} & 0 < |z| < |p| & f[k] = \begin{cases} -p^k, \quad & k<0 \
\hphantom{-}0, \quad & k\ge 0 \end{cases} \ \hline \multirow{4.4}{
}{$\begin{aligned} & \dfrac{Az}{z-p} + \dfrac{\overline{A}z}{z-p} \ & = 2z\dfrac{z\text{Re}(A)-\text{Re}(A\overline{p})} {z^2 - 2z\text{Re}(p)+|p|^2} \end{aligned}$} & |z| > |p| & f[k] = \begin{cases} \hphantom{-}0, & k<0 \ \hphantom{-}2|A||p|^k\cos(\Omega k+\varphi), & k\ge 0 \end{cases} \ \cline{2-3} & 0<|z|<|p| & f[k] = \begin{cases} -2|A||p|^k\cos(\Omega k+\varphi), & k<0\ \hphantom{-} 0, &k\ge 0
\end{cases} \end{array} ] \end{document}

Note: with use of the array inside of math environment instead of the tabular, you can omit all $ in table except in \multirow cells.

Bernard
  • 271,350
Zarko
  • 296,517
7

One possibility is to use booktabs package and replace every \hline by \midrule and \cline{2-3} with \cmidrule{2-3} as follows:

\documentclass[12pt]{article}

\usepackage[a4paper, top = 0.1cm, left = 0.1cm, right = 0.1cm, bottom = 0.1cm, bindingoffset=0cm]{geometry} \usepackage[utf8]{inputenc} \usepackage{mathtools} \usepackage{multirow} \usepackage{booktabs}

\newcommand{\ROC}{\text{ROC}}

\begin{document}

\begin{tabular}{@{}c|c|c@{}} $F(z)$ & $\ROC(f)$ & $f[.]$\\midrule \multirow{2}{}{$\dfrac{z}{z-p}$} & $|z| > |p|$ & $f[k] = \begin{cases}\hphantom{-}0, \quad &k<0\\hphantom{-}p^k, \quad &k\ge 0\end{cases}$\\cmidrule{2-3} & $0 < |z| < |p|$ & $f[k] = \begin{cases}-p^k, \quad &k<0\\hphantom{-}0, \quad &k\ge 0\end{cases}$\\midrule \multirow{2}{}{\shortstack{$\dfrac{Az}{z-p} + \dfrac{\overline{A}z}{z-p}$\$=2z\dfrac{z\text{Re}(A)-\text{Re}(A\overline{p})}{z^2 - 2z\text{Re}(p)+|p|^2}$}} & $|z| > |p|$ & $f[k] = \begin{cases}\hphantom{-}0, & k<0\\hphantom{-}2|A||p|^k\cos(\Omega k+\varphi), &k\ge 0 \end{cases}$\\cmidrule{2-3} & $0<|z|<|p|$ & $f[k] = \begin{cases}-2|A||p|^k\cos(\Omega k+\varphi), & k<0\\hphantom{-} 0, &k\ge 0 \end{cases}$ \end{tabular}

This gives the following output: enter image description here

Luis Turcio
  • 2,757
  • Thanks for the suggestion, but this now yields the problem that the vertical lines are seperated into different segments, which is also undesired. – Skydiver Nov 25 '20 at 00:05
  • 3
    Well vertical lines are a topic, many times not recommended as you can see in https://tex.stackexchange.com/questions/503806/continuous-vertical-line-using-booktabs-in-tabularx-table, or https://tex.stackexchange.com/questions/88929/vertical-table-lines-are-discontinuous-with-booktabs?rq=1 or https://tex.stackexchange.com/questions/18092/vertical-lines-are-being-broken-up-disrupted-by-the-horizontal-booktabs-lines?rq=1. But for what you want Zarko has already given a beautiful solution – Luis Turcio Nov 25 '20 at 00:13
  • @Skydiver: If you actually want vertical rules compatible with the horizontal rules drawn by booktabs, you should use nicematrix. – F. Pantigny Nov 25 '20 at 10:16
6

I would get rid of all vertical and almost all horizontal rules, left-align the cell contents, use array instead of tabular, double the value of \arraycolsep, and use the \addlinespace macro to create whitespace-type ("negative space") between the rows. I'd also clean up and streamline the LaTeX code; e.g., replace \overline with \bar, use an aligned environment rather than a \shortstack directive, and set up \ROC and \Re as math operators. (Many thanks to @egreg for suggesting the latter changes.)

enter image description here

\documentclass[12pt]{article}

\usepackage[a4paper, margin=5mm, bindingoffset=0cm]{geometry} % \usepackage[utf8]{inputenc} % is the default \usepackage[T1]{fontenc} \usepackage{mathtools} % for '\DeclarePairedDelimiter' macro \DeclarePairedDelimiter\abs\lvert\rvert \usepackage{booktabs}

\DeclareMathOperator{\ROC}{ROC} \renewcommand\Re{\operatorname{Re}}

\begin{document}

[ \setlength\arraycolsep{10pt} % default: 5pt \begin{array}{@{} lll @{}} F(z) & \ROC(f) & f[k] \ \midrule %\hline \dfrac{z}{z-p} & \abs{z} > \abs{p} & \begin{cases} \hphantom{-}0 &\text{if $k<0$}\ \hphantom{-}p^k &\text{if $k\ge0$} \end{cases} \ \addlinespace %\cline{2-3} & 0 < \abs{z} < \abs{p} & \begin{cases} -p^k &\text{if $k<0$}\ \hphantom{-}0 &\text{if $k\ge0$} \end{cases} \ \addlinespace[2\defaultaddspace] % \hline \smash[b]{% \begin{aligned}[t] &\frac{Az}{z-p} + \frac{\bar{A}z}{z-p} \ &=2z\frac{z\Re(A)-\Re(A\bar{p})}{z^2 - 2z\Re(p)+\abs{p}^2} \end{aligned}} & \abs{z} > \abs{p} & \begin{cases} \hphantom{-}0 & \text{if $k<0$}\ \hphantom{-}2\abs{A}\abs{p}^k\cos(\Omega k+\varphi) &\text{if $k\ge0$}
\end{cases} \ \addlinespace % \cline{2-3} & 0<\abs{z}<\abs{p} & \begin{cases} -2\abs{A}\abs{p}^k\cos(\Omega k+\varphi) & \text{if $k<0$}\ \hphantom{-} 0 &\text{if $k\ge0$}
\end{cases} \end{array} ]

\end{document}

Mico
  • 506,678
  • 1
    I believe that it should be \DeclareMathOperator{\ROC}{ROC} and \renewcommand{\Re}{\operatorname[Re}}. I’d remove also \multirow and use \bar{A}, but these are details. – egreg Nov 25 '20 at 08:37
  • @egreg - Many thanks for your suggestions, which I've implemented. – Mico Nov 25 '20 at 10:09
3

Here is a version with {NiceArray} of nicematrix.

This package provides two keys cell-space-top-limit and cell-space-bottom-limit (similar to the commands \cellspacetoplimit and \cellspacebottomlimit of cellspace). There is also the key cell-space-limits to fix both parameters.

\documentclass[12pt]{article}

\usepackage[a4paper, top = 0.1cm, left = 0.1cm, right = 0.1cm, bottom = 0.1cm, bindingoffset=0cm]{geometry} \usepackage{mathtools} \usepackage{nicematrix}

\newcommand{\ROC}{\text{ROC}}

\begin{document}

$\begin{NiceArray}{@{}c|c|c@{}}[cell-space-limits=3pt] F(z) & \ROC(f) & f[.]\ \Hline \Block{2-1}{\dfrac{z}{z-p}} & |z| > |p| & f[k] = \begin{cases}\hphantom{-}0, \quad &k<0\\hphantom{-}p^k, \quad &k\ge 0\end{cases}\ \Hline & 0 < |z| < |p| & f[k] = \begin{cases}-p^k, \quad &k<0\\hphantom{-}0, \quad &k\ge 0\end{cases}\ \Hline \Block{2-1}{\dfrac{Az}{z-p} + \dfrac{\overline{A}z}{z-p}\[4mm] =2z\dfrac{z\text{Re}(A)-\text{Re}(A\overline{p})}{z^2 - 2z\text{Re}(p)+|p|^2}} & |z| > |p| & f[k] = \begin{cases}\hphantom{-}0, & k<0\\hphantom{-}2|A||p|^k\cos(\Omega k+\varphi), &k\ge 0 \end{cases}\ \Hline & 0<|z|<|p| & f[k] = \begin{cases}-2|A||p|^k\cos(\Omega k+\varphi), & k<0\\hphantom{-} 0, &k\ge 0 \end{cases} \end{NiceArray}$

\end{document}

In your case, there is two avantages in using nicematrix.

  • The command \Block will center the content in the mathematical center of the merged cells (there is no need for manual adjustment as with \multirow).

  • A command \Hline will draw the rule excepted in the blocks (created by \Block): it's more easy to use than \cline.

Output of the above code

You need several compilations (because nicematrix uses PGF/Tikz nodes).

F. Pantigny
  • 40,250