4

Please tell me the way to code latex to produce a matrix whose form is in the following image. Many thanks. My current code is not the desired one. matrix

    \documentclass[a4paper]{article}
    \usepackage{amsmath}
    \begin{document}
    \begin{equation}
    U^{(k+1)}_a=
    \left(
    \begin{array}{ccccc|c}
    &  &  &  &  & \left(U^{(k+1)}_a\right)_{0k} \\
    &  &  &  &  & \left(U^{(k+1)}_a\right)_{1k} \\
    &  &  U^{(k)}_a  &  &  & \vdots \\
    &  &  &  &  & \vdots \\
    &  &  &  &  & \vdots \\
    \hline
    a_k & 0 & \dots & 0 & 0 & \left (U^{(k+1)}_a\right)_{kk}
    \end{array}
    \right).
    \end{equation}
    \end{document}
dat le
  • 43

4 Answers4

4

It's actually a two-by-two matrix, with nested ones:

\documentclass{article}
\usepackage{amsmath,array}

\begin{document}

\[
U'=\left(
\begin{array}{@{}c|c@{}}
U & \begin{array}{@{}c@{}} a \\ b \\ \vdots \end{array} \\
\cline{1-1}
\multicolumn{1}{@{}c}{
  \begin{matrix} a & b & \cdots \end{matrix}
} & z
\end{array}
\right)
\]

\end{document}

enter image description here

egreg
  • 1,121,712
2

This can be done using the \multicolumn command. The \cline command makes the partial horizontal line. The 1-column \multicolumn in the last row eliminates the last portion of the vertical line. Using \multicolumn for the U^{(k)}_a entry automatically centers it horizontally instead of placing it in the third column.

I also added a bit of space between your rows by setting \arraystretch to 1.6.

\documentclass[a4paper]{article}
\usepackage{amsmath}
\begin{document}
\begin{equation}
U^{(k+1)}_a=
\left(
\renewcommand{\arraystretch}{1.6}
\begin{array}{ccccc|c}
&  &  &  &  & \left(U^{(k+1)}_a\right)_{0k} \\
&  &  &  &  & \left(U^{(k+1)}_a\right)_{1k} \\
\multicolumn{5}{c|}{U^{(k)}_a} & \vdots \\
&  &  &  &  & \vdots \\
&  &  &  &  & \vdots \\
\cline{1-5}
a_k & 0 & \dots & 0 & \multicolumn{1}{c}{0} & \left (U^{(k+1)}_a\right)_{kk}
\end{array}
\right).
\end{equation}
\end{document}

enter image description here

I would also probably delete the 4th column and two of the rows of \vdots, and use \cdots instead of \dots, but that's just my opinion. If you add \usepackage{array} you'll get a cleaner join between the horizontal and vertical lines.

U^{(k+1)}_a=
\left(
\renewcommand{\arraystretch}{2}
\begin{array}{cccc|c}
&  &  &  & \left(U^{(k+1)}_a\right)_{0k} \\
    \multicolumn{4}{c|}{U^{(k)}_a} & \left(U^{(k+1)}_a\right)_{1k} \\
&  &  &  & \vdots \\
\cline{1-4}
a_k & 0 & \cdots & \multicolumn{1}{c}{0} & \left (U^{(k+1)}_a\right)_{kk}
\end{array}
\right).

enter image description here

Sandy G
  • 42,558
  • Totally awesome! Thank you, Sandy G, not only because of helping me code but also guiding me to post question properly. – dat le Nov 13 '17 at 15:25
  • I should add, though it may seem strange, that comments should not be used for giving thanks. The way to show appreciation is to vote up an answer that you like (using the voting arrows to the left of the answer). Note that you can vote up more than one answer. You should also "accept" the answer that you believe is the best solution to your problem. – Sandy G Nov 13 '17 at 15:33
1

If you like to have more dots without interruption, you may wish to use tikz.

 \documentclass{article}
 \usepackage{amsmath}
 \usepackage{tikz}
 \usetikzlibrary{matrix}
 \begin{document}
 \[U'~=~\left(
 \vcenter{\hbox{\begin{tikzpicture}
 \node[matrix of math nodes] (mymat) {
    &  & ~& \left(U^{(k+1)}_a\right)_{0k} \\
    &  & ~& \left(U^{(k+1)}_a\right)_{1k} \\
    & ~~~~~~{\text{\Huge$U$}}~~~~~~ & &  \\[1cm]
  ~  &  & ~ & ~ \\
 a   &  &  & \left (U^{(k+1)}_a\right)_{kk}\\
 };
 \draw (mymat-1-4.north west) -- (mymat-5-4.north west);
 \draw (mymat-4-1.south west) -- (mymat-4-3.south east);
 \draw[ultra thick,line cap=round,dash pattern=on 0 off 1.6mm](mymat-2-4)--(mymat-4-4);
 \draw[ultra thick,line cap=round,dash pattern=on 0 off 1.6mm](mymat-5-1)--(mymat-5-4);
 \end{tikzpicture}}}\right)
 \]
 \end{document}

enter image description here

0

With {pNiceArray} of nicematrix. With that environment, the rules specified by \Hline (similar to hline) and the specifier | in the preamble are not drawn in the virtual blocks delimited by the commands for continuous dotted lines (\Vdots and \Cdots).

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

$U' = \begin{pNiceArray}{ccc|c}[xdots/shorten=4pt,left-margin=2pt] \Block{3-3}{U} & & & a \ & & & b \ & & & \Vdots \ \Hline a & b & \Cdots & z \end{pNiceArray}$

\end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).

Output of the above code

F. Pantigny
  • 40,250