2

Normally, a simple cases will get the result below.

\documentclass{article}
\usepackage{amsmath}

\begin{document}
\begin{equation}
    X=\begin{cases}
      0, & \text{if $a=1$} \\
      1, & \text{otherwise}
    \end{cases}
\end{equation}

\end{document}

enter image description here

However, in my thesis template, it generates

enter image description here

\documentclass{article}
\usepackage{tabu}
\usepackage{longtable}
\usepackage{amsmath}
\usepackage{setspace}
\setstretch{1.435}

\begin{document}

\setlength{\extrarowheight}{8pt}
\begin{longtabu}{ll}
    \caption{This is a caption} \\
    Longtable & Longtable \\
    Longtable & Longtable \\
    Longtable & Longtable \\
\end{longtabu}

\begin{equation}
    X=\begin{cases}
      0, & \text{if $a=1$} \\
      1, & \text{otherwise}
    \end{cases}
\end{equation}

\end{document}

I changed the default line spacing by

\usepackage{setspace}
\setstretch{1.435}

and increased the row spacing by

\setlength{\extrarowheight}{8pt}

My question is how to center the two cases.

WZhao
  • 263
  • As campa says, as long as you do not provide code that we can test that is suppose to give the image you present, we cannot help. – daleif Aug 22 '19 at 07:40
  • Hello, @daleif @campa I know why this happens. It is because the line \setlength{\extrarowheight}{8pt} which was used to increase the vertical spacing for a table, but it also affects the equations as well. – WZhao Aug 22 '19 at 07:46
  • 1
    Again, provide something the rest of us can test. We cannot test any of the sniplets you are posting. Also, if you want you use \extrarowheight in a table, then don't change that value globally, place it in side the table float you have around your tabular, then the change it local to that float. – daleif Aug 22 '19 at 07:53
  • @daleif The MWE is added. Thanks a lot for you advice. – WZhao Aug 22 '19 at 08:41
  • 2
    If you just need the \extrarowheight for that one table, you can reset it to 0pt afterwards, or else, place the tabu in its own scope-limited group to limit the reach of the \extrarowheight (assuming that labels are not an issue). – Steven B. Segletes Aug 22 '19 at 09:08

1 Answers1

1

The use of \setstretch has adverse effects also on array, which cases is based on.

I suggest to patch array by setting \arraystretch to the inverse of the stretch factor.

\documentclass{article}
\usepackage{tabu}
\usepackage{longtable}
\usepackage{amsmath}
\usepackage{setspace}
\usepackage{etoolbox}

\setstretch{1.435}
\pretocmd{\array}{\renewcommand{\arraystretch}{0.69686}}{}{} % 1/1.435=0.69686

\begin{document}

\begingroup
\setlength{\extrarowheight}{8pt}
\begin{longtabu}{ll}
    \caption{This is a caption} \\
    Longtable & Longtable \\
    Longtable & Longtable \\
    Longtable & Longtable \\
\end{longtabu}
\endgroup

\begin{equation}
    X=\begin{cases}
      0, & \text{if $a=1$} \\
      1, & \text{otherwise}
    \end{cases}
\end{equation}

\end{document}

I believe that \extrarowheight should always be set locally and not inflicted to all tables.

enter image description here

egreg
  • 1,121,712
  • Does \arraystretch also affect the row spacing in tables? – WZhao Aug 22 '19 at 15:59
  • @WZhao Yes, of course. – egreg Aug 22 '19 at 16:02
  • 1
    I tested your approach, but I cannot see obvious changes of row spacing in tables with different value of \arraystretch comparing to spacing in cases. I would prefer increasing a little the row spacing rather than the signal spacing in tables. – WZhao Aug 22 '19 at 16:10