
Necesito tener dos cuadros del tamaño del más grande, incluyendo el "texto" dentro de cada uno de ellos un número de veces (diferente para cada uno de ellos).
Cuando escribo el siguiente código me da el resultado que se muestra a continuación (el texto aparece fuera del cuadro y no en el número deseado de repeticiones).
¿Alguien puede ayudar?
Gracias
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{fit}
\newbox\mybox
\def\mysaver{%
\pgfmathparse{\pgfpositionnodelatermaxx-\pgfpositionnodelaterminx}%
\xdef\nodeW{\pgfmathresult pt}%
\pgfmathparse{\pgfpositionnodelatermaxy-\pgfpositionnodelaterminy}%
\xdef\nodeH{\pgfmathresult pt}%
}
\begin{document}
\begin{tikzpicture}
\begin{scope}
{\pgfpositionnodelater{\mysaver}
% This node is clearly outside the grid
\node [inner sep=0] {Text};}
\node (a)
[draw,rounded corners=6pt,rectangle,inner sep=0.4cm]
{
\tikz{
\foreach \x in {0,\nodeW+0.2cm,\nodeW*2+0.2cm*2,\nodeW*3+0.2cm*3,\nodeW*4+0.2cm*4}
\foreach \y in {0,\nodeH+0.2cm,\nodeH*2+0.2cm*2,\nodeH*3+0.2cm*3}
\node [inner sep=0] at (\x,\y) {Text};
\node [inner sep=0] at (\nodeW*2+0.2cm*2,\nodeH*4+0.2cm*4) {Text};
}
};
\node (b) [right=0.4cm of a,inner sep=0] {Text Text};
{\pgfpositionnodelater{\mysaver}
% This node is clearly outside the grid
\node [inner sep=0] {Text};}
\node (c) [fit=(a),right=0.4cm of b,draw,rounded corners=6pt,rectangle,inner sep=0]
{
\tikz{
\foreach \x in {0,\nodeW+0.2cm}
\foreach \y in {0,\nodeH+0.2cm,\nodeH*2+0.2cm*2}
\node [inner sep=0] at (\x,\y) {Text};
}
};
\end{scope}
\end{tikzpicture}
\end{document}
Aquí hay un enlace a la figura ya que cargarla no funciona conmigo: https://drive.google.com/file/d/1e_bcgi96F45zsaeAd0kYY96fpe53mAR4/view?usp=sharing
Respuesta1
El problema es que no se debe anidar TikZ imágenes, y aquí tampoco hay necesidad de esto.
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{fit,calc}
\newbox\mybox
\def\mysaver{%
\pgfmathparse{\pgfpositionnodelatermaxx-\pgfpositionnodelaterminx}%
\xdef\nodeW{\pgfmathresult pt}%
\pgfmathparse{\pgfpositionnodelatermaxy-\pgfpositionnodelaterminy}%
\xdef\nodeH{\pgfmathresult pt}%
}
\begin{document}
\begin{tikzpicture}
\begin{scope}
{\pgfpositionnodelater{\mysaver}
% This node is clearly outside the grid
\node [inner sep=0] {Text};}
\node (a)
[draw,rounded corners=6pt,rectangle,inner sep=0.4cm]
{
\tikz{
\foreach \x in {0,\nodeW+0.2cm,\nodeW*2+0.2cm*2,\nodeW*3+0.2cm*3,\nodeW*4+0.2cm*4}
\foreach \y in {0,\nodeH+0.2cm,\nodeH*2+0.2cm*2,\nodeH*3+0.2cm*3}
\node [inner sep=0] at (\x,\y) {Text};
\node [inner sep=0] at (\nodeW*2+0.2cm*2,\nodeH*4+0.2cm*4) {Text};
}
};
\node (b) [right=0.4cm of a,inner sep=0] {Text Text};
{\pgfpositionnodelater{\mysaver}
% This node is clearly outside the grid
\node [inner sep=0] {Text};}
\node (c) [fit=(a),right=0.4cm of b,draw,rounded corners=6pt,rectangle,inner sep=0]
{
};
\foreach \x in {0,\nodeW+0.2cm}
\foreach \y in {0,\nodeH+0.2cm,\nodeH*2+0.2cm*2}
\node [inner sep=0] at ($(c.center)+(\x,\y)$) {Text};
\end{scope}
\end{tikzpicture}
\end{document}
Respuesta2
No está claro si es necesario utilizar Tikz
. De lo contrario, puede usar tcolorbox
y generar el resultado con equal height group
:
\documentclass{article}
\usepackage[most]{tcolorbox}
\newtcolorbox{mybox}[1][]{%
notitle,
equal height group=MyGroup,
before=,
after=\hfill,
valign=center,
#1}
\begin{document}
\begin{mybox}[width=.4\linewidth]
Text\\ Text Text Text Text\\
Text Text Text Text\\
Text Text Text Text\\
\end{mybox}
%
\begin{mybox}[blanker, width=15mm]
Text Text
\end{mybox}
%
\begin{mybox}[width=.3\linewidth]
Text Text\\
Text Text
\end{mybox}
\end{document}