2

I'm new to the latex world. Is there a way to produce a table like the following?

enter image description here

I've tried with the following code exploiting multirow, siunitx and booktabs packages following this reference https://tex.stackexchange.com/a/174328/233121 but the result is not really the expected one.

\documentclass[11pt]{article}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage{multirow}

\begin{document}

\begin{table}[ht] \begin{tabular}{ l *{6}{S[table-format=1.4]} S[table-format=5] S[table-format=3.2] } \toprule \multicolumn{1}{c|}{\textbf{Program}} & \multicolumn{1}{c|}{\textbf{Problem Size}} & \multicolumn{4}{c|}{\textbf{Instructions (Billions)}} & \multicolumn{3}{c}{\textbf{Synchronization Primitives}} \ \cmidrule(lr){3-6} \cmidrule(lr){7-9} && {\textbf{Total}} & {\textbf{FLOPS}} & {\textbf{Reads}} & {\textbf{Writes}} & {\textbf{Locks}} & {\textbf{Barriers}} & {\textbf{Conditions}} \ \midrule \texttt{blackscholes} & 65,536 options & 2.67 & 1.14 & 0.68 & 0.19 & 0 & 8 & 0 \ \texttt{freqmine} & 990,000 transactions & 33.45 & 0.00 & 11.31 & 5.24 & 990,025 & 0 & 0 \ \texttt{swaptions} & 64 swaptions, 20,000 simulations & 14.11 & 2.62 & 5.08 & 1.16 & 23 & 0 & 0 \ \texttt{bodytrack} & 4 frames, 4,000 particles & 14.03 & 4.22 & 3.63 & 0.95 & 114,621 & 619 & 2,042 \ \bottomrule \end{tabular} \end{table}

\end{document}

enter image description here

I'd like to find a solution in order to automatically wrap overfulling text but can't figure it out.

2 Answers2

3

