Matrices en látex

Matrices en látex

Intentando crear una matriz usando el siguiente marcado:

\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}

El resultado que obtengo es el siguiente:

ingrese la descripción de la imagen aquí

Como puede ver, las columnas de la matriz están espaciadas de manera desigual. Sería fantástico si pudiera conseguir columnas espaciadas uniformemente.

¿Algunas ideas?

Respuesta1

Advertencia: no soy blkarrayun experto ;-)

Sin embargo, es posible definir un nuevo tipo de columna (digamos B) para blockarrayel cual se utiliza el mismo ancho para todas las columnas con este especificador.

Dado que hay 7 columnas con esta característica, se podrían acortar cccccccy reemplazar *{7}Bcomo en los entornos tabulares habituales.

Tengo que averiguar si es \BAnewcolumntypecompatible con el tipo de columna con un 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}

ingrese la descripción de la imagen aquí

Respuesta2

El tabstackenginepaquete tiene una opción de ancho fijo para matrices, que empleo aquí. Debido a eso, simplemente necesitaba hacer una sola entrada en la matriz "1" del mismo ancho que la palabra "lectura" y el resto se resolvió. Lo logré con \tmpbox.

El paquete también permite apilar texto o matemáticas, lo que usé aquí para apilar el texto como texto y los números como matemáticas.

\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}

ingrese la descripción de la imagen aquí

El espacio entre columnas se establece en 1ex con \setstacktabbedgap{1ex}. Si se desea que el salto de línea de base entre filas sea mayor, \setstackgap{L}{1.2\baselineskip}se podría agregar la línea al preámbulo para lograr el siguiente resultado:

ingrese la descripción de la imagen aquí

Finalmente, se podría alinear a la izquierda la columna de palabras de la derecha agregando un [l]argumento opcional al archivo \Centerstack.

Respuesta3

Una variante con una columna menos, y 7 bloques, con \Right{.}{text}al final del preámbulo de cada bloque. También uso el eqparboxpaquete para asegurar columnas de igual ancho, sin tener que encontrar mediante pruebas y errores cuál será el tamaño correcto:

\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} 

ingrese la descripción de la imagen aquí

información relacionada