4

I already have something that looks good to me, but the latex implementation is hideous. Any ideas for how this could be done in a cleaner way?

\[
    \frac{dz}{dt} = 
    \raisebox{1.02em} {$
        \boldsymbol{[}\begin{array}{cc}
            1 & -1 \\
        \end{array}\boldsymbol{]}$
    }
    \left[\begin{array}{cc}
        \frac{\partial \underline{y}}{\partial \underline{x}} & \frac{\partial \overline{y}}{\partial \underline{x}} \\ [0.5em]
        \frac{\partial \underline{y}}{\partial \overline{x}}  & \frac{\partial \overline{y}}{\partial \overline{x}} \\
    \end{array}\right]
    \left[\begin{array}{c}
        1  \\[0.5em]
        -1 \\
    \end{array}\right].
\]

render

  • Is the example what you think looks good, or what you think looks hideous? I would personally prefer the first vector to be aligned centrally, but I get why one might prefer pushing it up. And the \partial symbols are not aligned horizontally which I don't love, I guess they're being pushed up by the \underline{}? – Charles Angus Apr 29 at 22:44
  • 1
    Welcome to TeX.SE. – Mico Apr 29 at 22:44
  • I think that the code looks hideous. I'm happy with way the rendered image looks. I wanted to align the tops of all the braces and have equally sized braces because that's how I think most people would write it. This misalignment of the \partials is a nightmare. I didn't notice. Any fixes for that? – Jesse Apr 29 at 23:45
  • I think the bigger brackets may be an improvement as well. – Jesse Apr 29 at 23:57
  • 1
    Don't worry about the “d”. Contrary to what @Schrödinger'scat thinks, mathematicians are happy to use an italic “d” for the differential and have mathematical reasons to justify the choice. – egreg Apr 30 at 8:19
3

Getting alignments with so inhomogeneous objects requires a bit of manual adjusting.

I raised the first row vector “by eye”; it would be possible to compute the amount of raising exactly, but I did it just to show that it's really awful and unhelpful for the reader. Why the top and not the bottom? There's no reason for choosing either, so the right place is at the center.

More importantly, I added some shorthands that help both in typing and in reading code.

Some “phantoms” make the objects align nicely.

\documentclass{article}
\usepackage{amsmath,bm}

\newenvironment{rowvector}
 {\bm{[}\begin{matrix}}
 {\end{matrix}\bm{]}}