Here is a way to do that table (in landscape mode because, otherwise, it's too wide).

\documentclass[landscape]{article}
\usepackage{geometry}
\usepackage{nicematrix}
\usepackage{siunitx}

\begin{document}

\begin{table}[ht] \setlength{\tabcolsep}{5pt} \begin{NiceTabular}{ll*{5}{S}S[table-format=4.0]S}[hvlines] \Block{2-1}{\textbf{Program}} & \Block{2-1}{\textbf{Problem Size}} & {\Block{1-4}{\textbf{Instructions (Billions)}}} &&&& {\Block{1-3}{\textbf{Synchronization Primitives}}} \ && {\textbf{Total}} & {\textbf{FLOPS}} & {\textbf{Reads}} & {\textbf{Writes}} & {\textbf{Locks}} & {\textbf{Barriers}} & {\textbf{Conditions}} \ \texttt{blackscholes} & 65,536 options & 2.67 & 1.14 & 0.68 & 0.19 & 0 & 8 & 0 \ \texttt{freqmine} & 990,000 transactions & 33.45 & 0.00 & 11.31 & 5.24 & 990,025 & 0 & 0 \ \texttt{swaptions} & 64 swaptions, 20,000 simulations & 14.11 & 2.62 & 5.08 & 1.16 & 23 & 0 & 0 \ \texttt{bodytrack} & 4 frames, 4,000 particles & 14.03 & 4.22 & 3.63 & 0.95 & 114,621 & 619 & 2,042 \ \end{NiceTabular} \end{table}

\end{document}

You need several compilations.

Output of the first code

The output is certainly better with only the horizontal rules provided by bookmarks:

\documentclass[landscape]{article}
\usepackage{geometry}
\usepackage{nicematrix}
\usepackage{siunitx}
\usepackage{booktabs}

\begin{document}

\begin{table}[ht] \setlength{\tabcolsep}{5pt} \begin{NiceTabular}{@{}ll*{5}{S}S[table-format=4.0]S@{}} \toprule \Block{2-1}{\textbf{Program}} & \Block{2-1}{\textbf{Problem Size}} & {\Block{1-4}{\textbf{Instructions (Billions)}}} &&&& {\Block{1-3}{\textbf{Synchronization Primitives}}} \ \cmidrule(lr){3-6} \cmidrule(l){7-9} && {\textbf{Total}} & {\textbf{FLOPS}} & {\textbf{Reads}} & {\textbf{Writes}} & {\textbf{Locks}} & {\textbf{Barriers}} & {\textbf{Conditions}} \ \midrule \texttt{blackscholes} & 65,536 options & 2.67 & 1.14 & 0.68 & 0.19 & 0 & 8 & 0 \ \texttt{freqmine} & 990,000 transactions & 33.45 & 0.00 & 11.31 & 5.24 & 990,025 & 0 & 0 \ \texttt{swaptions} & 64 swaptions, 20,000 simulations & 14.11 & 2.62 & 5.08 & 1.16 & 23 & 0 & 0 \ \texttt{bodytrack} & 4 frames, 4,000 particles & 14.03 & 4.22 & 3.63 & 0.95 & 114,621 & 619 & 2,042 \ \bottomrule \end{NiceTabular} \end{table}

\end{document}

Output of the second code

F. Pantigny
  • 40,250
  • I like both your solutions! Unfortunately I'm currently working on my thesis and I'm obliged to work with this format \documentclass[10pt,twoside,openright,english,italian]{book}. Do you think there is a workaround to fit the table? – browser-bug Mar 22 '21 at 15:39
  • I would rotate th tabular by 90° (\rotatebox{90}{...}) and let LaTeX puts the table as it usually does for all the floats. – F. Pantigny Mar 22 '21 at 16:01
0
  • Your table is to wide that can be fit in on page's text area
  • as possible solutions enabling split text in the second column into multi lines
  • also will help use smaller font and reduce size of the \tabcolsep:
\documentclass[10pt,twoside,openright,english,italian]{book}
\usepackage{geometry}  % added
\usepackage{siunitx}
\usepackage{booktabs, multirow, 
            tabularx} % added 
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\NewExpandableDocumentCommand\mcc{O{1}m}{\multicolumn{#1}{c}{#2}}

\begin{document} \begin{table}[ht] \centering \setlength\tabcolsep{3pt} \small \begin{tabularx}{\linewidth}{@{} l L S[table-format=2.2] S[table-format=1.2] S[table-format=2.2] S[table-format=1.2] % S[table-format=3.3] S[table-format=3.0] S[table-format=1.3] @{}} \toprule \textbf{Program}
& \textbf{Problem Size} & \mcc[4]{\textbf{Instructions (Billions)}}
& \mcc[3]{\textbf{Synchronization Primitives}} \ \cmidrule(lr){3-6} \cmidrule(lr){7-9} & & {\textbf{Total}} & {\textbf{FLOPS}} & {\textbf{Reads}} & {\textbf{Writes}} & {\textbf{Locks}} & {\textbf{Barriers}} & {\textbf{Conditions}} \ \midrule \texttt{blackscholes} & 65,536 options & 2.67 & 1.14 & 0.68 & 0.19 & 0 & 8 & 0 \ \texttt{freqmine} & 990,000 transactions & 33.45 & 0.00 & 11.31 & 5.24 & 990,025 & 0 & 0 \ \texttt{swaptions} & 64 swaptions, 20,000 simulations & 14.11 & 2.62 & 5.08 & 1.16 & 23 & 0 & 0 \ \texttt{bodytrack} & 4 frames, 4,000 particles & 14.03 & 4.22 & 3.63 & 0.95 & 114,621 & 619 & 2,042 \ \bottomrule \end{tabularx} \end{table} \end{document}

enter image description here

addendum: small variation where for X column is used \renewcommand\tabularxcolumn[1]{m{#1}} and enlarge table stretch:

\documentclass[10pt,twoside,openright,english,italian]{book}
\usepackage{geometry}
\usepackage{siunitx}
\usepackage{booktabs, multirow, tabularx}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\NewExpandableDocumentCommand\mcc{O{1}m}{\multicolumn{#1}{c}{#2}}

\begin{document} \begin{table}[ht] \centering \setlength\tabcolsep{3pt} \renewcommand\arraystretch{1.2} \renewcommand\tabularxcolumn[1]{m{#1}} \small \begin{tabularx}{\linewidth}{@{} l L S[table-format=2.2] S[table-format=1.2] S[table-format=2.2] S[table-format=1.2] % S[table-format=3.3] S[table-format=3.0] S[table-format=1.3] @{}} \toprule \textbf{Program}
& \textbf{Problem Size} & \mcc[4]{\textbf{Instructions (Billions)}}
& \mcc[3]{\textbf{Synchronization Primitives}} \ \cmidrule(lr){3-6} \cmidrule(lr){7-9} & & {\textbf{Total}} & {\textbf{FLOPS}} & {\textbf{Reads}} & {\textbf{Writes}} & {\textbf{Locks}} & {\textbf{Barriers}} & {\textbf{Conditions}} \ \midrule \texttt{blackscholes} & 65,536 options & 2.67 & 1.14 & 0.68 & 0.19 & 0 & 8 & 0 \ \texttt{freqmine} & 990,000 transactions & 33.45 & 0.00 & 11.31 & 5.24 & 990,025 & 0 & 0 \ \texttt{swaptions} & 64 swaptions, \newline 20,000 simulations & 14.11 & 2.62 & 5.08 & 1.16 & 23 & 0 & 0 \ \texttt{bodytrack} & 4 frames, \newline 4,000 particles & 14.03 & 4.22 & 3.63 & 0.95 & 114,621 & 619 & 2,042 \ \bottomrule \end{tabularx} \end{table} \end{document}

enter image description here

Zarko
  • 296,517