4

I need to incorporate multirow in the following table, and I keep coming across errors. I found the following example for a great formatted table with colored cells and rounded corners here.

I have tried to implement it for my own table, which you will see in this MWE.

\documentclass[10pt, compress]{beamer}
\usepackage{multirow}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usepackage{PTSansNarrow}
\usepackage[T1]{fontenc}
\usepackage{adjustbox}

\begin{document}

\begin{tikzpicture}
\clip node (m) [matrix,matrix of nodes,
fill=black!20,inner sep=0pt,
nodes in empty cells,
nodes={minimum height=1cm,minimum width=2.6cm,anchor=center,outer sep=0,font=\sffamily},
row 1/.style={nodes={fill=black,text=white}},
column 1/.style={nodes={fill=gray,text=white,align=right,text width=2.5cm,text depth=0.5ex}},
column 2/.style={text width=4cm,align=center,every even row/.style={nodes={fill=white}}},
%column 3/.style={text width=3cm,align=center,every even row/.style={nodes={fill=white}},},
row 1 column 1/.style={nodes={fill=gray}},
prefix after command={[rounded corners=4mm] (m.north east) rectangle (m.south west)}
] {
         & Things Identified \\
1  &  \\
2  & A \\
3  & B\\
3  & C\\
4  & D  \\
4  & E \\
4  & F \\
5  & G\\
5  & H\\
};
\end{tikzpicture}
}
\end{document}

This MWE provides me with the below result:

Table Sample Without Multirow

When I try to use multirow so that I do not repeat category names in Column 1, my presentation does not compile.

Here is the MWE of the code when I try to implement also multirow:

UPDATE:

\documentclass[10pt, compress]{beamer}
\usepackage{multirow}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usepackage{PTSansNarrow}
\usepackage[T1]{fontenc}
\usepackage{adjustbox}

\newcommand\PutLab[3][]{
\node[inner sep=0.05cm,text=white,font=\sffamily,anchor=east,#1] 
  at (#2)
  {#3};
}
\begin{document}

\begin{frame}

\begin{adjustbox}{max totalsize={1.2\textwidth}{0.8\textheight},center}
\begin{tikzpicture}[ampersand replacement=\&]
\clip node (m) 
  [
    matrix,
    matrix of nodes,
    fill=black!20,
    inner sep=0pt,
    nodes in empty cells,
    nodes={
      minimum height=1cm,
      minimum width=2.6cm,
      anchor=center,
      outer sep=0,
      font=\sffamily
    },
    row 1/.style={
      nodes={fill=black,text=white}
    },
    column 1/.style={
      nodes={
        fill=gray,
        text=white,
        align=right,
        text width=2.5cm,
        text depth=0.5ex}
    },
    column 2/.style={
      text width=4cm,
      align=center,
      every even row/.style={nodes={fill=white}}
    },
    column 3/.style={
      text width=3cm,
      align=center,
      every even row/.style={nodes={fill=white}}
    },
    row 1 column 1/.style={nodes={fill=gray}},
    prefix after command={
      [rounded corners=4mm] 
        (m.north east) rectangle (m.south west)
    }
] 
{
\& Things Identified \\
1 \& \\
2 \& A \\
\& B \\
\& C \\
\& D \\
\& E \\
\& F \\
\& G \\
\& H \\
};
\PutLab{m-4-1.south east}{3}
\PutLab{m-7-1.east}{4}
\PutLab{m-9-1.south east}{5}
\foreach \Valor in {1,2,3,5,8}
  \draw[black!70] (m-\Valor-1.south west) -- (m-\Valor-2.south east);
\end{tikzpicture}
\end{adjustbox}
\end{frame}
\end{document}

After resizing the box with \usepackageadjustbox, as in the updated code right above and implementing @Gonzalo Medina proposal, I have the problem with the lighter gray boxes still being visible in the multirow column, as such:

Table with Multirow and light gray lines

I am not sure if this is because the boxes are "overlapping" each other or for some other reason, but how can we eliminate (or cover them)?

4
  • 1
    Hmm, good question. A couple of things: 1) You're missing a \usetikzlibrary{matrix} line in both examples, otherwise I get a compiler error; 2) I'm not sure multirow will work in a matrix of nodes since the matrix of nodes isn't a "real" LaTeX table, but we might be able to fake it with Jake's answer you linked to; 3) As the code is now, the lines that are shown between cells in the left column are just artifacts in my PDF viewer, if I zoom in they go away, so do you want lines between rows in that column?; 4) You are drawing this table with three columns but you only need 2 :-)
    – darthbith
    Mar 4 '15 at 12:53
  • @darthbith To answer your points: 1. Sorry about that, I have it in the preamble of the working code that I am using, I must have forgot to include it when copying over the code for the tables. 2. Since I have posted this question, I have been trying to work with Jake's answer from the post I linked, but I have been unsuccessful, and as my multirow MWE above, it won't compile. 3. The lines between the rows in the left column are fine for the moment, especially because they are marking different "categories". 4. I updated the code in the MWE above :)
    – owwoow14
    Mar 4 '15 at 13:07
  • Thanks for updating the code! I don't get any compiler errors now, just some warnings. To clarify, do you want lines between the rows in the first column (except where there are multirows) or do you not want those lines? Without the lines, it may be difficult to tell where one multirow begins or ends
    – darthbith
    Mar 4 '15 at 13:08
  • @darthbith You are correct, I do want the lines in the first column (except for multirows). As you said, without them it would be difficult to understand what corresponds to what :-)
    – owwoow14
    Mar 4 '15 at 13:10
4

