1

This question already has an answer here:

I am currently writing a matrix equation with matrices that have the same number of rows, the lines of each have different heights. The result are very differently heightened matrices The only solution I found by googling was stretching all the matrices which looks highly awkward, as it stretches the first (big) matrix as well and makes it even bigger. Are there any suggestions?

My problem:

\documentclass[10pt]{article}
\usepackage{amsmath}
\newcommand{\partdiff}[2]{\ensuremath{\dfrac{\partial \! #1}{\partial \! #2}}}
\begin{document}
 Problem itself:\\
 \begin{equation}
  \begin{pmatrix}
    \partdiff{B_0}{y_0^0} & & \cdots  \\
     & \ddots & \\
    \cdots & & \partdiff{C_3}{y_2^{N-1}}
  \end{pmatrix}
  \cdot
  \begin{pmatrix}
    \delta y_0^0 \\
    \vdots \\
    \delta y_2^{N-1}
  \end{pmatrix}
   = - 
  \begin{pmatrix}
    B_0\\
    \vdots \\
    C_3
   \end{pmatrix}
\end{equation}

With sufficent strectching:\\
\begin{equation}
\renewcommand{\arraystretch}{2.7}
  \begin{pmatrix}
    \partdiff{B_0}{y_0^0} & & \cdots  \\
     & \ddots & \\
    \cdots & & \partdiff{C_3}{y_2^{N-1}}
  \end{pmatrix}
  \cdot
  \begin{pmatrix}
    \delta y_0^0 \\
    \vdots \\
    \delta y_2^{N-1}
  \end{pmatrix}
  = - 
  \begin{pmatrix}
    B_0\\
    \vdots \\
    C_3
  \end{pmatrix}
\end{equation}
\end{document}

Also, probably stupid aside: There has to be an easier way to paste code blocks than typing four spaces in front of each line manually.

marked as duplicate by Steven B. Segletes, Stefan Pinnow, Mensch, TeXnician, Troy Sep 27 '17 at 11:48

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Welcome to TeX.SX! Paste in the code, select it and click on the {} icon above the editing box (or hit Control-K). – egreg Sep 27 '17 at 9:04
  • For the ‘stupid’ question: select you code, and click on the pair-of-braces icon in the toolbar of the editing window – Bernard Sep 27 '17 at 9:04
2

I'm not sure the result is really better:

\documentclass[10pt]{article}
\usepackage{amsmath}

\newcommand{\partdiff}[2]{%
  \dfrac{\partial #1}{\partial #2}%
}

\begin{document}

\begin{equation}
  \begin{pmatrix}
  \partdiff{B_0}{y_0^0} & & \cdots  \\
   & \ddots & \\
  \cdots & & \partdiff{C_3}{y_2^{N-1}}
  \end{pmatrix}
  \cdot
  \begin{pmatrix}
    \delta y_0^0 \vphantom{\partdiff{B_0}{y_0^0}} \\
    \vdots \\
    \delta y_2^{N-1} \vphantom{\partdiff{C_3}{y_2^{N-1}}}
  \end{pmatrix}
   = - 
  \begin{pmatrix}
    B_0 \vphantom{\partdiff{B_0}{y_0^0}} \\
    \vdots \\
    C_3 \vphantom{\partdiff{C_3}{y_2^{N-1}}}
   \end{pmatrix}
\end{equation}

\end{document}

I removed \ensuremath that does nothing good and \! because it does evil.

enter image description here

  • Thanks this looks good. Alternativley, I found that you can stretch individual matrices and not just the whole equation, so you can use that for a dirty variant to. – DonLouigi Sep 27 '17 at 9:51
  • @DonLouigi You need to guess the right amount, though. I'd simply typeset them at their natural height. – egreg Sep 27 '17 at 10:26
  • Aye, yours looks better, is probably more exact and also more intuitive. And I learned more about this useful vphantom-command to boot. Thanks again! – DonLouigi Sep 27 '17 at 12:03
2

How about this?

\documentclass[10pt]{article}
\usepackage{amsmath}
\usepackage{esdiff}

\begin{document}

 \begin{equation}
  \begin{pmatrix}
    \diffp{B_0}{{y_0^0}}\!&\hdotsfor{2} \\
    &\! \ddots & \\
    \hdotsfor{2}& \diffp{C_3}{{{y_2^{N-1}}}}
  \end{pmatrix}
  \cdot
  \begin{pmatrix}
    \delta y_0^0 \\
    \vdots \\[-1.5ex] \vdots \\[-1.5ex] \vdots \\
    \delta y_2^{N-1}
  \end{pmatrix}
   = -
  \begin{pmatrix}
    B_0\\
    \vdots \\[-1.5ex] \vdots \\[-1.5ex] \vdots \\
    C_3
   \end{pmatrix}
\end{equation}

\end{document} 

enter image description here

Not the answer you're looking for? Browse other questions tagged or ask your own question.