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}
5
  • 1
    Welcome! You have much better chances of getting an answer if you provide a minimal working example. A good starting point for you might be the second answer to this question.
    – user121799
    Commented Nov 13, 2017 at 2:18
  • 1
    this might help: Seemingly simple block matrix Commented Nov 13, 2017 at 3:07
  • Welcome to TeX.SX. When you post a question, you are expected to provide a "Minimal Working Example" (MWE) that starts with \documentclass, includes all relevant \usepackage commands, ends with \end{document} and compiles without errors, even if it does not produce your desired output.
    – Sandy G
    Commented Nov 13, 2017 at 5:47
  • @barbarabeeton: Thank you, I have read the code but maybe it's too complicated to me. Thus, I expect a simpler one.
    – dat le
    Commented Nov 13, 2017 at 7:10
  • @SandyG: Thank you for your replying. I will do it for the next times.
    – dat le
    Commented Nov 13, 2017 at 7:11

4 Answers 4

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

2
  • Totally awesome! Thank you, Sandy G, not only because of helping me code but also guiding me to post question properly.
    – dat le
    Commented Nov 13, 2017 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
    Commented Nov 13, 2017 at 15:33
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

1
  • many thanks for your reply. It's greatly helpful.
    – dat le
    Commented Nov 13, 2017 at 15:23
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

You must log in to answer this question.

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