# A matrix with first row and column spanning over a sub-matrix

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{makeidx}
\usepackage{graphicx}

\begin{document}

$P=\left[ \begin{array}{cccc|cccccccccccc} 1 & 1 & \dots &1 & 1 & 1& \dots & 1 \\ 1 & & & & & & \\ \vdots & & \textbf{\Huge{C}} & &&& \textbf{\Huge{0}} & \\ 1 & & & & & & \\ \cline{2-8} 1 & & & & & & \\ \cdots & & \textbf{\Huge{0}} & & &&\textbf{\Huge{D}} \\ 1 & & & & & & \end{array} \right]$

\end{document}


I have written the following code. The problem I am facing is I want the line to appear after the first row. Please find the picture attached of the matrix I want to have. How do I remove the line from the first row? Please help I would be happy and grateful if it be done by just doing some manipulations to my given code. I want to do it without using any packages

By adapting the code of the OP:

\documentclass{article}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}

\begin{document}
\begin{center}
$P= \left[ \begin{matrix} 1 & 1 & \dots & 1 & 1 & 1 & \dots & 1 \\ 1 & & & & \multicolumn{1}{c|}{} & & \\ \vdots & & \textbf{\Huge{C}} & & \multicolumn{1}{c|}{} & & \textbf{\Huge{0}} & \\ 1 & & & & \multicolumn{1}{c|}{} & & \\ \cline{2-8} 1 & & & & \multicolumn{1}{c|}{} & & \\ \vdots & & \textbf{\Huge{0}} & & \multicolumn{1}{c|}{} & &\textbf{\Huge{D}} \\ 1 & & & & \multicolumn{1}{c|}{} & & \end{matrix} \; \right]$
\end{center}
\end{document} • The display structure $...$ automatically centers the display, so there's no need for \begin{center} ... \end{enter}. Otherwise, very effective. Jun 11, 2020 at 1:03
• Yes perfect!! Thank you very much!! You are awesome Panti!! Jun 11, 2020 at 3:15
• Hi, can you give, please, tex.stackexchange.com/questions/554659/… an answer using nicematrix package into this question? Thank you very much. Jul 24, 2020 at 11:59

A proposition with nicematrix:

\documentclass{article}
\usepackage{nicematrix}
\usepackage{tikz}

\begin{document}

$\begin{pNiceArray}{ccccr}[columns-width=4mm,right-margin,nullify-dots] 1 & \Cdots & & & 1 \\ \Vdots & \Block{2-2}<\Large>{C} & & \Block{2-2}<\Large>{0} & \\ \\ & \Block{2-2}<\Large>{0} & & \Block{2-2}<\Large>{D} & \\ 1 \CodeAfter \tikz \draw (4-|2) -- (4-|6) (2-|4) -- (6-|4) ; \end{pNiceArray}$

\end{document} • can you give any way to do it without nicematrix Jun 10, 2020 at 16:35
• can't it be done by just doing some manipulations to my given code, i want to do it without using complicated packages Jun 10, 2020 at 16:37

With array and some nesting:

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

