6

I'm struggling to make all the matrices in my equation of same height (vertical alignment). I would appreciate if I could get some suggestions. I tried some solutions here and there but it's looks my question is different. this what I got

\documentclass{article}   
\usepackage{amsmath}
\begin{document}
\begin{equation} \label{eq:system_dynamics_l}
\begin{bmatrix}
m_1+m_2 & \dfrac{1}{2}m_2 L  \\\[4mm\]
\dfrac{1}{2}m_2 L  & \dfrac{1}{2}m_2 L^2
\end{bmatrix}
\begin{bmatrix}
\ddot{x} \\\[4mm\] \ddot{\theta}
\end{bmatrix}
+ \begin{bmatrix}
b & 0  \\\[4mm\]
0 & c
\end{bmatrix}\begin{bmatrix}
\dot{x} \\\[4mm\] \dot{\theta}
\end{bmatrix}
+\begin{bmatrix}
k & 0 \\\[4mm\] 0 & m_2g\dfrac{L}{2}
\end{bmatrix}\begin{bmatrix}
x \\\[4mm\]  \theta
\end{bmatrix}
=\begin{bmatrix}
0 \\\[4mm\]  0
\end{bmatrix}
\end{equation}
\end{document}
  • try \tfrac for your fractions – Elements in Space Apr 26 '18 at 13:40
  • 3
    why are you forcing over sized 1/2 via \dfrac{1}{2} ? (just use \frac) – David Carlisle Apr 26 '18 at 13:40
8

Because \dfrac is higher than other elements of your matrices. Here are two possibilities: use \tfrac or \vphantoms.

enter image description here

\documentclass{article}   
\usepackage{amsmath}
\begin{document}
Arguably simplest solution (thanks to David Carlisle)
\begin{equation} \label{eq:system_dynamics_0}
\begin{bmatrix}
m_1+m_2 & \tfrac{1}{2}m_2 L  \\[4mm]
\tfrac{1}{2}m_2 L  & \tfrac{1}{2}m_2 L^2
\end{bmatrix}
\begin{bmatrix}
\ddot{x} \\[4mm] \ddot{\theta}
\end{bmatrix}
+ \begin{bmatrix}
b & 0  \\[4mm]
0 & c
\end{bmatrix}\begin{bmatrix}
\dot{x} \\[4mm] \dot{\theta}
\end{bmatrix}
+\begin{bmatrix}
k & 0 \\[4mm] 0 & m_2g\tfrac{L}{2}
\end{bmatrix}\begin{bmatrix}
x \\[4mm]  \theta
\end{bmatrix}
=\begin{bmatrix}
0 \\[4mm]  0
\end{bmatrix}
\end{equation}

Original proposal 1:
\begin{equation} \label{eq:system_dynamics_l}
\begin{bmatrix}
m_1+m_2 & \tfrac{1}{2}m_2 L  \\[4mm]
\tfrac{1}{2}m_2 L  & \tfrac{1}{2}m_2 L^2
\end{bmatrix}
\begin{bmatrix}
\ddot{x} \\[4mm] \ddot{\theta}
\end{bmatrix}
+ \begin{bmatrix}
b & 0  \\[4mm]
0 & c
\end{bmatrix}\begin{bmatrix}
\dot{x} \\[4mm] \dot{\theta}
\end{bmatrix}
+\begin{bmatrix}
k & 0 \\[4mm] 0 & m_2g\tfrac{L}{2}
\end{bmatrix}\begin{bmatrix}
x \\[4mm]  \theta
\end{bmatrix}
=\begin{bmatrix}
0 \\[4mm]  0
\end{bmatrix}
\end{equation}

