9

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}
3
  • Do you need the diagonal dots in row 4 column 4? If you replace them by \cdots, all problems are gone.
    – LaRiFaRi
    Jul 8, 2014 at 13:58
  • Uh, @LaRIFaRi, thank you, that was the problem. Cough cough. The other solutions are nice as well and contain elements that will definitely prove useful in my further TeXing!
    – mocenigo
    Jul 8, 2014 at 15:30
  • Nice! But horizontal lines are guiding the reader for the size property so you don't need the subscript of identity matrix. I would trust the reader instead. In my notes, I even remove the indices of the shifted part of the vectors and place a single character to indicate. Might a bit too much for your audience though.
    – percusse
    Jul 8, 2014 at 19:20

3 Answers 3

4

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.

1
  • Yes, this is more elegant. \ddots is more then two times higher than y_{n+k-2}. I guess, they got some extra space above and below in order to get nicer spacings. The same for \vdots. Therefore you have to smash all dots in the middle row or leave the whole row as it is.
    – LaRiFaRi
    Jul 8, 2014 at 14:35
2

The easiest way would be to replace the \ddots in row 4 by \cdots. I think, this makes more sense but maybe you need it this way.

The problem is that the \ddots are higher than the expressions in row 4 of the second and third term. If you increase the height of these expressions as shown in my MWE below, the alignment will be fixed again. If you want to distribute the rows more evenly, you could add such a \vphantom{\ddots} to the other rows, too.

% arara: pdflatex

\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}\vphantom{\ddots} \\ y_{n+k-1} \\
   \end{pmatrix}
=
  \begin{pmatrix}
  y_{k+1} \\ y_{k+2} \\ \vdots \\ y_{n+k-1}\vphantom{\ddots} \\ y_{n+k} \\
   \end{pmatrix}
   \enspace.
\]

\end{document}

enter image description here

Edit

\ddots and \vdots are enlarged by round about 50 % on the top and the bottom. This shall result in nicer spacing for typical dotted matrices. Maybe there are cropped dot-symbols around, but I haven't checked that.

2

As usual, in my ignorant opinion, the dots are ugly and making the matrix unreadable even when you have the most basic companion structure in the state matrix. Here is something that is more appealing to my taste which emphasizes the shift operation;

\documentclass{article}

\begin{document}
\[
\underbrace{\left(
\begin{array}{c|ccc}
\\0   &\multicolumn{3}{c}I\\ 
\\ \hline c_0 &c_1 &\ldots &c_{n-1}
\end{array}
\right)}_C\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)
\]
\end{document}

enter image description here

2
  • this is indeed nice. Since I am a fine typography freak, I may end up adopting this ;-)
    – mocenigo
    Jul 8, 2014 at 18:50
  • @mocenigo By all means. We need to increase the number of the members of the club :P
    – percusse
    Jul 8, 2014 at 19:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .