3

Without using phantom how can I place the text starting from the bottom up?

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

This outputs: enter image description here

  • Consider accepting one of the provided answers. They all seem to adequately address your problem. – Dr. Manuel Kuehner Feb 28 at 11:07
4

If you use a matrix, you do not have to hard code the text width. The width of the nodes will adjust to the widest entry.

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

enter image description here

Or with Millions.

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

enter image description here

  • I want to add another column yellow (millions) . I will ask as a separate question. – MathScholar Feb 28 at 14:38
  • @MathScholar No need, I added Millions. – user121799 Feb 28 at 14:56
4

like this?

enter image description here

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

addadendum: considering updated question, the first solution should be changed to:

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

which gives:

enter image description here

  • @MathScholar, you are welcome! i slightly change answer: to node style i add outer sep=0pt, which allows the lines between the boxes to overlap (looks thinner). – Zarko Feb 28 at 1:44
  • no, you only need to add fill=red!25 to boxes drawn in a loop. i will add this to answer asap. – Zarko Feb 28 at 1:59
  • 2
    you should clarify your question, now i'm lost in your comments. if each box >(node) has own color, than is sensible to change code, i.e. introduce new parameter for coloring. – Zarko Feb 28 at 2:21
  • I want to thank you for your answers and time. The number are still rotated. Nevertheless there is helpful content here. There was also a question you helped me much in the past! – MathScholar Feb 28 at 23:27
  • @MathScholar, i forgot on this. you only need to rotate numbers with \rotatebox{-90}{\j}. see edited answer. – Zarko Feb 28 at 23:33
3

It is not difficult with node[right,rotate=90]. Note that we use right because it is already rotated. You can see why when you use above instead.

This simple way will ensure a consistent size of the rectangles and the texts are at the middle.

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

enter image description here

3

There is no need to use tikz to make these kinds of tables. It is much easier to use the tabular environment.

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

screenshot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.