
Tentando criar uma matriz usando a marcação abaixo:
\begin{figure}
\centering
\[
\begin{blockarray}{cccccccc}
I & like & nlp & mlpr & enjoy & reading & books \\
\begin{block}{[ccccccc]c}
1 & 1 & 1 & 1 & 1 & 1 & 1 & I \\
1 & 1 & 1 & 1 & 1 & 1 & 1 & like \\
1 & 1 & 1 & 1 & 1 & 1 & 1 & nlp \\
1 & 1 & 1 & 1 & 1 & 1 & 1 & mlpr \\
1 & 1 & 1 & 1 & 1 & 1 & 1 & enjoy \\
1 & 1 & 1 & 1 & 1 & 1 & 1 & reading \\
1 & 1 & 1 & 1 & 1 & 1 & 1 & books \\
\end{block}
\end{blockarray}
\]
\caption{A caption to the entire figure}
\end{figure}
A saída que recebo é a seguinte:
Como você pode ver, as colunas da matriz estão espaçadas de forma desigual. Seria ótimo se eu conseguisse colunas com espaçamento uniforme.
Alguma ideia?
Responder1
Aviso: não sou blkarray
especialista ;-)
No entanto, é possível definir um novo tipo de coluna (digamos B) para blockarray
o qual utiliza a mesma largura para todas as colunas com este especificador.
Como existem 7 colunas com esse recurso, pode-se encurtar ccccccc
e substituir por *{7}B
como em ambientes tabulares usuais.
Eu tenho que descobrir se \BAnewcolumntype
suporta o tipo de coluna com um argumento.
\documentclass{article}
\usepackage{mathtools}
\usepackage{blkarray}
\BAnewcolumntype{B}{>{\centering}p{1cm}}
\begin{document}
\begin{figure}
\centering
$
\begin{blockarray}{cccccccc}
\text{I} & \text{like} & \text{nlp} & \text{mlpr} & \text{enjoy} & \text{reading} & \text{books} \\
\begin{block}{[*{7}B]c}
1 & 1 & 1 & 1 & 1 & 1 & 1 & \text{I} \\
1 & 1 & 1 & 1 & 1 & 1 & 1 & \text{like} \\
1 & 1 & 1 & 1 & 1 & 1 & 1 & \text{nlp} \\
1 & 1 & 1 & 1 & 1 & 1 & 1 & \text{mlpr} \\
1 & 1 & 1 & 1 & 1 & 1 & 1 & \text{enjoy} \\
1 & 1 & 1 & 1 & 1 & 1 & 1 & \text{reading} \\
1 & 1 & 1 & 1 & 1 & 1 & 1 & \text{books} \\
\end{block}
\end{blockarray}
$
\caption{A caption to the entire figure}
\end{figure}
\end{document}
Responder2
O tabstackengine
pacote tem uma opção de largura fixa para arrays, que utilizo aqui. Por conta disso, bastava fazer uma única entrada no array "1" com a mesma largura da palavra "leitura" e o resto estava resolvido. Eu consegui isso com \tmpbox
.
O pacote também permite empilhar texto ou matemática, que usei aqui para empilhar o texto como texto e os números como matemática.
\documentclass{article}
\usepackage{tabstackengine}
\setstackEOL{\cr}
\setstacktabbedgap{1ex}
\fixTABwidth{T}
\begin{document}
\begin{figure}
\centering
\[
\stackText
\setbox0=\hbox{reading}
\savestack{\tmpbox}{\makebox[\wd0]{$1$}}
\savestack{\toprow}{\tabbedCenterstack{I & like & nlp & mlpr & enjoy & reading & books}}
\ensurestackMath{
\stackon{\bracketMatrixstack{
\tmpbox & 1 & 1 & 1 & 1 & 1 & 1 \cr
1 & 1 & 1 & 1 & 1 & 1 & 1 \cr
1 & 1 & 1 & 1 & 1 & 1 & 1 \cr
1 & 1 & 1 & 1 & 1 & 1 & 1 \cr
1 & 1 & 1 & 1 & 1 & 1 & 1 \cr
1 & 1 & 1 & 1 & 1 & 1 & 1 \cr
1 & 1 & 1 & 1 & 1 & 1 & 1
}}{\toprow}}
\Centerstack{ I \cr like \cr nlp \cr mlpr \cr enjoy \cr reading \cr books}
\]
\caption{A caption to the entire figure}
\end{figure}
\end{document}
O intervalo entre colunas é definido como 1ex com \setstacktabbedgap{1ex}
. Se alguém desejasse que o salto de linha de base entre linhas fosse maior, a linha \setstackgap{L}{1.2\baselineskip}
poderia ser adicionada ao preâmbulo para obter o seguinte resultado:
Finalmente, pode-se alinhar à esquerda a coluna de palavras à direita adicionando um [l]
argumento opcional ao \Centerstack
.
Responder3
Uma variante com uma coluna a menos e 7 blocos, com \Right{.}{text}
no final o preâmbulo de cada bloco. Também utilizo o eqparbox
pacote para garantir colunas com larguras iguais, sem ter que encontrar por tentativas e erros qual será o tamanho certo:
\documentclass{article}
\usepackage{mathtools}
\usepackage{blkarray}
\usepackage{eqparbox}
\BAnewcolumntype{B}{>{\centering}p{1cm}}
\begin{document}
\begin{figure}
\centering\makeatletter\setlength\tabcolsep{-10pt}\BA@colsep =1pt\makeatother
$
\begin{blockarray}{*{7}{c}}
\eqmakebox[C]{I} & \eqmakebox[C]{like} & \eqmakebox[C]{nlp} & \eqmakebox[C]{mlpr} & \eqmakebox[C]{enjoy} & \eqmakebox[C]{reading} & \eqmakebox[C]{books} \\
\begin{block}{*{7}{c}\Right{.}{I}}
1 & 1 & 1 & 1 & 1 & 1 & 1 \\
\end{block}
\begin{block}{*{7}{c}\Right{.}{like}}
1 & 1 & 1 & 1 & 1 & 1 & 1 \\
\end{block}
\begin{block}{*{7}{c}\Right{.}{nlp}}
1 & 1 & 1 & 1 & 1 & 1 & 1 \\
\end{block}
\begin{block}{*{7}{c}\Right{.}{mlpr}}
1 & 1 & 1 & 1 & 1 & 1 & 1 \\
\end{block}
\begin{block}{*{7}{c}\Right{.}{enjoy}}
1 & 1 & 1 & 1 & 1 & 1 & 1 \\
\end{block}
\begin{block}{*{7}{c}\Right{.}{reading}}
1 & 1 & 1 & 1 & 1 & 1 & 1 \\
\end{block}
\begin{block}{*{7}{c}\Right{.}{books}}
1 & 1 & 1 & 1 & 1 & 1 & 1 \\
\end{block}
\end{blockarray}
$
\caption{A caption to the entire figure}
\end{figure}
\end{document}