In case you want to keep the \verb|\dfrac|s, which is perfectly fine IMHO
\begin{equation} \label{eq:system_dynamics_2}
\begin{bmatrix}
m_1+m_2 & \dfrac{1}{2}m_2 L  \\[4mm]
\dfrac{1}{2}m_2 L  & \dfrac{1}{2}m_2 L^2
\end{bmatrix}
\begin{bmatrix}\vphantom{\dfrac{1}{2}}
\ddot{x} \\[4mm] \vphantom{\dfrac{1}{2}}\ddot{\theta}
\end{bmatrix}
+ \begin{bmatrix}
\vphantom{\dfrac{1}{2}}b & 0  \\[4mm]
\vphantom{\dfrac{1}{2}}0 & c
\end{bmatrix}\begin{bmatrix}
\vphantom{\dfrac{1}{2}}\dot{x} \\[4mm] \vphantom{\dfrac{1}{2}}\dot{\theta}
\end{bmatrix}
+\begin{bmatrix}
\vphantom{\dfrac{1}{2}}k & 0 \\[4mm] 0 & m_2g\dfrac{L}{2}
\end{bmatrix}\begin{bmatrix}
\vphantom{\dfrac{1}{2}}x \\[4mm] \vphantom{\dfrac{1}{2}} \theta
\end{bmatrix}
=\begin{bmatrix}
\vphantom{\dfrac{1}{2}}0 \\[4mm]  \vphantom{\dfrac{1}{2}}0
\end{bmatrix}
\end{equation}
\end{document}
  • +1. However, instead of m_2g\tfrac{L}{2}, I'd write \tfrac{1}{2}m_2gL to improve legibility. – Mico Apr 26 '18 at 14:14
  • 2
    @Mico I agree, of course, but I guess that is up to the OP to decide. I only focused on the alignment of the brackets. – user121799 Apr 26 '18 at 14:39
  • 2
    I'd use \frac rather than \tfrac as shown by the question most of the time forcing \dfrac or \tfrac either does what \frac would do, or does the wrong thing. – David Carlisle Apr 26 '18 at 15:17
  • @DavidCarlisle You are right, of course. Except if the OP would start adding \displaystyle somewhere. So with your permission I'd like to modify my answer to include your suggestion. – user121799 Apr 26 '18 at 15:20
  • sure feel free:-) – David Carlisle Apr 26 '18 at 15:22
8

The easiest way to handle Ratios Of Unusual Size (ROUS) is to increase \arraystretch (macro). Every row starts with a strut of height \arraystretch\ht\strutbox.

\documentclass{article}   
\usepackage{amsmath}
\begin{document}
\begin{equation} \label{eq:system_dynamics_l}
\def\arraystretch{1.7}%
\begin{bmatrix}
m_1+m_2 & \dfrac{1}{2}m_2 L  \\
\dfrac{1}{2}m_2 L  & \dfrac{1}{2}m_2 L^2
\end{bmatrix}
\begin{bmatrix}
\ddot{x} \\ \ddot{\theta}
\end{bmatrix}
+ \begin{bmatrix}
b & 0  \\
0 & c
\end{bmatrix}\begin{bmatrix}
\dot{x} \\ \dot{\theta}
\end{bmatrix}
+\begin{bmatrix}
k & 0 \\ 0 & m_2g\dfrac{L}{2}
\end{bmatrix}\begin{bmatrix}
x \\  \theta
\end{bmatrix}
=\begin{bmatrix}
0 \\  0
\end{bmatrix}
\end{equation}
\end{document}

demo

  • +1 for the nicely-placed reference to one of the most memorable scenes in the movie "The Pricess Bride". :-) – Mico Apr 26 '18 at 14:15
  • Just to be fussy: I'd put the redefinition of \arraystretch within equation. The environment grouping prevents unpleasant consequences. – campa Apr 26 '18 at 14:42
  • @campa - right you are. – John Kormylo Apr 26 '18 at 15:00
  • @JohnKormylo what is this"1.7"? – AlFagera Apr 28 '18 at 10:47
  • 1
    @AlFagera - \arraystretch is a scale factor applied to the strut at the start of every row of the array row. 1.6 was too small. – John Kormylo Apr 28 '18 at 13:53
1

I propose a solution based on the medium-sized fractions from nccmath (in my opinion, for numerical coefficients, \dfrac is too large, and tfrac too small) and \vphantom{\mfrac{1}{2} at the relevant places. I also load cellspace to add some vertical padding to the matrix rows:

 \documentclass{article}

 \usepackage{amsmath, nccmath}
\usepackage{array}
\usepackage[math]{cellspace}
\setlength{\cellspacetoplimit}{2pt}
\setlength{\cellspacebottomlimit}{2pt}

\newcommand*{\mystrut}{\vphantom{\mfrac{1}{2}}}

\begin{document}

\begin{equation} \label{eq:system_dynamics_l}
\begin{bmatrix}
m_1+m_2 & \mfrac{1}{2}m_2 L \\
\mfrac{1}{2}m_2 L & \mfrac{1}{2}m_2 L^2
\end{bmatrix}
\begin{bmatrix}
\ddot{x} \mystrut \\ \ddot{\theta} \mystrut
\end{bmatrix}
+ \begin{bmatrix}
b & 0 \mystrut \\
0 & c \mystrut
\end{bmatrix}
\begin{bmatrix}
\dot{x} \mystrut \\ \dot{\theta} \mystrut
\end{bmatrix}
+\begin{bmatrix}
k & 0 \mystrut \\ 0 & m_2g\mfrac{L}{2}
\end{bmatrix}\begin{bmatrix}
x \mystrut \\ \theta \mystrut
\end{bmatrix}
=\begin{bmatrix}
0 \mystrut \\ 0 \mystrut
\end{bmatrix}
\end{equation}

\end{document} 

enter image description here

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.