1

I need to write very long table (128 rows x 64 columns), with different colors in a rows. Also it have to have "color in color" within one row, so it can be interpreted as one row consists of several subsets, each smaller than previous.

I started writing it, but seams the way I'm using takes a lot of time. The problem is to alight numbers in the row. Right now I'm doing it manually by adding spaces between numbers (and the number of spaces I have to add is not the same all the time). The example in latex is below.

I'm wondering is there any other way how to achieve it (to have colors in rows as I've already done in my example)? But without using manual way of aligning the numbers vertically?

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage[dvipsnames]{xcolor}
\usepackage[cmex10]{amsmath}
\usepackage{array}

\begin{document}

\begin{table*}
\caption{Integer approximation of the HEVC's DCT. Smaller sizes are embedded in the higher order matrix.}
\begin{center}
\begin{tabular}{l}
\setlength{\fboxsep}{0pt}\colorbox{GreenYellow}{
    \setlength{\fboxsep}{1.1pt}\colorbox{WildStrawberry}{\setlength{\fboxsep}{1.05pt}\colorbox{Yellow}{\colorbox{Turquoise}{64\:\:\:64\:\:\:64\:\:\:64}\:\:\:64\:\:\:64\:\:\:64\:\:\:64}\:\:\:64\:\:\:64\:\:\:64\:\:\:64\:\:\:64\:\:\:64\:\:\:64\:\:\:64}\:\:\:64\:\:\:64\:\:\:64\:\:\:64\:\:\:64\:\:\:64\:\:\:64\:\:\:64\:\:\:64\:\:\:64\:\:\:64\:\:\:64\:\:\:64\:\:\:64\:\:\:64\:\:\:64} \\

\setlength{\fboxsep}{0pt}\colorbox{GreenYellow}{
    \setlength{\fboxsep}{1.1pt}\colorbox{GreenYellow}{\setlength{\fboxsep}{1.05pt}\colorbox{GreenYellow}{\colorbox{GreenYellow}{90\:\:\:90\:\:\:88\:\:\:85}\:\:\:82\:\:\:78\:\:\:73\:\:\:67}\:\:\:61\:\:\:54\:\:\:46\:\:\:38\:\:\:31\:\:\:22\:\:\:13\:\:\:\:\:4}\:\:\:\:-4\:\,-13\:-22\:\:-31\:-38\:\:-46\:-54\:\:-61\:-67\:\:-73\:-78\:\:-82\:-85\:\:\:88\:\:-90\:-90} \\

\setlength{\fboxsep}{0pt}\colorbox{GreenYellow}{
    \setlength{\fboxsep}{1.1pt}\colorbox{WildStrawberry}{\setlength{\fboxsep}{1.05pt}\colorbox{WildStrawberry}{\colorbox{WildStrawberry}{90\:\:\:87\:\:\:80\:\:\:70}\:\:\:57\:\:\:43\:\:\:25\:\:\:\:\:9}\:\:\:\:-9\:\,-25\:-43\:\:-57\:-70\:\:-80\:\:-87\:-90}\:-90\:\:-87\:-80\:\:-70\:-57\:\:-43\:-25\:\:\:\:-9\:\:\:\:\:9\:\:\:25\:\:\:43\:\:\:57\:\:\:70\:\:\:80\:\:\:87\:\:\:90} \\

\setlength{\fboxsep}{0pt}\colorbox{GreenYellow}{
    \setlength{\fboxsep}{1.1pt}\colorbox{GreenYellow}{\setlength{\fboxsep}{1.05pt}\colorbox{GreenYellow}{\colorbox{GreenYellow}{90\:\:\:82\:\:\:67\:\:\:46}\:\:\:22\:\:\:-4\:\:-31\:-54}\:\:-73\:\:-85\:-90\:\:-88\:-78\:\:-61\:\:-38\:-13}\:\:\:13\:\:\:38\:\:\:61\:\:\:78\:\:88\:\:\:\:90\:\:85\:\:\:73\:\:\:54\:\:\:\:31\:\:\:\:4\:\:-22\:\:-46\:-67\:\:-82\:-90} \\

\setlength{\fboxsep}{0pt}\colorbox{GreenYellow}{
    \setlength{\fboxsep}{1.1pt}\colorbox{WildStrawberry}{\setlength{\fboxsep}{1.05pt}\colorbox{Yellow}{\colorbox{Yellow}{89\:\:\:75\:\:\:50\:\:\:18}\:-18\:\:-50\:-75\:-89}\:\:-89\:\:-75\:-50\:\:-18\:\:\:18\:\:\:50\:\:\:\:75\:\:89}\:\:\:89\:\:\:75\:\:\:50\:\:\:18\:-18\:\:-50\:-75\:-89\:\:-89\:\:-75\:\:-50\:-18\:\:\:18\:\:\:50\:\:\:75\:\:\:89} \\

\setlength{\fboxsep}{0pt}\colorbox{GreenYellow}{
    \setlength{\fboxsep}{1.1pt}\colorbox{GreenYellow}{\setlength{\fboxsep}{1.05pt}\colorbox{GreenYellow}{\colorbox{GreenYellow}{88\:\:\:67\:\:\:31\:\:-13}\:-54\:\:-82\:-90\:-78}\:\:-46\:\:\:-4\:\:\:38\:\:\:\:73\:\:\:90\:\:\:85\:\:\:\:61\:\:22}\:-22\:\:-61\:-85\:\:-90\:-73\:\:-38\:\:\:\:4\:\:\:46\:\:\:78\:\:\:\:90\:\:\:82\:\:\:54\:\:\:13\:\:-31\:-67\:-88}
\end{tabular}
\end{center}
\end{table*}

\end{document}

An example of what I want to accomplish is in the image below. Please note that one color goes around other, making impression that box is inside box. This is just a part of the table. It has more rows and columns, but the color boxes are important to me now. Example

  • use tabular to align the numbers and \rowcolor (colortbl package) to colour the rows. – David Carlisle Jan 16 at 18:35
  • Could you provide me with an example using my code? I would appreciate very much since I tried a lot of different things and nothing worked. – MilosR. Jan 16 at 18:37
  • welcome to tex.se! please extend your code snipet to complete small document beginning with \documentclass... and ending with \end{document} with your table, which we can test as it is. so far you have errors in your code. also from code is difficult to see, what you like to obtain. can you provide a sketch? – Zarko Jan 16 at 18:41
  • @MilosRadosavljevic: Would a result like the following be sufficient or do you really need the style of a box inside of another colored box? i.stack.imgur.com/9yOZD.png – leandriis Jan 16 at 18:48
  • only partly. you have defined colors in preamble, which is unknown to us. also are missed $. from image i conclude, that you need to define more columns (as many as you have numbers) ... – Zarko Jan 16 at 18:52
2

How about a tikz matrix solution using the background and fit libraries?

\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{backgrounds,fit,matrix}
\begin{document}
\begin{tikzpicture}[outer sep=0pt,inner sep=1.5pt]
  \matrix [matrix of math nodes,
           column sep=7pt, row sep=7pt,
           nodes={anchor=east}] (m)
  {
    64 & 64 & 64 & 64 & 64 & 64 & 64 & 64 & 64 & 64 \\
    90 & 88 & 83 & 73 & 61 & 46 & 31 & 4 & -3 & -22 \\
    90 & 80 & 57 & 25 & -9 & -43 & -70 & -87 & -90 & -80 \\
    90 & 67 & 22 & -31 & -73 & -90 & -78 & -38 & 13 & 61 \\
    89 & 50 & -18 & -75 & -89 & -50 & 18 & 75 & 89 & 50 \\
  };
  \begin{scope}[on background layer]
    \node[fill=GreenYellow,inner sep=4.5pt,fit=(m-1-1) (m-5-10)] {};
    \node[fill=WildStrawberry,inner sep=3pt,fit=(m-1-1) (m-1-8)] {};
    \node[fill=Yellow,inner sep=1.5pt,fit=(m-1-1) (m-1-4)] {};
    \node[fill=Turquoise,inner sep=0pt,fit=(m-1-1) (m-1-2)] {};
    \node[fill=WildStrawberry,inner sep=3pt,fit=(m-3-1) (m-3-8)] {};
    \node[fill=WildStrawberry,inner sep=3pt,fit=(m-5-1) (m-5-8)] {};
    \node[fill=Yellow,inner sep=1.5pt,fit=(m-5-1) (m-5-4)] {};
  \end{scope}
\end{tikzpicture}
\end{document}

output

  • That is what I was looking for. Now just to figure out how to reduce spaces between rows and columns. Thank you. – MilosR. Jan 17 at 15:25
  • Do you know how to reduce the spaces between all rows and columns? When I column sep to 2pt, it does not apply to all columns. – MilosR. Jan 17 at 15:51
  • Actualy I figured out. Just have to add negative number to column sep. For example: row sep=2pt, column sep=-2pt. – MilosR. Jan 17 at 17:48
3

showed image i can reproduce with the following mwe (minimal working example):

\documentclass{article}
\usepackage[table, dvipsnames]{xcolor}
\usepackage[skip=1ex]{caption}

\begin{document}
    \begin{table}[htb]
\caption{Integer approximation of the HEVC's 32-point DCT. Smaller sizes of 16-point, 8-point, and 4-point DCT are embedded in the 32-point matrix.}
\label{tab:DCTMAtrix1}
    \centering
\begin{tabular}{ *{6}{c} }
    \rowcolor{olive!60}
64  & 64 & \cellcolor{red}{64}
             & \cellcolor{red}{64}
                   & \cellcolor{yellow}{64}
                       & 64                 \\
    \rowcolor{olive!60}
64 & 64 & 64 & 64 & 64 & 64
\end{tabular}
\end{table}
\end{document}

enter image description here

however, i really doubt, that it is possible to squeeze in text width a table with 88 columns even if you table rotate in landscape orientation.

  • That does not show the requested result, as the colors cover the whole cell while should be smaller and show the background image of the outer color group. Also, please use proper capitalization. – Martin Scharrer Jan 17 at 10:28
  • @MartinScharrer Exactly. It is not the same compared to what I need. – MilosR. Jan 17 at 10:50

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.