12

This question already has an answer here:

Recently, I have to work with some problems that require to draw table like below in LaTeX. I used to think about diagonal line inside a cell, but it's not a good choice for this problem since the texts are not in diagonal direction. Does anyone create something like this in LaTeX, can you suggest me any solution

sample table

marked as duplicate by Peter Jansson, Svend Tveskæg, Werner, Guido, Charles Stewart Jan 29 '14 at 20:39

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    Add your code (a minimal working example), it may be helpful and incite us to help. – Manuel Dec 14 '13 at 14:33
  • 1
    Not only do you have the diagonal lines, there seems to be no relationship between the column widths and the contents. For a one-off, you could probably reproduce it using Tikz. – John Kormylo Dec 14 '13 at 19:52
4

Update: See improved version in an own answer.


Here is a MWE of such a table.

\documentclass{minimal}
\usepackage{tikz}

\newlength{\csize}
\newlength{\cwidth}
\newlength{\clabel}

\newcommand{\cell}[1]% centers text in cell
{node[above right,minimum width=\csize, minimum height=\csize]{#1}}

\begin{document}

\setlength{\csize}{1.5\baselineskip}% cell size (note: \baselineskip depends on current font)
\settowidth{\clabel}{simple label}% label width
\addtolength{\clabel}{1em}
\setlength{\cwidth}{2\csize}% total width (2 cells)
\addtolength{\cwidth}{\clabel}

\begin{tikzpicture}
\path (0,0) node[above right,fill=yellow,minimum width=\cwidth, minimum height=\csize]{};
\draw% horizontal lines
 (0,0) -- (\cwidth,0)
 (0,\csize) -- (\cwidth,\csize)
 (0,2\csize) -- (\cwidth,2\csize);
\path% labels
 (0,0) node[above right]{left}
 (\clabel,0) node[above left]{right}
 (0,\csize) node[above right]{simple label};

\begin{scope}[xshift=\clabel]
\draw% vertical lines
 (0,0) -- (0,2\csize)
 (\csize,0) -- (\csize,2\csize)
 (2\csize,0) -- (2\csize,2\csize);
\path% fill cells
 (0,\csize) \cell{1}
 (\csize,\csize) \cell{2}
 (0,0) \cell{3}
 (\csize,0) \cell{4};
\end{scope}

\begin{scope}[xshift=\clabel, yshift=2\csize]
\draw% diagonal lines
 (0,0) -- ++(45:\clabel)
 (\csize,0) -- ++(45:\clabel)
 (2\csize,0) -- ++(45:\clabel);
\path% diagonal labels
 (\csize,0) node[above right,rotate=45]{first}
 (2\csize,0) node[above right,rotate=45]{second};
\end{scope}
\end{tikzpicture}
\end{document}

table

  • I tried using a \matrix, but the lines didn't quite match. – John Kormylo Dec 16 '13 at 17:56
  • BTW, I have an improved version now. Should I replace the above? – John Kormylo Dec 17 '13 at 19:21
  • Nobody noticed until now. Clear answer: Yes! If the change is big, then add the new code below the other and point to this better version before the older version. – Speravir Jan 29 '14 at 15:29
  • I'll see if I still have it. The idea was to put the origin in a common location (upper left corner of 1), – John Kormylo Jan 29 '14 at 18:07
11

Reproduction of the table without tikz:

\documentclass{article}
\usepackage[hmargin=20mm]{geometry}
\usepackage{xcolor}
\usepackage{graphicx}
\usepackage{colortbl}
\usepackage{array}
\usepackage{pifont}

\begin{document}
  \begingroup
    \renewcommand*{\arraystretch}{1.5}%
    \definecolor{tabred}{RGB}{230,36,0}%
    \definecolor{tabgreen}{RGB}{0,116,21}%
    \definecolor{taborange}{RGB}{255,124,0}%
    \definecolor{tabbrown}{RGB}{171,70,0}%
    \definecolor{tabyellow}{RGB}{255,253,169}%
    \newcommand*{\redtriangle}{\textcolor{tabred}{\ding{115}}}%
    \newcommand*{\greenbullet}{\textcolor{tabgreen}{\ding{108}}}%
    \newcommand*{\orangecirc}{\textcolor{taborange}{\ding{109}}}%
    \newcommand*{\headformat}[1]{{\small#1}}%
    \newcommand*{\vcorr}{%
      \vadjust{\vspace{-\dp\csname @arstrutbox\endcsname}}%
      \global\let\vcorr\relax
    }%
    \newcommand*{\HeadAux}[1]{%
      \multicolumn{1}{@{}r@{}}{%
        \vcorr
        \sbox0{\headformat{\strut #1}}%
        \sbox2{\headformat{Complex Data Movement}}%
        \sbox4{\kern\tabcolsep\redtriangle\kern\tabcolsep}%
        \sbox6{\rotatebox{45}{\rule{0pt}{\dimexpr\ht0+\dp0\relax}}}%
        \sbox0{\raisebox{.5\dimexpr\dp0-\ht0\relax}[0pt][0pt]{\unhcopy0}}%
        \kern.75\wd4 %
        \rlap{%
          \raisebox{.25\wd4}{\rotatebox{45}{\unhcopy0}}%
        }%
        \kern.25\wd4 %
        \ifx\HeadLine Y%
          \dimen0=\dimexpr\wd2+.5\wd4\relax
          \rlap{\rotatebox{45}{\hbox{\vrule width\dimen0 height .4pt}}}%
        \fi
      }%
    }%
    \newcommand*{\head}[1]{\HeadAux{\global\let\HeadLine=Y#1}}%
    \newcommand*{\headNoLine}[1]{\HeadAux{\global\let\HeadLine=N#1}}%
    \noindent
    \begin{tabular}{%
      >{\bfseries}lc|>{\quad}c
      *{4}{c|}c>{\quad}c
      *{4}{c|}c>{\quad}c
      *{2}{c|}c%
    }%
      &
      \head{Data Dimensions} &
      &
      \head{Single Input/Output} &
      \head{Statc Rates} &
      \head{Hierachical Memory} &
      \head{Complex Data Movement} &
      \headNoLine{Single Kernel Execution} &
      &
      \head{Application graph} &
      \head{Implicit memory access} &
      \head{Theoretical Framework} &
      \head{Out-of-band control} &
      \headNoLine{Real-time constraints} &
      &
      \head{Data Parallelism} &
      \head{Pipeline Parallelism} &
      \headNoLine{Task Parallelism}
      \\
      \sbox0{S}%
      \rule{0pt}{\dimexpr\ht0 + 2ex\relax}%
      StreamIt & \textcolor{tabred}{\bfseries 1} &&
      \redtriangle & \redtriangle & & & &&
      \greenbullet & \greenbullet & \orangecirc & \greenbullet & &&
      \greenbullet & \greenbullet & \greenbullet
      \\\hline
      StreamC/KernelC & \textcolor{tabred}{\bfseries 1} &&
      & & & & \redtriangle &&
      \greenbullet & \greenbullet & & \greenbullet & &&
      \greenbullet & &
      \\\hline
      SDF & \textcolor{tabred}{\bfseries 1} &&
      & \redtriangle & & & &&
      \greenbullet & \greenbullet & \greenbullet & & &&
      & \greenbullet & \greenbullet
      \\\hline
      MDSDF & \textcolor{tabgreen}{\bfseries\itshape n} &&
      & \redtriangle & & \redtriangle & &&
      \greenbullet & \greenbullet & \greenbullet & & &&
      \greenbullet & \greenbullet & \greenbullet
      \\\hline
      ArrayOL & \textcolor{tabgreen}{\bfseries\itshape n} &&
      & \redtriangle & & \redtriangle & &&
      \greenbullet & \greenbullet & \orangecirc & & &&
      \greenbullet & \greenbullet & \greenbullet
      \\\hline
      Brook & \textcolor{tabgreen}{\bfseries\itshape n} &&
      & & & & \redtriangle &&
      & \greenbullet & & & &&
      \greenbullet & &
      \\\hline
      Sequoia & \textcolor{tabgreen}{\bfseries\itshape n} &&
      & & \redtriangle & \redtriangle & \redtriangle &&
      & & & & &&
      \greenbullet & &
      \\\hline
      \rowcolor{tabyellow}%
      Block-parallel & \textcolor{tabbrown}{\bfseries 2} &&
      & \redtriangle & & & &&
      \greenbullet & \greenbullet & \orangecirc & \greenbullet &
        \greenbullet &&
      \greenbullet & \greenbullet & \greenbullet
      \\[.5ex]
      \multicolumn{3}{c}{} &
      \multicolumn{5}{c}{\bfseries Limitations} &&
      \multicolumn{5}{c}{\bfseries Features} &&
      \multicolumn{3}{c}{\bfseries Parallelism}
      \\
    \end{tabular}%
    \kern19.5mm % manually with the help of the next \vrule
    % \vrule height 50mm
  \endgroup
\end{document}

Result

Remarks:

  • The color values are taken from the image.
  • The symbols come from the symbol font Zapf Dingbats. \ding of package pifont access these symbols.
  • The background color of the last table line is done by \rowcolor of package colortbl.
  • The rotation is done with \rotatebox of the graphics (graphicx) package.
  • The depth of the head line row is empty, therefore the vertical line would be missing. This is fixed by moving the head line down with \vcorr until the rotated lines hits the vertical column lines.
  • The value of the \kern after the end of the table is set manually with the help of the following rule. The white space by \kern notifies LaTeX that the table is larger than it thinks because of the overlap of the rotated headers.
1

Here is the improved version (common scope).

\documentclass{minimal}
\usepackage{amssymb}
\usepackage{tikz}

\usetikzlibrary{calc}

% create symbols

\newcommand{\reddot}{\tikz{\fill[red] (0,0) circle (4pt);}}
\newcommand{\greentriangle}{\tikz{\fill[green] (0,0) -- (4.62pt,8pt) -- (9.23pt,0) -- cycle;}}
\newcommand{\bigx}{\tikz{\draw[black,thick] (0,0) -- (7pt,7pt) (0,7pt) -- (7pt,0);}}

\newlength{\csize}
\newlength{\clabel}
\newlength{\cwidth}

\newcommand{\cell}[1]% centers text in cell
{node[above right,minimum width=\csize, minimum height=\csize]{#1}}

\begin{document}

test \reddot \greentriangle \bigx \checkmark $\bigstar$

\setlength{\csize}{1.5\baselineskip}% cell size (note: \baselineskip depends on current font)
\addtolength{\csize}{.6666em}
\settowidth{\clabel}{longest label}% label width
\addtolength{\clabel}{.6666em}
\setlength{\cwidth}{2\csize}% total width
\addtolength{\cwidth}{\clabel}

\begin{tikzpicture}
\path (-\clabel,-2\csize) node[above right,fill=yellow,minimum width=\cwidth, minimum height=\csize]{};
\draw% horizontal lines
 (-\clabel,0) -- (2\csize,0)
 (-\clabel,-\csize) -- (2\csize,-\csize)
 (-\clabel,-2\csize) -- (2\csize,-2\csize);
\path% labels
 (-\clabel,-2\csize) node[above right]{left}
 (0,-2\csize) node[above left]{right}
 (-0.5\clabel,-\csize) node[above]{center};
\draw% vertical lines
 (0,0) -- (0,-2\csize)
 (\csize,0) -- (\csize,-2\csize)
 (2\csize,0) -- (2\csize,-2\csize);
\path% fill cells
 (0,-\csize) \cell{1}
 (\csize,-\csize) \cell{2}
 (0,-2\csize) \cell{3}
 (\csize,-2\csize) \cell{4};
\draw% diagonal lines
 (0,0) -- ++(45:\clabel)
 (\csize,0) -- ++(45:\clabel)
 (2\csize,0) -- ++(45:\clabel);
\path% diagonal labels
 (\csize,0) node[above right,rotate=45]{first}
 (2\csize,0) node[above right,rotate=45]{second};
\end{tikzpicture}
\end{document}

table

  • 1
    Just as remark: Why should the minimal class be avoided?. – Speravir Jan 29 '14 at 18:19
  • A lot of standard latex features are not defined. Back when I wrote this, I was planning to replace article with minimal on everything, but I started getting odd errors so I went back to article. – John Kormylo Jan 29 '14 at 18:25
  • Nope, I see clearly \documentclass{minimal}, BTW already in the older version. – Speravir Jan 29 '14 at 18:32
  • They were both written at the same time (more or less). – John Kormylo Jan 29 '14 at 18:36

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