3

I have this code, which outputs a block matrix:

\documentclass[letterpaper,12pt]{book}
\usepackage[T1]{fontenc}    
\usepackage[spanish,es-tabla]{babel} 
\usepackage{amsmath, nccmath, amsthm}   
\usepackage{arydshln}

\newcommand{\biga}{\mbox{\normalfont\Large\bfseries $A_i$}}
\newcommand{\rvline}{\hspace*{-\arraycolsep}\vline\hspace*{-\arraycolsep}}



\begin{document}


\[
\begin{pmatrix}
  \begin{matrix}
  1  \\
  1 \\
  1
  \end{matrix}
  & \rvline
 & \begin{matrix}
  \begin{matrix}
  a & b \\
  \hline
  \end{matrix}
  & \rvline & a \\
  \biga & \rvline &
  \begin{matrix}
  a  \\
  c 
  \end{matrix}
 \end{matrix}
\end{pmatrix}
\]

\end{document}

I want to do two things with it. First,

  • To change \newcommand{\biga}{\mbox{\normalfont\Large\bfseries $A_i$}} in such a way that I can change the i in $A_i$ for a different number each time I use it.
  • To change the lines for dotted lines.

I have tried lots of things already.

THANKS

2
  • 2
    You should provide a complete MWE (with the \documentclass, the needed \usepackage, etc). Mar 6, 2021 at 20:55
  • @F.Pantigny done. I beleive. It compiles. Mar 6, 2021 at 21:08

2 Answers 2

4

Here is a way to do that with {pNiceMatrix} of nicematrix.

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

\NewDocumentCommand{\MyMatrix}{m}
  {
    \begin{pNiceMatrix}
    1 & a                           & b & a \\
    1 & \Block{2-2}<\Large>{A_{#1}} &   & a \\
    1 &                             &  & c 
    \CodeAfter 
        \tikz \draw [dotted] (1-|2) -- (4-|2) 
                             (1-|4) -- (4-|4) 
                             (2-|2) -- (2-|4) ;
    \end{pNiceMatrix}
  }

\begin{document}

$\MyMatrix{i}$\qquad $\MyMatrix{1}$

\end{document}

Output of the above code

Explanations

The syntax (i-|j) specify the point at the intersection of the (potential) horizontal line number i and the (potential) vertical line number j.

\draw (point1) -- (point2) ; is the Tikz instruction to draw a line between two points.

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

 \begin{document}

 $\begin{NiceMatrix}
 1 & a                           & b & a \\
 1 & \Block{2-2}<\Large>{A_1} &   & a \\
 1 &                             &  & c 
 \CodeAfter 
 \tikz 
 \draw 
    (2-|2) circle (0.1mm) node [left] {\tiny \color{red} (2-$|$2)} 
 -- (2-|4) circle (0.1mm) node [right] {\tiny \color{red} (2-$|$4)} ;
 \end{NiceMatrix}$

 \end{document}

Output of the second code

5
  • Not OP but I have one question, why are you writing {m} on the command definition? Shouldn't there be the number of inputs that the commad has? Thanks in advance!
    – Jes
    Mar 6, 2021 at 21:18
  • 1
    @Jes: With \NewDocumentCommand, which is now the recommend way to define user-commands in LaTeX, you put m for each mandatory argument (see the documentation of xparse). Mar 6, 2021 at 21:23
  • Thank you! I will check it ;)
    – Jes
    Mar 6, 2021 at 21:25
  • @F.Pantigny could you specify a bit more how is it working the code after ` \draw [dotted] ` ? It sets the coordinates of the dotted lines, yes, but what is (1-|2) -- (4-|2) (1-|4) etc? Mar 7, 2021 at 0:48
  • @Ofelia y Orquesta: I have added explanations. Mar 7, 2021 at 9:21
2

To change \newcommand{\biga}{\mbox{\normalfont\Large\bfseries $A_i$}} in such a way that I can change the i in $A_i$ for a different number each time I use it.

\newcommand{\biga}[1][i]{\mbox{\normalfont\Large\bfseries $A_{#1}$}}

One optional additional argument for \newcommand, "i" by default

default usage: \biga
custom index: \biga[x]
without index: \biga[]

You must log in to answer this question.

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