Позиционирование текста узла работает неправильно

Позиционирование текста узла работает неправильно

Мне нужно иметь два блока размером с больший блок, включив «текст» внутри каждого из них несколько раз (разный для каждого из них).

Когда я пишу следующий код, он дает мне результат, показанный ниже (текст появляется за пределами поля и не в желаемом количестве повторений).

Кто-нибудь может помочь?

Спасибо

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

Вот ссылка на рисунок, так как загрузить его у меня не получается: https://drive.google.com/file/d/1e_bcgi96F45zsaeAd0kYY96fpe53mAR4/view?usp=sharing

решение1

Проблема в том, что не следует вкладывать TiкZ картинки, и здесь в этом тоже нет необходимости.

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

введите описание изображения здесь

решение2

Неясно, нужно ли вам использовать Tikz. Если нет, вы можете использовать tcolorboxи построить результат с помощью 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}

введите описание изображения здесь

Связанный контент