Problemas con márgenes en matriz tikz

Problemas con márgenes en matriz tikz

Estoy creando un juego de mesa cuadrado, que requiere que se gire el texto de las celdas (para que todos los jugadores puedan leerlo). El problema que tengo es que cuando giro la celda me aparecen unos espacios extra, que no he podido eliminar. Como se sugiere en otras respuestas en este sitio, he usado

anchor=base,minimum width=1.75cm,minimum height=1.75cm,text height=2ex,text depth=0.25ex

y

column sep=0cm, row sep=0cm, outer sep=0pt,inner sep=0

a donde pertenece. Pero sigo recibiendo el error. Mi código es:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,matrix}
\usepackage{amsthm}
\usepackage{colortbl}
\begin{document}

\begin{tikzpicture}[element/.style={anchor=base,minimum width=1.75cm,minimum height=1.75cm,draw=black,line width=1pt,text height=2ex,text depth=0.25ex}]
\matrix (m) [matrix of nodes,nodes={element},column sep=0cm, row sep=0cm, outer sep=0pt,inner sep=0]{
|[draw,rotate=-90]|1 & |[draw,fill=blue!20,rotate=180]|10 & |[draw,rotate=-90]|11 & |[draw,fill=blue!20,rotate=180]|20 & |[draw,fill=red!20,rotate=180]|21 & |[draw,rotate=-90]|3 & |[draw,fill=blue!20,rotate=180]|10 & |[draw,rotate=-90]|31 & |[draw,fill=blue!20,rotate=180]|23 & |[draw,fill=red!20,rotate=180]|21 \\
|[draw,rotate=-90]|2 & |[draw,fill=red!20,rotate=180]|9 & |[draw,rotate=-90]|12 & |[draw,fill=red!20,rotate=180]|19 & |[draw,fill=red!20,rotate=180]|22 & |[draw,rotate=-90]|1 & |[draw,fill=blue!20,rotate=180]|10 & |[draw,rotate=-90]|11 & |[draw,fill=blue!20,rotate=180]|20 & |[draw,fill=red!20,rotate=180]|21 \\
|[draw,rotate=-90]|3 & |[draw,fill=blue!20,rotate=180]|8 & |[draw,rotate=-90]|13 & |[draw,fill=yellow!20,rotate=180]|18 & |[draw,fill=red!20,rotate=180]|23 & |[draw,rotate=-90]|1 & |[draw,fill=blue!20,rotate=180]|10 & |[draw,rotate=-90]|11 & |[draw,fill=blue!20,rotate=180]|20 & |[draw,fill=red!20,rotate=180]|21 \\
|[draw,rotate=-90]|4 & |[draw,fill=red!20,rotate=180]|7 & |[draw,rotate=-90]|14 & & & & & |[draw,rotate=-90]|11 & |[draw,fill=blue!20,rotate=180]|20 & |[draw,fill=red!20,rotate=180]|21\\
|[draw,rotate=-90]|5 & |[draw,fill=red!20,rotate=180]|6 & |[draw,rotate=-90]|15 & & & & & |[draw,rotate=-90]|11 & |[draw,fill=blue!20,rotate=180]|20 & |[draw,fill=red!20,rotate=180]|21 \\
|[draw,rotate=-90]|4 & |[draw,fill=red!20,rotate=180]|7 & |[draw,rotate=-90]|14 & & & & & |[draw,rotate=-90]|11 & |[draw,fill=blue!20,rotate=180]|20 & |[draw,fill=red!20,rotate=180]|21\\
|[draw,rotate=-90]|5 & |[draw,fill=red!20,rotate=180]|6 & |[draw,rotate=-90]|15 & & & & & |[draw,rotate=-90]|11 & |[draw,fill=blue!20,rotate=180]|20 & |[draw,fill=red!20,rotate=180]|21 \\
|[draw,rotate=-90]|3 & |[draw,fill=blue!20,rotate=180]|8 & |[draw,rotate=-90]|13 & |[draw,fill=yellow!20,rotate=180]|18 & |[draw,fill=red!20,rotate=180]|23 & |[draw,rotate=-90]|1 & |[draw,fill=blue!20,rotate=180]|10 & |[draw,rotate=-90]|11 & |[draw,fill=blue!20,rotate=180]|20 & |[draw,fill=red!20,rotate=180]|21 \\
|[draw,rotate=-90]|4 & |[draw,fill=red!20,rotate=180]|7 & |[draw,rotate=-90]|14 & |[draw,fill=red!20,rotate=180]|17 & |[draw,fill=blue!20,rotate=180]|24 & |[draw,rotate=-90]|1 & |[draw,fill=blue!20,rotate=180]|10 & |[draw,rotate=-90]|11 & |[draw,fill=blue!20,rotate=180]|20 & |[draw,fill=red!20,rotate=180]|21\\
|[draw,rotate=-90]|5 & |[draw,fill=red!20,rotate=180]|6 & |[draw,rotate=-90]|15 & |[draw,fill=blue!20,rotate=180]|16 & |[draw,fill=yellow!20,rotate=180]|25 & |[draw,rotate=-90]|1 & |[draw,fill=blue!20,rotate=180]|10 & |[draw,rotate=-90]|11 & |[draw,fill=blue!20,rotate=180]|20 & |[draw,fill=red!20,rotate=180]|21 \\
};

