3

I basically want to list attribute names and a attribute description in a table. The attributes belong to a certain category. The idea is to list all attributes in one table to avoid creating multiple tables for each category. At the moment I am simply subdividing the table by using midrules for each category. The result looks ok, but I wonder if there is a more beautiful way to do this (e.g. indenting the rows below each category).

\documentclass{article}
\usepackage{booktabs}
\begin{document}

\begin{table}[h]
\centering
\begin{tabular}{ll}
\toprule
\textbf{Attribute} & \textbf{Description} \\ \midrule
\multicolumn{2}{l}{{Category 1}} \\ \midrule
A1 & D1 \\
A2 & D2 \\ \midrule
\multicolumn{2}{l}{{Category 2}} \\ \midrule
A3 & D3 \\
A4 & D4 \\
\bottomrule
\end{tabular}
\end{table}

\end{document}
1
  • 1
    Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
    – user31729
    Mar 28 '15 at 17:16
2

Maybe I'm old-fashioned, but I still like simple tables:

enter image description here

\documentclass{article}
\usepackage{booktabs,multirow}
\begin{document}
\begin{table}[h]
\centering
\begin{tabular}{ccc}
\toprule
\textbf{Category} & \textbf{Attribute} & \textbf{Description} \\ \midrule\\[-.9em]
\multirow{2}{*}{1}
  & A1 & D1 \\
  & A2 & D2 \\[.5em]
\multirow{2}{*}{2}
  & A3 & D3 \\
  & A4 & D4 \\[.5em]
\multirow{2}{*}{3}
  & A2 & D1 \\
  & A3 & D4 \\
\bottomrule
\end{tabular}
\end{table}

\end{document}
2
  • Thank you for your advise! What I didn't mention was that the description of an attribute might be a little bit longer (however no line break was necessary in my first approach above). If I put the category in one column, I run out of horizontal space. Mar 29 '15 at 17:23
  • Then my choice would be \usepackage{tabulary} in the preamble and start the table with \begin{tabulary}{\linewidth}{cLc} or may be use the sister package tabularx to allow line breaks in the column\s with longs texts.
    – Fran
    Mar 29 '15 at 17:56
1

I will do something like this:

My redesign of the table

\documentclass{article}
\usepackage{booktabs}
\begin{document}

\begin{table}[h]
\centering
\begin{tabular}{@{}lll@{}}
\toprule
&\textbf{Attribute} & \textbf{Description} \\ \midrule
\multicolumn{3}{l}{\small \textsc{category 1}} \\ 
&A1 & D1 \\
&A2 & D2 \\ 
\multicolumn{3}{l}{\small \textsc{category 2}} \\ 
&A3 & D3 \\
&A4 & D4 \\
\bottomrule
\end{tabular}
\end{table}

\end{document}

Key changes:

  • Don't use hline
  • "Indent" the lines using 3 columns instead of 2.
  • Distintive typography for "categories."
  • Use @{} in the column description to remove blank space at the first and last column.

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.