5

I am using \renewcommand{\arraystretch}{2.5} in my arrays to produce nice tables. But this is affecting also matrix environments. Supposedly one can redefine the \arraystretch locally inside each environment, but this does not work when I try to make my matrices look nice again. Please help.

Here's a MWE (which also illustrates the issue):

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz-cd}
\renewcommand{\arraystretch}{2.5}
\usepackage{amssymb, amsmath}
\begin{document}

 \[\begin{array}{|c|c|}
  \hline \omega^s_{~s}= 0 & \omega^s_{~\theta}= -\dfrac{f'}{f}\,\theta^\theta \\[.5em] \hline  \omega^\theta_{~s}=\dfrac{f'}{f}\,\theta^\theta & \omega^\theta_{~\theta}=0 \\[.5em] \hline
\end{array}\]

 \[  \begin{vmatrix} \renewcommand*{\arraystretch}{.5}
g(u_1,v_1) & g(u_1,v_2) \\ g(u_2,v_1) & g(u_2,v_2)    
  \end{vmatrix}\]

\end{document}

2 Answers 2

5

You can use \bgroup and \egroup for that.

\documentclass{article}
\usepackage[utf8]{inputenc}
\renewcommand{\arraystretch}{2.5}
\usepackage{amssymb, amsmath}
\begin{document}
% your araystretch
 \[\begin{array}{|c|c|}
  \hline \omega^s_{~s}= 0 & \omega^s_{~\theta}= -\dfrac{f'}{f}\,\theta^\theta \\[.5em] \hline  \omega^\theta_{~s}=\dfrac{f'}{f}\,\theta^\theta & \omega^\theta_{~\theta}=0 \\[.5em] \hline
\end{array}\]
% araystretch locally redefined
 \[  \bgroup\renewcommand*{\arraystretch}{.5}\begin{vmatrix} 
g(u_1,v_1) & g(u_1,v_2) \\ g(u_2,v_1) & g(u_2,v_2)    
  \end{vmatrix}\egroup\]
% your araystretch again
 \[\begin{array}{|c|c|}
  \hline \omega^s_{~s}= 0 & \omega^s_{~\theta}= -\dfrac{f'}{f}\,\theta^\theta \\[.5em] \hline  \omega^\theta_{~s}=\dfrac{f'}{f}\,\theta^\theta & \omega^\theta_{~\theta}=0 \\[.5em] \hline
\end{array}\]
\end{document}

enter image description here

5
  • Fast answer, works nice, and I learned something new (I had never heard of \bgroup and \egroup, thanks!
    – Ivo Terek
    Apr 11, 2019 at 4:30
  • 1
    \bgroup and \egroup aren't really needed. Putting \renewcommand*{\arraystretch}{.5} before \begin{vmatrix} works as expected.
    – corporal
    Apr 11, 2019 at 4:32
  • This is curious. I figured the actual "array" wouldn't begin until the \begin{vmatrix}.
    – Ivo Terek
    Apr 11, 2019 at 4:34
  • 1
    @corporal Not if the second array is in the same equation.
    – user121799
    Apr 11, 2019 at 4:35
  • 2
    @IvoTerek \bgroup...\egroup is the same as {...} in most places, so there's nothing really new.Not in this case, but using {...} for making some setting local in math mode could introduce bad spacing; better using \begingroup...\endgroup.
    – egreg
    Apr 11, 2019 at 6:37
2

Here's how to do it without plaguing the typescript with \renewcommand{\arraystretch}{...}. Every Xmatrix environment in amsmath is defined in terms of \env@matrix; since environments form groups, the setting of \arraystretch will be local.

\documentclass{article}
\usepackage{amssymb, amsmath, etoolbox}

\renewcommand{\arraystretch}{2.5}

\makeatletter
\preto\env@matrix{\renewcommand{\arraystretch}{1}}
\makeatother

\begin{document}

\begin{gather*}
\begin{array}{|c|c|}
\hline
\omega^s_{~s}= 0 & \omega^s_{~\theta}= -\dfrac{f'}{f}\,\theta^\theta \\[.5em]
\hline
\omega^\theta_{~s}=\dfrac{f'}{f}\,\theta^\theta & \omega^\theta_{~\theta}=0 \\[.5em]
\hline
\end{array}
\\
\begin{vmatrix}
g(u_1,v_1) & g(u_1,v_2) \\ 
g(u_2,v_1) & g(u_2,v_2)
\end{vmatrix}
\end{gather*}

\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 .