\end{tikzpicture}

\end{document}

Mi salida:

ingrese la descripción de la imagen aquí

¿Cómo puedo deshacerme de todos los espacios en blanco para que la rotación no arruine mi tablero?

Respuesta1

una solución para el problema básico se da enSigur comentario. Sin embargo, su código se puede simplificar y hacerlo más conciso mediante:

  • definiendo estilos por separado para cada columna. por esto todos los comandos locales para rotación y muchos para colores se vuelven superfluos
  • es mejor definir el estilo de los nodos en un solo lugar, como opciones dematrix
  • Dado que el contenido de los nodos son números, la prescripción de text depthdatos superfluos.
  • ser nodos cuadrados es suficiente para determinar el tamaño mínimo de los nodos

mwe resultante es entonces:

\documentclass{standalone}
%\usepackage[table]{xcolor}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usepackage{amsthm}

\begin{document}
    \begin{tikzpicture}
\matrix (m) [matrix of nodes,
             nodes={draw, line width=1pt,
                    minimum size=4ex, outer sep=0pt,
                    anchor=center},
             column sep=-1pt, row sep=-1pt,
             column 1/.style = {nodes={rotate=-90}},
             column 2/.style = {nodes={rotate=180}},
             column 3/.style = {nodes={rotate=-90}},
             column 4/.style = {nodes={rotate=180}},
             column 5/.style = {nodes={rotate=180}},
             column 6/.style = {nodes={rotate=-90}},
             column 7/.style = {nodes={fill=blue!20,rotate=180}},
             column 8/.style = {nodes={rotate=-90}},
             column 9/.style = {nodes={fill=blue!20,rotate=180}},
            column 10/.style = {nodes={fill=red!20,rotate=-90}},
            ]{
1 & |[fill=blue!20]|10 & 11 & |[fill=blue!20]|20   & |[fill=red!20]|21 & 3 & 10 & 31 & 23 & 21 \\
%
2 & |[fill=red!20]|9    & 12  & |[fill=red!20]|19    & |[fill=red!20]|22 & 1 & 10 & 11 & 20 & 21 \\
%
3 & |[fill=blue!20]|8   & 13  & |[fill=yellow!20]|18 & |[fill=red!20]|23 & 1 & 10 & 11 & 20 & 21 \\
%
4 & |[fill=red!20]|7    & 14  & & & & & 11 & 20 & 21 \\
%
5 & |[fill=red!20]|6    & 15  & & & & & 11 & 20 & 21 \\
%
4 & |[fill=red!20]|7    & 14  & & & & & 11 & 20 & 21 \\
%
5 & |[fill=red!20]|6    & 15  & & & & & 11 & 20 & 21 \\
%
3 & |[fill=blue!20]|8   & 13  & |[fill=yellow!20]|18 & |[fill=red!20]|23  & 1 & 10 & 11 & 20 & 21 \\
%
4 & |[fill=red!20]|7    & 14  & |[fill=red!20]|17    & |[fill=blue!20]|24 & 1 & 10 & 11 & 20 & 21 \\
%
5 & |[fill=red!20]|6 & 15 & |[fill=blue!20]|16 & |[fill=yellow!20]|25 & 1 & 10 & 11 & 20 & 21 \\
};
    \end{tikzpicture}

resultado es:

ingrese la descripción de la imagen aquí

Respuesta2

Descargo de responsabilidad: Todo el crédito para Sigur, quien resolvió el problema. Todo lo que hice fue hacer algunos ajustes adicionales menores. El problema principal se resuelve estableciendo anchor=center, como señala Sigur, ya que de lo contrario los centros de rotación no son los mismos. Los cambios menores están marcados en el código.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,matrix,shapes,positioning}
\usepackage{amsthm}
\usepackage{colortbl}
\begin{document}