\newcommand{\bigentry}[\huge]{\begin{tabular}{@{}c@{}}#1$#2$\end{tabular}}

\begin{document}

\newcommand{\ones}{\begin{matrix} 1 \\[-1ex] \vdots \\ 1 \end{matrix}} \left[\begin{array}{ c @{} c | c @{} } \noalign{\vspace{0.5ex}} \begin{matrix} 1 \end{matrix} & \multicolumn{1}{c@{}}{\begin{matrix} 1 & \dots & 1 \end{matrix}} & \begin{matrix} 1 & \dots & 1 \end{matrix} \\ \ones & \bigentry{\mathbf{C}} & \bigentry{\mathbf{0}} \\ \cline{2-3} \ones & \bigentry{\mathbf{0}} & \bigentry{\mathbf{D}} \\ \noalign{\vspace{0.5ex}} \end{array}\right]

\end{document} We need a couple of tricks because of \vdots not being really suitable for the purpose, so some vertical space has to be added at the top and the bottom.

Avoid \textbf for math objects in formulas, it should be \mathbf.

The nested tabular for \bigentry ensures vertical centering and can accommodate a size changing command, which would otherwise be illegal in math mode.

The command \ones is just a local shorthand for reducing code clutter.

• Okay I will keep mathbf in mind, thanks a lot for suggesting Jun 10, 2020 at 16:44
• But can you do it without using any package and without using newcommand Jun 10, 2020 at 16:44
• @Math_Freak array is not essential; why would you do without amsmath? Jun 10, 2020 at 16:45
• Since i dont understand use of #@,is it possible to get rid of this \newcommand{\bigentry}[\huge]{\begin{tabular}{@{}c@{}}#1$#2$\end{tabular}} and do it? Jun 10, 2020 at 16:46
• @Math_Freak If your aim is to use it in MathJax, please tell it so, but in this case the question would be closed as off-topic. And no, I don't know how to make it work in MathJax and don't bother. Jun 10, 2020 at 16:47

Like this? I use nicematrix package to redraw the matrix, the key point is first-row option.

\documentclass{article}
\usepackage{nicematrix}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}

\begin{document}
$p=\left[ \begin{NiceArray}{*4{C}|*3{C}}[first-row, extra-margin=2mm] 1 & 1 & \Cdots & 1 & 1 & \Cdots & 1 \\ 1 & \Block{3-3}<\Huge>{\mathbf{C}} & & & \Block{3-3}<\Huge>{\mathbf{0}} & & \\ \Vdots & & & & & & \\ 1 & & & & & & \\ \cline{2-7} 1 & \Block{3-3}<\Huge>{\mathbf{0}} & & & \Block{3-3}<\Huge>{\mathbf{D}} & & \\ \Vdots & & & & & & \\ 1 & & & & & & \\ \end{NiceArray}\right]$
\end{document} • Thanks but the dots are going through 1 in 1st row Jun 10, 2020 at 16:42
• @Math_Freak answer changed Jun 10, 2020 at 16:45
• can u please do it without \newcommand{\Hugeeq}{\text{\Huge $\mathbf{#1}$}}, i dont understand use of #1 Jun 10, 2020 at 16:49
• @Math_Freak it is just a format command, if you don't like it, replace the command with what you want to display. Jun 10, 2020 at 17:05
{"ft_lang_label":"__label__en","ft_lang_prob":0.6305518,"math_prob":0.9641745,"size":856,"snap":"2022-27-2022-33","text_gpt3_token_len":289,"char_repetition_ratio":0.19366197,"word_repetition_ratio":0.12162162,"special_character_ratio":0.36098132,"punctuation_ratio":0.03649635,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97519755,"pos_list":[0,1,2,3,4,5,6,7,8,9,10],"im_url_duplicate_count":[null,3,null,3,null,3,null,3,null,3,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-08-12T22:14:36Z\",\"WARC-Record-ID\":\"<urn:uuid:90e977b0-a477-4215-99c6-f3c97e15f24f>\",\"Content-Length\":\"270598\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:5e44db06-572a-4fcb-b73b-7d02b1b0a7cf>\",\"WARC-Concurrent-To\":\"<urn:uuid:ebcef504-fe5a-48ca-b801-7f5c1759e762>\",\"WARC-IP-Address\":\"151.101.1.69\",\"WARC-Target-URI\":\"https://tex.stackexchange.com/questions/548798/a-matrix-with-first-row-and-column-spanning-over-a-sub-matrix\",\"WARC-Payload-Digest\":\"sha1:5TVVGXJ2EJD2CB3I4P3WCG4B2AFETAUY\",\"WARC-Block-Digest\":\"sha1:WCRAY5Y43LAOWHGFXSJDIONNVNJETBTG\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-33/CC-MAIN-2022-33_segments_1659882571758.42_warc_CC-MAIN-20220812200804-20220812230804-00294.warc.gz\"}"}