2

Is there an elegant way of splitting labels across two or more lines when using kbordermatrix?

Consider the following example:

I'd like to split the label across two lines.

Now, the following does not work at all:

\documentclass{standalone}
\usepackage{kbordermatrix}
\usepackage{tikz}
\begin{document}
\kbordermatrix{
  & \begin{tikzpicture}\node[align=center] at (0,0){a label consisting\\of several words};\end{tikzpicture}\\ 
a & $0$\\
b & $0$
}
\end{document}

And the following

\documentclass{standalone}
\usepackage{kbordermatrix}
\usepackage{tikz}
\begin{document}
\kbordermatrix{
  & \begin{minipage}{0.1\textwidth}a label consisting\\of several words\end{minipage}\\ 
a & $0$\\
b & $0$
}
\end{document}

produces this:

which is obviously not good.

1
  • Could you post a sketch of what you're trying to obtain? It's not clear to me.
    – Bernard
    Commented Aug 15, 2021 at 14:10

3 Answers 3

2

With {NiceTabular} of nicematrix.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\begin{NiceTabular}{cc}
    & \small \Block{}{A label\\ consisting\\ of several\\ words} \\
$a$ & $0$ \\
$b$ & $0$ \\
\CodeAfter 
  \SubMatrix[{2-2}{3-2}]
\end{NiceTabular}

\end{document}

Output of the above code

1

I propose to use the blkarray and stackengine packages for that:

\documentclass[border=6pt]{standalone}
\usepackage{kbordermatrix}
\usepackage{blkarray}
\usepackage[usestackEOL]{stackengine}

\begin{document}

 $\setstackgap{L}{2ex} \begin{blockarray}{rc}
 & \scriptsize\Centerstack{A label\\ consisting \\of several \\words} \\
\begin{block}{ >{\scriptstyle}r[c]}
 a & 0 \\
 b & 0 \\
\end{block}
\end{blockarray} $

\end{document}

enter image description here

1

Thanks to all the answers. I'll post here an alternative that I stumbled on myself, one that uses bnicematrix as well.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}
$
\begin{bNiceMatrix}[first-row,first-col]
    & \mbox{\begin{tabular}{c}
            \textnormal{A label ,}\\\textnormal{on several rows}
            \end{tabular}
        } \\
        a & 0 \\
        b & 1 
\end{bNiceMatrix}
$
\end{document}

Resuld of which looks as follows:

enter image description here

You must log in to answer this question.

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