TransWikia.com

How to make a list in table cell to show multiple items in a better way?

TeX - LaTeX Asked on August 13, 2021

I am trying to show multiple-choice questions in a table along with a description & percent. Here is my attempt:

begin{table*}
small
centering
begin{tabular}{rrr}
toprule
 {bf Question Type} & {bf Percent.} & {bf Example} 
midrule

Type 1  &  0.47 &makecell{Which is not a side effect of the progestogen-only pill (POP)? hfill textbf{a)} colorbox{mygreen}{Ovarian cysts}
   textbf{b)} Venous thromboembolism 
   textbf{c}) Increased risk of diabetes mellitus
    textbf{d)} Ectopic pregnancy}
 
 hline
Type 1  &  0.47 &makecell{Which is not a side effect of the progestogen-only pill (POP)? hfill textbf{a)} colorbox{mygreen}{Ovarian cysts}
   textbf{b)} Venous thromboembolism 
   textbf{c}) Increased risk of diabetes mellitus
    textbf{d)} Ectopic pregnancy}
 
bottomrule
end{tabular}
caption{}
label{tab:subject_wise}
vspace{-2ex}
end{table*}

But it’s not looking good :

enter image description here

Is there a better way to do this? I have to show two multiple-choice questions per question type.

Edit:

The accepted answer’s code is working well, but I am getting this error:

enter image description here

enter image description here

How to resize the table to fit it in one page?

One Answer

enter image description here

documentclass[twocolumn]{article}
usepackage{booktabs}
usepackage{makecell}
usepackage{xcolor}
definecolor{mygreen}{RGB}{0,255,0}
usepackage{tabularx}
usepackage{caption}
renewcommand{theadfont}{normalsizebfseries}

usepackage[inline]{enumitem}
newlist{tabenum}{enumerate}{1}
setlist[tabenum]{label*=alph*),
                  font=bfseries,
                  leftmargin=*,
                  nosep,
                  before=begin{minipage}[t]{hsize},
                  after=end{minipage}}

setlengthfboxsep{0pt}
newcommand{correctitem}{item[stepcounter{tabenumi}colorbox{mygreen}{thetabenumi}]}
begin{document}

begin{table*}
caption{Fine-grained evaluation per medical subject in Test and Dev set}
label{tab:subject_wise}
begin{tabularx}{textwidth}{ccX}
toprule
 thead{Question Type} & thead{Percent.} & thead{Example} 
midrule
Type 1  &  0.47 & Which is not a side effect of the progestogen-only pill (POP)?  
        &       & begin{tabenum}
                  correctitem Ovarian cysts
                  item  Venous thromboembolism
                  item  Increased risk of diabetes mellitus 
                  item  Ectopic pregnancy
                  end{tabenum}
 
midrule
Type 1  &  0.47 & Which is not a side effect of the progestogen-only pill (POP)? Ths question is a lot longer, this question is a lot longer 
        &       & begin{tabenum}
                  correctitem Ovarian cysts
                  item  Venous thromboembolism
                  item  Increased risk of diabetes mellitus 
                  item  Ectopic pregnancy
                  end{tabenum}
 
bottomrule
end{tabularx}

end{table*}

end{document}

If you want the answers to be indented with respect to the question, replace leftmargin=* with leftmargin=30pt or a different length of your choice.

Correct answer by leandriis on August 13, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP