직사각형 Tikz 내의 노드 위치 지정

직사각형 Tikz 내의 노드 위치 지정

팬텀을 사용하지 않고 어떻게 텍스트를 아래에서 위로 배치할 수 있습니까?

\documentclass{article}
\usepackage{tikz}

\begin{document}

 \def\n{.5}
 \definecolor{aqua}{rgb}{0.0, 1.0, 1.0}
 \definecolor{carnationpink}{rgb}{1.0, 0.65, 0.79}

 \begin{tikzpicture}
  %%%Ones Value
 \foreach \x/\xtext in {1/\textcolor{black} 
 {hundreds\phantom{xxxx}},2/\textcolor{black} 
 {tens},3/\textcolor{blue}{ones}}
 \draw[xshift=.5*\x cm,fill=aqua] (0,.5) rectangle (\n,3.5) node[midway, 
    rotate=90,text=blue] {\textbf{\xtext}};
 \foreach \x/\d in {1/3,2/6,3/4}
 \draw[xshift=.5*\x cm,fill=aqua] (0,0) rectangle (\n,\n) node[pos=.5] 
 {$\d$};
 %%%Thousands
  \foreach \x/\xtext in {0/\textcolor{black} 
   {Thousands\phantom{xxxx}},1/\textcolor{black}{Ten Thousands\phantom{x}}}
  \draw[xshift=-.5*\x cm,fill=carnationpink] (0,.5) rectangle (\n,3.5) 
    node[midway, rotate=90,text=blue] {\textbf{\xtext}};
 \foreach \x/\d in {0/,1/}
 \draw[xshift=-.5*\x cm,fill=carnationpink] (0,0) rectangle (\n,\n) node[pos=.5] {$\d$};
 \end{tikzpicture}
 \end{document}

이는 다음을 출력합니다: 여기에 이미지 설명을 입력하세요

답변1

행렬을 사용하는 경우 text width. 노드의 너비는 가장 넓은 항목에 맞게 조정됩니다.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,backgrounds}
\begin{document}
\definecolor{aqua}{rgb}{0.0, 1.0, 1.0}
\definecolor{carnationpink}{rgb}{1.0, 0.65, 0.79}

\begin{tikzpicture}
\matrix [matrix of nodes,nodes in empty cells,draw,
 row 1/.style={nodes={rotate=90,anchor=west,font=\bfseries}}] (mat)
{
 Ten Thousands & Thousands & hundreds & tens & |[text=blue]| ones\\
  &  & 3 & 6 & 4 \\
  };
  \foreach \X [count=\Y] in {2,...,5}
  {\path (mat-1-\Y.center) -- (mat-1-\X.center) coordinate[midway] (h-\Y);
  \draw (h-\Y|-mat.south) -- (h-\Y|-mat.north);}
  \draw (mat-2-5.north -|mat.west) -- (mat-2-5.north -|mat.east);
  \begin{scope}[on background layer]
   \fill[carnationpink] (h-2|-mat.south) rectangle (mat.north west); 
   \fill[aqua] (h-2|-mat.south) rectangle (mat.north east); 
  \end{scope}
\end{tikzpicture}
\end{document}

여기에 이미지 설명을 입력하세요

아니면 수백만 명과 함께.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,backgrounds}
\begin{document}
\definecolor{aqua}{rgb}{0.0, 1.0, 1.0}
\definecolor{carnationpink}{rgb}{1.0, 0.65, 0.79}

\begin{tikzpicture}
\matrix [matrix of nodes,nodes in empty cells,draw,
 row 1/.style={nodes={rotate=90,anchor=west,font=\bfseries,text
 height=2.5ex,text depth=0.25ex}}] (mat)
{
Ten Millions & Millions & Hundred Thousands & Ten Thousands & Thousands & hundreds & tens & |[text=blue]| ones\\
 & & &  &  & 3 & 6 & 4 \\
  };
  \foreach \X [count=\Y] in {2,...,8}
  {\path (mat-1-\Y.center) -- (mat-1-\X.center) coordinate[midway] (h-\Y);
  \draw (h-\Y|-mat.south) -- (h-\Y|-mat.north);}
  \draw (mat-2-8.north -|mat.west) -- (mat-2-8.north -|mat.east);
  \begin{scope}[on background layer]
   \fill[aqua] (h-5|-mat.south) rectangle (mat.north east); 
   \fill[carnationpink] (h-5|-mat.south) rectangle (h-2|-mat.north east); 
   \fill[yellow] (h-2|-mat.south) rectangle (mat.north west); 
  \end{scope}
\end{tikzpicture}
\end{document}

여기에 이미지 설명을 입력하세요

답변2

이와 같이?

여기에 이미지 설명을 입력하세요

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{chains, positioning}   % <--- new

\begin{document}
\def\n{.5}
\definecolor{aqua}{rgb}{0.0, 1.0, 1.0}
    \begin{tikzpicture}[
node distance = 0pt,                    % <--- new
  start chain = A going above,          % <--- new 
   box/.style = {draw, fill=aqua, text width=#1, minimum height=6mm,
                 outer sep=0pt, rotate=90, on chain},  % <--- new
 box/.default = 35mm
                        ]
\node[box, text=blue]   {ones};         % A-1
\node[box]              {hundreds};
\node[box]              {thousands};    % A-3 
\foreach \i in {1,2,3}
\node[box=6mm, fill=red!30, left=of A-\i] {};
    \end{tikzpicture}
\end{document}

부록: 업데이트된 질문을 고려하면 첫 번째 솔루션을 다음과 같이 변경해야 합니다.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{chains, positioning}   % <--- new

\begin{document}
\definecolor{aqua}{rgb}{0.0, 1.0, 1.0}
\definecolor{carnationpink}{rgb}{1.0, 0.65, 0.79}
    \begin{tikzpicture}[
node distance = 0pt,                        % <--- new
  start chain = A going below,              % <--- new
  bbox/.style = {draw, fill=#1, text width=24mm,
                 minimum height=6mm, outer sep=0pt,
                 rotate=90, on chain},      % <--- new
  sbox/.style = {draw, fill=#1, text width=3mm, align=center,   % <--- new
                 minimum height=6mm, outer sep=0pt,             % <--- new
                 rotate=90, on chain}                           % <--- new
                        ]
\node[bbox=carnationpink]   {Ten Thousands};    % A-1
\node[bbox=carnationpink]   {Thousands};
\node[bbox=aqua]            {hundreds};
\node[bbox=aqua]            {tens};
\node[bbox=aqua, text=blue] {ones};             % A-5
\foreach \i/\j [count=\k] in {carnationpink/ , carnationpink/ , aqua/3, aqua/6, aqua/4}
\node[sbox=\i, left=of A-\k] {\rotatebox{-90}{\j}};                        ]
    \end{tikzpicture}
\end{document}

이는 다음을 제공합니다:

여기에 이미지 설명을 입력하세요

답변3

에서는 어렵지 않습니다 node[right,rotate=90]. right이미 d이기 때문에 사용한다는 점에 유의하세요 rotate. 대신 사용해보면 그 이유를 알 수 있습니다 above.

이 간단한 방법을 사용하면 직사각형의 크기가 일정하게 유지되고 텍스트가 중앙에 위치하게 됩니다.

\documentclass[tikz,margin=3mm]{standalone}
\definecolor{aqua}{rgb}{0.0, 1.0, 1.0}
\definecolor{carnationpink}{rgb}{1.0, 0.65, 0.79}
\begin{document}
\begin{tikzpicture}[scale=0.75]
\fill[carnationpink] (0,0) rectangle (2,5);
\fill[aqua] (2,0) rectangle (5,5);
\draw (0,0) grid (5,1);
\foreach \i in {0,...,4} \draw (\i,1) rectangle (\i+1,5);
\node at (2.5,.5) {3};
\node at (3.5,.5) {6};
\node at (4.5,.5) {4};
\draw (.5,1) node[right,rotate=90] {ten thousands};
\draw (1.5,1) node[right,rotate=90] {thousands};
\draw (2.5,1) node[right,rotate=90] {hundreds};
\draw (3.5,1) node[right,rotate=90] {tens};
\draw[blue] (4.5,1) node[right,rotate=90] {ones};
\end{tikzpicture}
\end{document}

여기에 이미지 설명을 입력하세요

답변4

tikz이런 종류의 테이블을 만드는 데 사용할 필요가 없습니다 . 환경 을 사용하는 것이 훨씬 쉽습니다 tabular.

\documentclass{article}
\usepackage{tikz}
\usepackage{colortbl}
\begin{document}

 \def\n{.5}
 \definecolor{aqua}{rgb}{0.0, 1.0, 1.0}
 \definecolor{carnationpink}{rgb}{1.0, 0.65, 0.79}

\def\angle{90}
\begin{tabular}{*{2}{|>{\cellcolor{carnationpink}}l}*{3}{|>{\cellcolor{aqua}}l}|}
\hline
 \rotatebox{\angle}{Ten thousands } &  \rotatebox{\angle}{Thousands} & \rotatebox{\angle}{hundreds }    &    \rotatebox{\angle}{tens}   &  \rotatebox{\angle}{ones}  \\
\hline
 & & 3&6 & 4\\\hline
 & & & & \\\hline
\end{tabular}
\end{document}

스크린샷

관련 정보