[Tex/LaTex] Aligning different matrices

matricesvertical alignment

I want to write the companion matrix of a recurrence relation and its use (the notation will be a bit unusual since it is "for cryptography", where we always do stuff in a different way).

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

\begin{document}

\[
  C :=
   \begin{pmatrix}
   0      & 1      & 0      & \cdots & 0 \\
   0      & 0      & 1      & \cdots & 0 \\
   \vdots & \vdots & \vdots & \ddots & \vdots \\
   0      & 0      & 0      & \ddots & 1 \\
   c_0    & c_1    & c_2    & \cdots & c_{n-1}  \\
  \end{pmatrix}
%%%
    \quad\textrm{and}\quad
%%%
  C \cdot
  \begin{pmatrix}
  y_{k} \\ y_{k+1} \\ \vdots \\ y_{n+k-2} \\ y_{n+k-1} \\
   \end{pmatrix}
=
  \begin{pmatrix}
  y_{k+1} \\ y_{k+2} \\ \vdots \\ y_{n+k-1} \\ y_{n+k} \\
   \end{pmatrix}
   \enspace.
\]

\end{document}

however, the square matrix is taller than the column vectors. How can I make everything align nicely?

rendering of above code

Roberto

EDIT: Thank you all folks, in my case it was the wrong \ddots (ahem).

EDIT 2:

So, merging @percusse's suggestion with braces over matrix I came up with this

\def\matriximg{%
    \begin{array}{c|ccc}
      \\
      \vphantom{\vdots} 0 &\multicolumn{3}{c}{I_{n-1}} \\
      \\ \hline
      \vphantom{y_k} c_0  & c_1 & \ldots &c_{n-1}
    \end{array}
}%
\begin{equation}
 \label{eq:companion}
  \left(\vphantom{\matriximg}\right.%
  \kern-2\nulldelimiterspace%
  \underbrace{\matriximg}_{\displaystyle C}%
  \kern-\nulldelimiterspace%
  \left.\vphantom{\matriximg}\right)%
%
  \cdot
%
     \left(\!\begin{array}{c}
     y_{k} \\ \hline y_{k+1} \\ \vdots  \\ y_{n+k-1} \\
     \end{array}\!\right)
  =
     \left(\!\begin{array}{c}
     y_{k+1} \\ \vdots \\ y_{n+k-1} \\ \hline y_{n+k} \\
     \end{array}\!\right)
  \enspace.
\end{equation}

Best Answer

Curious. It turns out \ddots is slightly higher than other characters. I suggest \smash ing them in the first matrix:

Sample output

\documentclass[11pt]{article}

\usepackage{mathtools}

\begin{document}

\begin{equation*}
  C \coloneqq
   \begin{pmatrix}
   0      & 1      & 0      & \cdots & 0 \\
   0      & 0      & 1      & \cdots & 0 \\
   \vdots & \vdots & \vdots & \smash{\ddots} & \vdots \\
   0      & 0      & 0      & \smash{\ddots} & 1 \\
   c_0    & c_1    & c_2    & \cdots & c_{n-1} 
  \end{pmatrix}
%%%
    \quad\textrm{and}\quad
%%%
  C \cdot
  \begin{pmatrix}
   y_{k} \\  y_{k+1} \\ \vdots \\ 
  y_{n+k-2} \\  y_{n+k-1} 
   \end{pmatrix}
   =
  \begin{pmatrix}
   y_{k+1} \\ y_{k+2} \\ \vdots \\ y_{n+k-1} \\ y_{n+k} \\
   \end{pmatrix}
   .
\end{equation*}

\end{document}

I have used mathtools just get the \coloneqq symbol.

Related Question