\begin{tikzpicture}[element/.style={regular polygon,
regular polygon sides=4, %<- make sure that the nodes end up being quadratic
anchor=center,%<- Sigur
minimum width=1.75cm,
draw=black,line width=1pt,text height=2ex,text depth=0.25ex
}]
\matrix (m) [matrix of nodes,nodes={element},column sep=0cm, row sep=0cm, 
outer sep=0pt,inner sep=0,row sep=-1pt,column sep=-1pt]{%<- to have the same line width everywhere
|[draw,rotate=270]|1 & |[draw,fill=blue!20,rotate=180]|10 & |[draw,rotate=270]|11 & |[draw,fill=blue!20,rotate=180]|20 & |[draw,fill=red!20,rotate=180]|21 & |[draw,rotate=270]|3 & |[draw,fill=blue!20,rotate=180]|10 & |[draw,rotate=270]|31 & |[draw,fill=blue!20,rotate=180]|23 & |[draw,fill=red!20,rotate=180]|21 \\
|[draw,rotate=270]|2 & |[draw,fill=red!20,rotate=180]|9 & |[draw,rotate=270]|12 & |[draw,fill=red!20,rotate=180]|19 & |[draw,fill=red!20,rotate=180]|22 & |[draw,rotate=270]|1 & |[draw,fill=blue!20,rotate=180]|10 & |[draw,rotate=270]|11 & |[draw,fill=blue!20,rotate=180]|20 & |[draw,fill=red!20,rotate=180]|21 \\
|[draw,rotate=270]|3 & |[draw,fill=blue!20,rotate=180]|8 & |[draw,rotate=270]|13 & |[draw,fill=yellow!20,rotate=180]|18 & |[draw,fill=red!20,rotate=180]|23 & |[draw,rotate=270]|1 & |[draw,fill=blue!20,rotate=180]|10 & |[draw,rotate=270]|11 & |[draw,fill=blue!20,rotate=180]|20 & |[draw,fill=red!20,rotate=180]|21 \\
|[draw,rotate=270]|4 & |[draw,fill=red!20,rotate=180]|7 & |[draw,rotate=270]|14 & & & & & |[draw,rotate=270]|11 & |[draw,fill=blue!20,rotate=180]|20 & |[draw,fill=red!20,rotate=180]|21\\
|[draw,rotate=270]|5 & |[draw,fill=red!20,rotate=180]|6 & |[draw,rotate=270]|15 & & & & & |[draw,rotate=270]|11 & |[draw,fill=blue!20,rotate=180]|20 & |[draw,fill=red!20,rotate=180]|21 \\
|[draw,rotate=270]|4 & |[draw,fill=red!20,rotate=180]|7 & |[draw,rotate=270]|14 & & & & & |[draw,rotate=270]|11 & |[draw,fill=blue!20,rotate=180]|20 & |[draw,fill=red!20,rotate=180]|21\\
|[draw,rotate=270]|5 & |[draw,fill=red!20,rotate=180]|6 & |[draw,rotate=270]|15 & & & & & |[draw,rotate=270]|11 & |[draw,fill=blue!20,rotate=180]|20 & |[draw,fill=red!20,rotate=180]|21 \\
|[draw,rotate=270]|3 & |[draw,fill=blue!20,rotate=180]|8 & |[draw,rotate=270]|13 & |[draw,fill=yellow!20,rotate=180]|18 & |[draw,fill=red!20,rotate=180]|23 & |[draw,rotate=270]|1 & |[draw,fill=blue!20,rotate=180]|10 & |[draw,rotate=270]|11 & |[draw,fill=blue!20,rotate=180]|20 & |[draw,fill=red!20,rotate=180]|21 \\
|[draw,rotate=270]|4 & |[draw,fill=red!20,rotate=180]|7 & |[draw,rotate=270]|14 & |[draw,fill=red!20,rotate=180]|17 & |[draw,fill=blue!20,rotate=180]|24 & |[draw,rotate=270]|1 & |[draw,fill=blue!20,rotate=180]|10 & |[draw,rotate=270]|11 & |[draw,fill=blue!20,rotate=180]|20 & |[draw,fill=red!20,rotate=180]|21\\
|[draw,rotate=270]|5 & |[draw,fill=red!20,rotate=180]|6 & |[draw,rotate=270]|15 & |[draw,fill=blue!20,rotate=180]|16 & |[draw,fill=yellow!20,rotate=180]|25 & |[draw,rotate=270]|1 & |[draw,fill=blue!20,rotate=180]|10 & |[draw,rotate=270]|11 & |[draw,fill=blue!20,rotate=180]|20 & |[draw,fill=red!20,rotate=180]|21 \\
};
\end{tikzpicture}

\end{document}

ingrese la descripción de la imagen aquí

¡Feliz juego!

información relacionada