\newcommand{\pder}[2]{\frac{\partial #1}{\partial #2}}
\newcommand{\ol}{\overline}
\newcommand{\ul}{\underline}

\begin{document}

\[
\frac{dz}{dt} =
\raisebox{3ex}{$\begin{rowvector} 1 & -1 \end{rowvector}$}
\begin{bmatrix}
  \pder{\ul{y}}{\ul{x}} & \pder{\ol{y}\vphantom{\ul{y}}}{\ul{x}} \\[0.5em]
  \pder{\ul{y}}{\ol{x}} & \pder{\ol{y}\vphantom{\ul{y}}}{\ol{x}}
\end{bmatrix}
\begin{bmatrix}
  1 \vphantom{\pder{\ul{y}}{\ul{x}}} \\[0.5em]
 -1 \vphantom{\pder{\ul{y}}{\ul{x}}}
\end{bmatrix}
\]

\[
\frac{dz}{dt} =
\begin{rowvector} 1 & -1 \end{rowvector}
\begin{bmatrix}
  \pder{\ul{y}}{\ul{x}} & \pder{\ol{y}\vphantom{\ul{y}}}{\ul{x}} \\[0.5em]
  \pder{\ul{y}}{\ol{x}} & \pder{\ol{y}\vphantom{\ul{y}}}{\ol{x}}
\end{bmatrix}
\begin{bmatrix}
  1 \vphantom{\pder{\ul{y}}{\ul{x}}} \\[0.5em]
 -1 \vphantom{\pder{\ul{y}}{\ul{x}}}
\end{bmatrix}
\]

\end{document}

enter image description here

| improve this answer | |
  • Although a number of the answers gave excellent solutions, I accepted this because it was the best for my question. The code is clean and the result is in the same style as my solution, but with multiple improvements (e.g. the bracket alignment and spacing looks better imho). I have no idea what did it, but even the partials look aligned. – Jesse Apr 30 at 15:22
  • 1
    @Jesse Look in the code for \vphantom that inserts an invisible object with the same vertical size of what's specified in the argument. – egreg Apr 30 at 15:30
  • Very clever. \pder{\ul{y}}{\ul{x}} & \pder{\ol{y}\vphantom{\ul{y}}}{\ul{x}} \\[0.5em] – Jesse Apr 30 at 15:33
5

I would use bmatrix environments instead of generic array environments, and I would not raise the row vector above the baseline.

Using \overline and \underline may be an acquired taste. To my taste, though, the lines produced by these macros look really heavy, even domineering. Using \bar{...} and \underaccent{\bar}{...} (\underaccent is courtesy of the accents package) provides a lighter-looking solution; see the second row belo2. In that solution, I insert a couple of (typographic) struts (called \bstrut in the code) to fine-tune the positions of the numerator terms \partial{\bar{y}}.

enter image description here

\documentclass{article}
\usepackage{mathtools,accents}
% Create a typographic (bottom) strut:
\newcommand\bstrut{\vphantom{\underaccent{\bar}{y}}} 

\begin{document}
\begin{align*}
\frac{dz}{dt} 
&= \begin{bmatrix} 
       1 & -1 
   \end{bmatrix}
   \begin{bmatrix}
       \frac{\partial\underline{y}}{\partial\underline{x}} & 
       \frac{\partial\overline{y}}{\partial\underline{x}}\\[1ex]
       \frac{\partial\underline{y}}{\partial\overline{x}}  & 
       \frac{\partial\overline{y}}{\partial\overline{x}}
   \end{bmatrix}
   \begin{bmatrix*}[r]
       1 \\ -1 
   \end{bmatrix*} \\
&= \begin{bmatrix} 
       1 & -1 
   \end{bmatrix}
   \begin{bmatrix}
       \frac{\partial\underaccent{\bar}{y}}{\partial\underaccent{\bar}{x}} & 
       \frac{\partial\bar{y}\bstrut}{\partial\underaccent{\bar}{x}}\\[1.25ex]
       \frac{\partial\underaccent{\bar}{y}}{\partial\bar{x}}  & 
       \frac{\partial\bar{y}\bstrut}{\partial\bar{x}}
   \end{bmatrix}
   \begin{bmatrix*}[r]
       1 \\ -1 
   \end{bmatrix*}
\end{align*}
\end{document}
| improve this answer | |
  • 1
    This was my initial solution except for a few very nice touches that you added like the little space before the period. I diverged from that initial approach because I wanted it to look like how I would have written it. Is this the standard solution (was my final rendered result unusual)? I see from your profile that you're quite a TeX guru. – Jesse Apr 29 at 23:50
  • 1
    @Jesse yes, it is the standard solution, and I would suggest you also use this style when writing by hand. – leftaroundabout Apr 30 at 8:13
  • @Jesse - I may be reasonably good at TeX and LaTeX in general, but I would not claim to be a guru on the subject of linear algebra notation. That said, I've never seen in any of my math textbooks row or column vectors that weren't centered on the math line. (The math line is an invisible line; it can be visualized as running through the middle of = symbols.) – Mico Apr 30 at 9:03
  • 1
    @Mico Strang's textbook is an example, in the excerpt, his typographer shifts vectors and matrices up to align them (math.mit.edu/~gs/learningfromdata/dsla1-1.pdf). I think I gained my preferences from his textbooks. This solution is excellent though. – Jesse Apr 30 at 15:14
3

I propose to use a single blockarray, the \medmath command from nccmath to have medium-size fraction inside arrays, and the diffcoeff package, for a simple syntax for partial derivatives. I also replaced \overline with \widebar, which is a real math accent from `mathabx (without loading the package).

\documentclass{article}
\usepackage{mathtools}
\usepackage{blkarray, bigstrut}
\usepackage{diffcoeff}
\usepackage{nccmath}
\newcommand{\mdiffp}[2]{\medmath{\diffp{#1}{#2}}}

\usepackage[math]{cellspace}
\setlength{\cellspacetoplimit}{2pt}
\setlength{\cellspacebottomlimit}{3pt}

\DeclareFontFamily{U}{mathx}{\hyphenchar\font45}
\DeclareFontShape{U}{mathx}{m}{n}{
<-6> mathx5 <6-7> mathx6 <7-8> mathx7
<8-9> mathx8 <9-10> mathx9
<10-12> mathx10 <12-> mathx12
}{}
\DeclareSymbolFont{mathx}{U}{mathx}{m}{n}
\DeclareFontSubstitution{U}{mathx}{m}{n}
\DeclareMathAccent{\widebar}{0}{mathx}{"73}

\begin{document}

\[ \setlength{\bigstrutjot}{0.75em}\diff{z}{r} = \begin{blockarray}

{@{}cc@{\hskip 0.65em}[cc][r]}
   \boldsymbol{[}\, 1 & -1\, \boldsymbol{]} &\bigstrut\mdiffp{\underline{y}}{ \underline{x}} &\mdiffp{\widebar{y}}{ \underline{x}} & 1\\%[2ex]
   & & \bigstrut\mdiffp{\underline{y}}{\widebar{x}} & \mdiffp{\widebar y}{ \widebar x } & -1 
\end{blockarray}\]%

\end{document} 

enter image description here

| improve this answer | |
1

I tried a number of things, but finally settled on this. I \smashed the matrix elements and increased \arraystretch until the spacing look good. Then I put the row vector into \raisebox and adjusted the alignment again by hand.

\documentclass{article}
\usepackage{mathtools}
\begin{document}
\def\arraystretch{1.6}% increase until matrix looks good
\[
    \frac{dz}{dt} = 
    \raisebox{2.2ex}% adjust until ones are lined up
    {$\displaystyle \begin{bmatrix} 
       1 & -1
    \end{bmatrix}$}
    \begin{bmatrix}
       \smash{\frac{\partial\underline{y}}{\partial\underline{x}}} & 
       \smash{\frac{\partial\overline{y}}{\partial\underline{x}}}\\
       \smash{\frac{\partial\underline{y}}{\partial\overline{x}}}  & 
       \smash{\frac{\partial\overline{y}}{\partial\overline{x}}}
    \end{bmatrix}
    \begin{bmatrix*}[r]
       1 \\% \llap{\rule{1.5in}{0.5pt}}\\% to chaeck alignment
      -1
    \end{bmatrix*}\,.
\]
\end{document}

demo

| improve this answer | |
0

This is perhaps a little goofy, but I think it's in a way cleaner. Slightly different result.

I use \vphantom to create space to line things up programmatically without using explicit numbers, and define a command which holds the taller of your partial fractions so you only need to change the spacing in one place.

I use \bigl[ instead of \boldsymbol{[} (the \boldsymbol does not actually appear to do anything).

I line up the row vector with the center of the upper row of the other elements, rather than push it right to the top.

\newcommand{\partialfractall}{\frac{\partial \underline{y}}{\partial \underline{x}}}


\[
    \frac{dz}{dt} = 
    \begin{array}{cc}
    \bigl[\begin{array}{cc}
            1 & -1
        \end{array}\bigr] \\
        \vphantom{\partialfractall{}}
    \end{array}
    \left[\begin{array}{cc}
        \frac{\partial \underline{y}}{\partial \underline{x}} & \frac{\partial \overline{y}}{\partial \underline{x}} \\ [0.5em]
        \frac{\partial \underline{y}}{\partial \overline{x}}  & \frac{\partial \overline{y}}{\partial \overline{x}} \\
    \end{array}\right]
    \left[%
    \vphantom{\begin{array}{cc}
        \frac{\partial \underline{y}}{\partial \underline{x}} & \frac{\partial \overline{y}}{\partial \underline{x}} \\ [0.5em]
        \frac{\partial \underline{y}}{\partial \overline{x}}  & \frac{\partial \overline{y}}{\partial \overline{x}} \\
    \end{array}}%
    \begin{array}{c}
        \vphantom{\partialfractall{}} 1  \\
        \vphantom{\partialfractall{}} -1 \\
    \end{array}\right].
\]

new result

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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