8

Is it possible to create a table with a layout as this one?

enter image description here

If yes, what packages should I use?

  • 1
    Welcome to TeX.SX! You can have a look on our starter guide to familiarize yourself further with our format. – jubobs May 28 '13 at 8:22
  • 3
    Yes it is possible. What type of syntax would like? What have you tried yourself? On the other hand do you really want tables with such poor layout: see the disucssion in booktabs documentation on designing tables. – Andrew Swann May 28 '13 at 8:24
  • Hi. I didn't really understand the question about the syntax. What do you mean? My goal is to create a table with custom format as shown in the figure. At the moment I am inserting this as images. Perhaps the easiest way is to include the figure but label it as a table? Like to create a table with a single cell that contains the figure?? – Eugen May 28 '13 at 8:44
  • By "syntax" I meant what type form of input would you like to use. – Andrew Swann May 28 '13 at 9:11
  • I guess it would be 'table' environment. – Eugen May 28 '13 at 9:22
10

You could use TikZ for this. The advantage of TikZ is that it's very powerful, so you can produce whatever effect you want, providing you have the know-how.

Here is some code.

  • The \def... lines near the top are for customising the size and colour of the cells.
  • The table might look wrong if the data in the cells is too long, so you must manually make sure that \cellwidth is big enough for your needs.
  • The data in the table is given in a slightly strange way, with lots of {, }, / and % symbols. Make sure you keep to this template when putting in your own data, or it will all go belly up!

Do let me know (in the comments below) if you'd like any clarification.

\documentclass[border=5mm]{standalone}

\usepackage{tikz}

\begin{document}

\def\cellwidth{40}
\def\bluecellwidth{10}
\def\cellheight{7}
\def\bluecellcolor{blue!20}
\def\yellowcellcolor{yellow}
\def\whitecellcolor{white}

\begin{tikzpicture}[%
  x=1mm,%
  y=-1mm,%
  every node/.style={%
    shape=rectangle,
    anchor=north west,
    outer sep=0mm,
    draw=black},
  bluecell/.style={%
    fill=\bluecellcolor,
    minimum height=\cellheight * 2 mm,
    minimum width=\bluecellwidth mm},
  yellowcell/.style={%
    fill=\yellowcellcolor,
    minimum height=\cellheight mm, 
    minimum width=\cellwidth mm},
  whitecell/.style={%
    fill=\whitecellcolor,
    minimum height=\cellheight mm,
    minimum width=\cellwidth mm}]

\def\y{0} % Vertical cursor

\foreach \header/\contents in {%
  {123}/{%
    {1339707619:``value''}/{1.1},
    {1339707619:``value''}/{1.11},
    {1339707619:``value''}/{0.87}
  },%
  {456}/{%
    {1339707619:``value''}/{40},
    {1339707619:``value''}/{111},
    {1339707619:``value''}/{144},
    {1339707619:``value''}/{222}
  },%
  {789}/{%
    {1339707619:``value''}/{21.345}
  }%
}{
\node[bluecell] at (0,\y) {\header};
\foreach [count=\i] \yellowtext/\whitetext in \contents {
  \node[yellowcell] at ({\bluecellwidth+(\i-1)*\cellwidth},\y) {\yellowtext};
  \node[whitecell] at ({\bluecellwidth+(\i-1)*\cellwidth},\y+\cellheight) {\whitetext};
}
\xdef\y{\y+2*\cellheight} % Move vertical cursor down one row
}
\end{tikzpicture}

\end{document}

enter image description here

  • Perhaps a matrix solution will save some work (defining the coordinates in principle)... – Claudio Fiandrino May 28 '13 at 9:33
  • Wow, that is an accurate representation. Thanks a lot ! – Eugen May 28 '13 at 10:27
6

Your example could be done like this, losing the fancy formatting, but retaining all the information, as far as I can tell.

\documentclass{scrartcl}

\usepackage{booktabs}

\begin{document}
\begin{table}
\centering
\begin{tabular}{lcccc}
    \toprule
        & 1339707619:``value'' & 1339817619:``value'' &
    1369707619:``value'' & 1369707888:``value''\\
    \midrule
    123 & 1.1    & 1.11 & 0.87 & \\
    456 & 40     & 111  & 144  & 222 \\
    789 & 21.345 &      &      & \\
    \bottomrule
\end{tabular}
\end{table}
\end{document}

Table

3

Yes you can using multirow, here is an example:

\documentclass[border=5mm]{standalone}    
\usepackage{multirow}
\begin{document}

\begin{tabular}{cc|c|c|c|c|l}
\cline{3-6}
& & \multicolumn{4}{ c| }{Primes} \\ \cline{3-6}
& & 2 & 3 & 5 & 7 \\ \cline{1-6}
\multicolumn{1}{ |c| }{\multirow{2}{*}{Powers} } &
\multicolumn{1}{ |c| }{504} & 3 & 2 & 0 & 1 &     \\ \cline{2-6}
\multicolumn{1}{ |c  }{}                        &
\multicolumn{1}{ |c| }{540} & 2 & 3 & 1 & 0 &     \\ \cline{1-6}
\multicolumn{1}{ |c  }{\multirow{2}{*}{Powers} } &
\multicolumn{1}{ |c| }{gcd} & 2 & 2 & 0 & 0 & min \\ \cline{2-6}
\multicolumn{1}{ |c  }{}                        &
\multicolumn{1}{ |c| }{lcm} & 3 & 3 & 1 & 1 & max \\ \cline{1-6}
\end{tabular}
\end{document}
3

Compound stacks!

\documentclass{arlticle}
\usepackage{xcolor}
\usepackage[usestackEOL]{stackengine}
\newcommand\widebox[2][white]{\fcolorbox{black}{#1}{\makebox[1.5in]{#2\strut}}}
\newcommand\groupbox[1]{\groupboxaux[#1]}
\def\groupboxaux[#1\cr#2]{\stackanchor[-\fboxsep]{\widebox[yellow]{#1}}
  {\widebox{#2}}\kern-\fboxrule\ignorespaces}
\newcommand\leadbox[1]{\unskip\fcolorbox{black}{blue!30}{\makebox[.5in]{%
  #1\stackanchor[\dimexpr2\fboxrule+\fboxsep]{\strut}{\strut}}}\kern-\fboxrule%
  \ignorespaces}
\begin{document}
\setstackgap{S}{-\fboxrule}
\Shortstack[l]{
  \leadbox{123}
  \groupbox{1339707619:``value''\cr 1.1}
  \groupbox{1339817619:``value''\cr 1.1}
  \groupbox{1369707619:``value''\cr 0.87}
\\
  \leadbox{456}
  \groupbox{1339707619:``value''\cr 40}
  \groupbox{1339817619:``value''\cr 111}
  \groupbox{1339817619:``value''\cr 144}
  \groupbox{1369707619:``value''\cr 222}
\\
  \leadbox{789}
  \groupbox{1339707619:``value''\cr 21.345}
}
\end{document}

enter image description here

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.