Here's one possibility; the \multirow command from the multirow package won't be useful here since a TikZ matrix is not really a standard LaTeX matrix; you can use the anchors for some of the matrix cells to place the labels at the desired location (defining a command to do so, as in my example code). I also drew some horizontal lines to separate the groups of rows (otherwise, the multirow labels won't be rapidly read). The dimensions for your matrix are too big and it won't fit in a frame so I used the shrink option just for the example (the best alternative is to reduce the dimensions, if possible):

\documentclass[10pt, compress]{beamer}
\usepackage{multirow}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usepackage{PTSansNarrow}
\usepackage[T1]{fontenc}
\usepackage{adjustbox}

\newcommand\PutLab[3][]{
\node[inner sep=0.05cm,text=white,font=\sffamily,anchor=east,#1] 
  at (#2)
  {#3};
}
\begin{document}

\begin{frame}[shrink=15]
\begin{tikzpicture}[ampersand replacement=\&]
\clip node (m) 
  [
    matrix,
    matrix of nodes,
    fill=black!20,
    inner sep=0pt,
    nodes in empty cells,
    nodes={
      minimum height=1cm,
      minimum width=2.6cm,
      anchor=center,
      outer sep=0,
      font=\sffamily
    },
    row 1/.style={
      nodes={fill=black,text=white}
    },
    column 1/.style={
      nodes={
        fill=gray,
        text=white,
        align=right,
        text width=2.5cm,
        text depth=0.5ex}
    },
    column 2/.style={
      text width=4cm,
      align=center,
      every even row/.style={nodes={fill=white}}
    },
    column 3/.style={
      text width=3cm,
      align=center,
      every even row/.style={nodes={fill=white}}
    },
    row 1 column 1/.style={nodes={fill=gray}},
    prefix after command={
      [rounded corners=4mm] 
        (m.north east) rectangle (m.south west)
    }
] 
{
\& \& Things Identified \\
1 \& \& \\
2 \& \& A \\
\& \& B \\
\& \& C \\
\& \& D \\
\& \& E \\
\& \& F \\
\& \& G \\
\& \& H \\
};
\PutLab{m-4-1.south east}{3}
\PutLab{m-7-1.east}{4}
\PutLab{m-9-1.south east}{5}
\foreach \Valor in {1,2,3,5,8}
  \draw[black!70] (m-\Valor-1.south west) -- (m-\Valor-3.south east);
\end{tikzpicture}
\end{frame}

\end{document}

enter image description here

Update:

\documentclass[10pt, compress]{beamer}
\usepackage{multirow}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usepackage{PTSansNarrow}
\usepackage[T1]{fontenc}
\usepackage{adjustbox}

\newcommand\PutLab[3][]{
\node[inner sep=0.05cm,text=white,font=\sffamily,anchor=east,#1] 
  at (#2)
  {#3};
}
\begin{document}

\begin{frame}[shrink=15]
\begin{tikzpicture}[ampersand replacement=\&]
\clip node (m) 
  [
    matrix,
    matrix of nodes,
    fill=black!20,
    inner sep=0pt,
    nodes in empty cells,
    nodes={
      minimum height=1cm,
      minimum width=2.6cm,
      anchor=center,
      outer sep=0,
      font=\sffamily
    },
    row 1/.style={
      nodes={fill=black,text=white}
    },
    column 1/.style={
      nodes={
        fill=gray,
        text=white,
        align=right,
        text width=2.5cm,
        text depth=0.5ex}
    },
    column 2/.style={
      text width=4cm,
      align=center,
      every even row/.style={nodes={fill=white}}
    },
    column 3/.style={
      text width=3cm,
      align=center,
      every even row/.style={nodes={fill=white}}
    },
    row 1 column 1/.style={nodes={fill=gray}},
    prefix after command={
      [rounded corners=4mm] 
        (m.north east) rectangle (m.south west)
    }
] 
{
\& Things Identified \\
1 \& \\
2 \& A \\
\& B \\
\& C \\
\& D \\
\& E \\
\& F \\
\& G \\
\& H \\
};
\PutLab{m-4-1.south east}{3}
\PutLab{m-7-1.east}{4}
\PutLab{m-9-1.south east}{5}
\foreach \Valor in {1,2,3,5,8}
  \draw[black!70] (m-\Valor-1.south west) -- (m-\Valor-2.south east);
\end{tikzpicture}
\end{frame}

\end{document}
6
  • I implemented your proposal, and I needed to modify the code because as @darthbith mentioned above, the original code that I posted included 3 columns, instead of just 2. When I implemented your proposal, with the updated code (only 2 columns). I am having a problem with the drawn lines, as the error is telling me that there is no shape named. Any ideas, how to solve that, I provided the example of the code above in the question.
    – owwoow14
    Mar 4 '15 at 13:45
  • 1
    @owwoow14 You commented out only a part of a column style and left a part uncommented, so this produced errors. Also, since now you have only two columns, you can't use the value 3 in the \foreach. See the update. Mar 4 '15 at 13:56
  • as you will see in the updated code example, I have implemented your proposal without error and resized the image using adjustbox. However, the grey lines of the cells of the multirow are visible. Is there a way to eliminate these lines? See updated code in the OP, for image and code example.
    – owwoow14
    Mar 4 '15 at 14:50
  • The problem does not appear on the browser, yet it does when you look at it in PDF-Viewer
    – owwoow14
    Mar 4 '15 at 15:01
  • 1
    @owwoow14 Sorry, that's not a LaTeX issue, but a problem with the PDF viewers. See, for example tex.stackexchange.com/q/11769/3954 for an explanation and a (possible) solution. Also, don't forget that you can accept the answer if you consider it solved your problem. In case of doubt, please see How do you accept an answer?. Mar 4 '15 at 16:26

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.