Hi all!
Is it possible to align rows of 2 matrices, please see attached fig for example. Rows are not aligned, but I want them to be, so that the equation is more intuitive.
Thanks!
Best,
Marko.
Math & Science ⇒ Big matrix equation and matrix rows vertical alignment
Big matrix equation and matrix rows vertical alignment
- Attachments
-
- meq.png (29.79 KiB) Viewed 8500 times
Big matrix equation and matrix rows vertical alignment
I did the hack with \vphantom, but that is not elegant solution. I hope there is a package that enables this.
- Attachments
-
- matrices.png (42.53 KiB) Viewed 8493 times
- Johannes_B
- Site Moderator
- Posts: 4182
- Joined: Thu Nov 01, 2012 4:08 pm
Re: Big matrix equation and matrix rows vertical alignment
Can you post the code that outputs the screenshot?
It is much easier to help having some code. Nobody wants to type in the numbers to make a test document.
It is much easier to help having some code. Nobody wants to type in the numbers to make a test document.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Big matrix equation and matrix rows vertical alignment
Here I post the code without \vphantom hack:
Code: Select all
\documentclass[conference]{article}
\usepackage[cmex10]{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\newcommand*{\mathminus}{%
\leavevmode
\hphantom{0}%
\llap{%
\settowidth{\dimen0 }{$0$}%
\resizebox{1.1\dimen0 }{\height}{$-$}%
}%
}
\begin{document}
$$
\begin{bmatrix}
\mathminus m_u^{(1)} & 0 \\
\mathminus M_{u,\varepsilon}^{(1)} & 0 \\
\mathminus M_u^{(1)} & 0 \\
m_u^{(1)} & 0 \\
\mathminus m_u^{(1)} & 0 \\
M_u^{(1)} & 0 \\
0 & \mathminus m_u^{(2)} \\
0 & \mathminus M_{u,\varepsilon}^{(2)} \\
0 & \mathminus M_u^{(2)} \\
0 & m_u^{(2)} \\
0 & \mathminus m_u^{(2)} \\
0 & M_u^{(2)} \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0
\end{bmatrix} \delta_k +
\begin{bmatrix}
0 & 0 \\
0 & 0 \\
1 & 0 \\
\mathminus 1 & 0 \\
1 & 0 \\
\mathminus 1 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 1 \\
0 & \mathminus 1 \\
0 & 1 \\
0 & \mathminus 1 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0
\end{bmatrix} z_k \leq
\begin{bmatrix}
1 & 0 \\
\mathminus 1 & 0 \\
0 & 0 \\
0 & 0 \\
1 & 0 \\
\mathminus 1 & 0 \\
0 & 1 \\
0 & \mathminus 1 \\
0 & 0 \\
0 & 0 \\
0 & 1 \\
0 & \mathminus 1 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
\mathminus 1 & \mathminus 1 \\
1 & 1
\end{bmatrix} u_k +
\begin{bmatrix}
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
1 & 0 \\
\mathminus 1 & 0 \\
0 & 1 \\
0 & \mathminus 1 \\
0 & 0 \\
0 & 0
\end{bmatrix} x_k +
\begin{bmatrix}
\mathminus m_u^{(1)} \\
\mathminus \varepsilon \\
0 \\
0 \\
\mathminus m_u^{(1)} \\
M_u^{(1)} \\
\mathminus m_u^{(2)} \\
\mathminus \varepsilon \\
0 \\
0 \\
\mathminus m_u^{(2)} \\
M_u^{(2)} \\
m_x^{(1)} \\
M_x^{(1)} \\
m_x^{(2)} \\
M_x^{(2)} \\
\mathminus m_{d,k} \\
M_{d,k}
\end{bmatrix}
$$
\end{document}
- Johannes_B
- Site Moderator
- Posts: 4182
- Joined: Thu Nov 01, 2012 4:08 pm
Big matrix equation and matrix rows vertical alignment
I renewed the arraystretch inside the math environment (be sure
not to use
entries looked to cramped.
not to use
$$ <math> $$
) because those massiveentries looked to cramped.
Code: Select all
\documentclass{article}
\usepackage[cmex10]{mathtools}
\usepackage{graphicx}
\newcommand*{\mathminus}{%
\leavevmode
\hphantom{0}%
\llap{%
\settowidth{\dimen0 }{$0$}%
\resizebox{1.1\dimen0 }{\height}{$-$}%
}%
}
\begin{document}
%$$
\[
\renewcommand{\arraystretch}{1.35}
\begin{bmatrix*}
\mathminus m_u^{(1)} & 0 \\
\mathminus M_{u,\varepsilon}^{(1)} & 0 \\
\mathminus M_u^{(1)} & 0 \\
m_u^{(1)} & 0 \\
\mathminus m_u^{(1)} & 0 \\
M_u^{(1)} & 0 \\
0 & \mathminus m_u^{(2)} \\
0 & \mathminus M_{u,\varepsilon}^{(2)} \\
0 & \mathminus M_u^{(2)} \\
0 & m_u^{(2)} \\
0 & \mathminus m_u^{(2)} \\
0 & M_u^{(2)} \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0
\end{bmatrix*} \delta_k +
\begin{bmatrix*}[r]
0 & 0 \\
0 & 0 \\
1 & 0 \\
\mathminus 1 & 0 \\
1 & 0 \\
\mathminus 1 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 1 \\
0 & \mathminus 1 \\
0 & 1 \\
0 & \mathminus 1 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0
\end{bmatrix*} z_k \leq
\begin{bmatrix*}[r]
1 & 0 \\
\mathminus 1 & 0 \\
0 & 0 \\
0 & 0 \\
1 & 0 \\
\mathminus 1 & 0 \\
0 & 1 \\
0 & \mathminus 1 \\
0 & 0 \\
0 & 0 \\
0 & 1 \\
0 & \mathminus 1 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
\mathminus 1 & \mathminus 1 \\
1 & 1
\end{bmatrix*} u_k +
\begin{bmatrix*}[r]
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
1 & 0 \\
\mathminus 1 & 0 \\
0 & 1 \\
0 & \mathminus 1 \\
0 & 0 \\
0 & 0
\end{bmatrix*} x_k +
\begin{bmatrix*}
\mathminus m_u^{(1)} \\
\mathminus \varepsilon \\
0 \\
0 \\
\mathminus m_u^{(1)} \\
M_u^{(1)} \\
\mathminus m_u^{(2)} \\
\mathminus \varepsilon \\
0 \\
0 \\
\mathminus m_u^{(2)} \\
M_u^{(2)} \\
m_x^{(1)} \\
M_x^{(1)} \\
m_x^{(2)} \\
M_x^{(2)} \\
\mathminus m_{d,k} \\
M_{d,k}
\end{bmatrix*}
%$$
\]
\end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Big matrix equation and matrix rows vertical alignment
Wow, thanks! This was very helpful.
Why \[ and \] are used, what do they do? And why bmatrix* environment, because of the alignment?
Another issuse: now that you've aligned contents to the right, the right bracket is too close to contents. I can add hphantom to all entries, but is there any way to do this automatically? (only for right bracket)
Best,
Marko.
Why \[ and \] are used, what do they do? And why bmatrix* environment, because of the alignment?
Another issuse: now that you've aligned contents to the right, the right bracket is too close to contents. I can add hphantom to all entries, but is there any way to do this automatically? (only for right bracket)
Best,
Marko.
- Johannes_B
- Site Moderator
- Posts: 4182
- Joined: Thu Nov 01, 2012 4:08 pm
Big matrix equation and matrix rows vertical alignment
Using
Check out the following, it looks as the content is too close, but actually it just appears like that, because youre other content is so spacy.
$$ math $$
is the old TeX way. LaTeX uses \[ math \]
to do the task. The starred variant for the different matrices is provided by package mathtools. If you have a lot of maths, you should check out the documentation. There are some useful things in there. Check out the following, it looks as the content is too close, but actually it just appears like that, because youre other content is so spacy.
Code: Select all
\documentclass{article}
\usepackage[cmex10]{mathtools}
\usepackage{graphicx}
\newcommand*{\mathminus}{%
\leavevmode
\hphantom{0}%
\llap{%
\settowidth{\dimen0 }{$0$}%
\resizebox{1.1\dimen0 }{\height}{$-$}%
}%
}
\begin{document}
%$$
\[
\renewcommand{\arraystretch}{1.35}
\begin{bmatrix*}
\mathminus m_u^{(1)} & 0 \\
\mathminus M_{u,\varepsilon}^{(1)} & 0 \\
\mathminus M_u^{(1)} & 0 \\
m_u^{(1)} & 0 \\
\mathminus m_u^{(1)} & 0 \\
M_u^{(1)} & 0 \\
0 & \mathminus m_u^{(2)} \\
0 & \mathminus M_{u,\varepsilon}^{(2)} \\
0 & \mathminus M_u^{(2)} \\
0 & m_u^{(2)} \\
0 & \mathminus m_u^{(2)} \\
0 & M_u^{(2)} \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0
\end{bmatrix*} \delta_k +
\begin{bmatrix*}[r]
0 & 0 \\
0 & 0 \\
1 & 0 \\
\mathminus 1 & 0 \\
1 & 0 \\
\mathminus 1 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 1 \\
0 & \mathminus 1 \\
0 & 1 \\
0 & \mathminus 1 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0
\end{bmatrix*} z_k \leq
\begin{bmatrix*}[r]
1 & 0 \\
\mathminus 1 & 0 \\
0 & 0 \\
0 & 0 \\
1 & 0 \\
\mathminus 1 & 0 \\
0 & 1 \\
0 & \mathminus 1 \\
0 & 0 \\
0 & 0 \\
0 & 1 \\
0 & \mathminus 1 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
\mathminus 1 & \mathminus 1 \\
1 & 1
\end{bmatrix*} u_k +
\begin{bmatrix*}[r]
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
0 & 0 \\
1 & 0 \\
\mathminus 1 & 0 \\
0 & 1 \\
0 & \mathminus 1 \\
0 & 0 \\
0 & 0
\end{bmatrix*} x_k +
\begin{bmatrix*}
\mathminus m_u^{(1)} \\
\mathminus \varepsilon \\
0 \\
0 \\
\mathminus m_u^{(1)} \\
M_u^{(1)} \\
\mathminus m_u^{(2)} \\
\mathminus \varepsilon \\
0 \\
0 \\
\mathminus m_u^{(2)} \\
M_u^{(2)} \\
m_x^{(1)} \\
M_x^{(1)} \\
m_x^{(2)} \\
M_x^{(2)} \\
\mathminus m_{d,k} \\
M_{d,k}
\end{bmatrix*}
+
\begin{bmatrix*}
0 \\
0 \\
0 \\
0 \\
0 \\
0 \\
0 \\
0 \\
0 \\
0 \\
0 \\
0 \\
0 \\
0 \\
0 \\
0 \\
0 \\
0 \\
\end{bmatrix*}
1
%$$
\]
\end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.