2

When the matrix is complex and the vector is simple, the output does not look good:

Code:

\begin{bmatrix}
\displaystyle\sum_{i=1}^M{(x_i)^2} & \displaystyle\sum_{i=1}^M{(x_i)} \\
\displaystyle\sum_{i=1}^M{(x_i)} & M
\end{bmatrix}
\begin{bmatrix}
m \\ c
\end{bmatrix} = \begin{bmatrix}
\displaystyle\sum_{i=1}^M{(x_i y_i)} \\
\displaystyle\sum_{i=1}^M{(y_i)}
\end{bmatrix}

Output:

Output

In the desired output, the brackets of the vector should have the same size as that of the matrix, and the elements of the vector should align with the row of the matrix, which looks like this:

Desired output (this was produced by editing the above image):

enter image description here

What should I do to get the desired output without complex layout commands? A solution that could work inside the TeX mode ($$) on StackEdit is preferred.

Thanks!

  • Welcome to TeX.SE. – Mico Sep 15 '19 at 9:51
2

I think the central problem with your equation is not that the column vector looks puny next to the matrices, but that you're using \displaystyle (and, implicitly) \limits inside the matrices. Speacking for myself, creating super-tall column vectors -- as you do in your screenshot and as is done in the first solution shown below -- does not good at all. In fact, it's just preposterous.

Switching from implicit \limits to explicit \nolimits of summation -- see the second solution below -- creates a modest visual improvement. However, in my opionion, the column vector still looks much too tall.

What you should really be thinking about is (a) not using \displaystyle at all, (b) simplifying the terms in the limits of summation (to show just the index of summation), and (c) reducing the visual clutter by omitting the unnecessary parentheses around the terms x_i^2, x_i, y_i, and x_iy_i; the outcome of this approach is shown in third solution below. Observe that the height of the column vector is automatically equal to the height of the matrices -- no additional fiddling required!

Incidentally, if your readers aren't already fully aware of the fact that the summation runs from i=1 to i=M, you simply must inform them about this before they start seeing lots and lot of summation expressions.

enter image description here

\documentclass{article}
\usepackage{amsmath}  % for 'bmatrix' and 'gather*' environments
\usepackage{booktabs} % for '\addlinespace' macro
%% Define two typographic struts:
\newcommand\tallstrut{\vphantom{\displaystyle\sum\nolimits_{i=1}^M}}
\newcommand\reallytallstrut{\vphantom{\displaystyle\sum_{i=1}^M}}

\begin{document}

\begin{gather*}
%% First solution: use \displaystyle and \limits (as in the OP's query)
\begin{bmatrix}
\displaystyle\sum_{i=1}^M{(x_i)^2} & \displaystyle\sum_{i=1}^M{(x_i)} \\ \addlinespace
\displaystyle\sum_{i=1}^M{(x_i)} & M
\end{bmatrix}
\begin{bmatrix}
m\reallytallstrut \\ \addlinespace c\reallytallstrut
\end{bmatrix} 
= 
\begin{bmatrix}
\displaystyle\sum_{i=1}^M{(x_i y_i)} \\ \addlinespace
\displaystyle\sum_{i=1}^M{(y_i)}
\end{bmatrix}\\[2ex]
%% Second solution: use \displaystyle and \nolimits
\begin{bmatrix}
\displaystyle\sum\nolimits_{i=1}^M{(x_i)^2} & \displaystyle\sum\nolimits_{i=1}^M{(x_i)} \\ \addlinespace
\displaystyle\sum\nolimits_{i=1}^M{(x_i)} & M
\end{bmatrix}
\begin{bmatrix}
m\tallstrut \\ \addlinespace c\tallstrut
\end{bmatrix} 
= 
\begin{bmatrix}
\displaystyle\sum\nolimits_{i=1}^M{(x_i y_i)} \\ \addlinespace
\displaystyle\sum\nolimits_{i=1}^M{(y_i)}
\end{bmatrix}\\[2ex]
%% Third solution: use \textstyle (and \nolimits)
\begin{bmatrix}
\sum_i x_i^2 & \sum_i x_i \\ \addlinespace
\sum_i x_i & M
\end{bmatrix}
\begin{bmatrix}
m \\ \addlinespace c
\end{bmatrix} 
= 
\begin{bmatrix}
\sum_i x_i y_i \\ \addlinespace
\sum_i y_i
\end{bmatrix}
\end{gather*}

\end{document}
| improve this answer | |
  • 1
    I tried the first solution and that is what I preferred. It works very well in StackEdit! In my version, I did not use \addlinespace (it does not seem to work in StackEdit), and I did not use \newcommand (I put the expanded version in \vphantom). Now I know how to use \vphantom too! Thank you so much! – Siu Ching Pong -Asuka Kenji- Sep 15 '19 at 10:15
  • @SiuChingPong-AsukaKenji- - Glad you liked learning about \vphantom. :-) – Mico Sep 15 '19 at 10:50

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.