Math & ScienceHow to type complexity equation in overleaf

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
Ethan_Tran
Posts: 1
Joined: Tue Jun 27, 2023 4:18 am

How to type complexity equation in overleaf

Post by Ethan_Tran »

I tried to type an equation below in Overleaf. Please help me with how I could type it.
Thank you all,
Attachments
Capture.PNG
Capture.PNG (30.47 KiB) Viewed 10231 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
agsh
Posts: 5
Joined: Mon Jun 26, 2023 2:05 pm

How to type complexity equation in overleaf

Post by agsh »

Hello!

You need use nicematrix package. It definitelly can do such matrices.

https://ctan.org/pkg/nicematrix

Unfortunatelly, I'm not LaTeX professional, so this is the best I can do, sorry.

Code: Select all

\documentclass{article}

\usepackage{tikz}
\usepackage{nicematrix}

\begin{document}

$$
    \begin{pNiceArray}{ccccccccc}[first-row,first-col]
        & n + 1 & \cdots & n + m & 1 & \cdots & m & m +1 & \cdots & n \\
        {n + 1}& \Block[borders={bottom, right, tikz={dashed}}]{3-3}{\vec a} & & &
               \Block[borders={bottom, right, tikz={dashed}}]{3-3}{\vec b} & & &
               \Block[borders={bottom, tikz={dashed}}]{3-3}{\vec c} & & \\
        {\Vdots} & & & & & & & & & \\
        {n + m} & & & & & & & & & \\
        {1} & \Block[borders={bottom, right, tikz={dashed}}]{3-3}{\vec x} & & & \Block{6-6}{\vec a} & & & & & \\
        {\Vdots} & & & & & & & & & \\
        {m} & & & & & & & & & \\
        {m + 1} & \Block[borders={right, tikz={dashed}}]{3-3}{\vec y} & & & & & & & & \\
        {\Vdots} & & & & & & & & & \\
        {n} & & & & & & & & & \\
    \end{pNiceArray}
$$

\end{document}
Image

The main problem of my solution is that left exterior column is right aligned. According nicematrix documentation this is by design (page 24 on pdf documentation). In footnote 35 on this page I read that we need to use \CodeAfter and \Submatrix to make left exterior column be centering or to have other alignment. I tried this without success. The error is about the last column is empty, and I have no idea how to solve this. Of course there is an email of package author on the top of nicematrix documentation...

AGSH
FPantigny
Posts: 5
Joined: Wed Jul 26, 2023 10:37 pm

How to type complexity equation in overleaf

Post by FPantigny »

Here is a solution with nicematrix and the first column left-aligned (by using the command \SubMatrix in the so-called \CodeAfter.

Code: Select all

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

\begin{document}

\[
    \begin{NiceArray}{lccccccccc}[first-row]
        & n + 1 & \cdots & n + m & 1 & \cdots & m & m +1 & \cdots & n \\
        n + 1& \Block[borders={bottom, right, tikz=dashed}]{3-3}{\vec{a}} & & &
               \Block[borders={bottom, right, tikz=dashed}]{3-3}{\vec{b}} & & &
               \Block[borders={bottom, tikz=dashed}]{3-3}{\vec{c}} & & \\
        \vdots & & & & & & & & & \\
        n + m & & & & & & & & & \\
        1 & \Block[borders={bottom, right, tikz=dashed}]{3-3}{\vec{x}} & & & \Block{6-6}{\vec{a}} & & & & & \\
        \vdots & & & & & & & & & \\
        m & & & & & & & & & \\
        m + 1 & \Block[borders={right, tikz=dashed}]{3-3}{\vec{y}} & & & & & & & & \\
        \vdots & & & & & & & & & \\
        n & & & & & & & & & \\
    \CodeAfter
        \SubMatrix({1-2}{9-10})
    \end{NiceArray}
\]

\end{document}
Post Reply