0

I'm trying to make a table that's essentially a feature matrix. Entries are grouped, and each group is a set of completions to a sentence. Because of space constraints, I'm trying to keep the start of the sentence and the first completion on the same line, like so:

Working without row colors

However, I'd like to add row colors to better differentiate the groups. I've achieved the effect of pushing the text in each group header to the sides by adding \hskips in between the two pieces...but then, as documented in the colortbl comments, the color falls short of reaching the end of the cell:

Not working with colored rows

Is there a way to achieve this combination of effects without that ugly gap in coloration, either by tweaking colortbl-related code or by using a different mechanism to split the group headers? (Or perhaps a different design solution altogether...)

MWE:

\documentclass[12pt]{report}

\usepackage{colortbl,booktabs}
\usepackage{pifont}

\newcommand{\rowgrpheader}[2]{\textbf{#1\ldots} \hskip 5pt plus 1filll \ldots #2}
\newcommand{\xmark}{\ding{55}}
\newcommand{\cmark}{\ding{51}}

\begin{document}
\begin{tabular}{rcc}
  \toprule
  & \textbf{Broke a chain} & \textbf{Freed a human soul} \\ \midrule
  \rowcolor[gray]{.85} \rowgrpheader{Loyalty to}{a petrified opinion} & \xmark & \xmark \\
  \rowcolor[gray]{.85} \ldots principled open-mindedness & \cmark & \cmark \\
  \rowgrpheader{Telling other people to}{shut up} & \xmark & \xmark \\
  \ldots be their best selves & \cmark & \cmark \\
  \bottomrule
\end{tabular}
\end{document}
0

Here's a way with tabularx (and makecell, for a better look):

\documentclass[12pt]{report}
\usepackage[showframe]{geometry}
\usepackage[table, svgnames]{xcolor}
\usepackage{booktabs, tabularx, makecell, bigstrut}
\usepackage{pifont}

\renewcommand{\theadfont}{\normalsize\bfseries}

\newcommand{\rowgrpheader}[2]{\textbf{#1\ldots} \hskip 5pt plus 1filll \ldots #2}
\newcommand{\xmark}{\ding{55}}
\newcommand{\cmark}{\ding{51}}

\begin{document}

\noindent\begin{tabularx}{\linewidth}{ >{\raggedleft}Xcc}
  \toprule
  & \thead{Broke a chain} & \thead{Freed a\\ human soul} \\
  \specialrule{\lightrulewidth}{0pt}{0pt}
  \rowcolor{Gainsboro!70} \rowgrpheader{Loyalty to}{a petrified opinion} & \xmark & \xmark\bigstrut[t] \\
  \rowcolor{Gainsboro!70} \ldots principled open-mindedness & \cmark & \cmark \\
  \rowgrpheader{Telling other people to}{shut up} & \xmark & \xmark \\
  \ldots be their best selves & \cmark & \cmark \\
  \bottomrule
\end{tabularx}

\end{document} 

enter image description here

1

You can get rid of the white gap by simply using a fixed width column type like p or m for the first column.

As the table exceeds the textwidth, I have included tabularx and adjusted the widths of the second and third column.

\documentclass[12pt]{report}

\usepackage{colortbl,booktabs}
\usepackage{pifont}
\usepackage{tabularx}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\newcommand{\xmark}{\ding{55}}
\newcommand{\cmark}{\ding{51}}

\begin{document}

\begin{tabularx}{\textwidth}{XC{2cm}C{2.5cm}}
  \toprule
  & \textbf{Broke a chain} & \textbf{Freed a human soul} \\ \midrule
 \rowcolor[gray]{.85} \textbf{Loyalty to \ldots} \hfill  \ldots a petrified solution & \xmark & \xmark \\
 \rowcolor[gray]{.85}  \raggedleft \ldots principled open-mindedness & \cmark & \cmark \\
 \textbf{Telling other people to \ldots} \hfill \ldots shut up  & \xmark & \xmark \\
 \raggedleft \ldots be their best selves & \cmark & \cmark \\
  \bottomrule
\end{tabularx}

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