0

enter image description here

I want to use this table format in my work. I have tried to implement it, but I have been unable to obtain the same result. Please help me to access the code of this table format.

3
5

Here's how I'd do it. It needs a few tweaks, but hopefully this will get you pointed in the right direction. I recommend taking a look at some of the packages I've used. They probably have some useful functionality for some of the sort of tables you seem to be trying to produce.

\documentclass{article}
\usepackage{booktabs} % Adds table formatting options
\usepackage{dcolumn} % Adds option to align data around the decimal point
\newcolumntype{d}{D{.}{.}{-1}} % Use 'd' to align column on decimal place
\usepackage[labelfont={bf},singlelinecheck={off}]{caption} % Formats captions on images, tables, etc.
\newcommand{\cc}[1]{\multicolumn{1}{c}{#1}} % centralise table cell

\begin{document}

\begin{table}[tp]
    \centering
    \caption{caption text goes here}
    \label{tbl:crossref-label}
    \begin{tabular}{l d d @{\extracolsep{6pt}} d d l}
        \toprule
        & \multicolumn{2}{c}{multicolumn title} & \multicolumn{3}{c}{multicolumn title} \\
        \cmidrule{2-3} \cmidrule{4-6}
        & \cc{Mean} & \cc{SD} & \cc{Mean} & \cc{SD} & \cc{$p$} \\
        \midrule
        text &&&&& \\
        more text & 12.34 & 1.234 & 1.23 & 1.234 & ** \\
        more text & 1.23 & 1.2345 & 12.3 & 1.23 & ** \\
        \bottomrule
    \end{tabular}
\end{table}

\end{document}

This will display like this: result

2
  • 1
    You can use \cmidrule instead of \cline to get the same vertical distances as \midrule.
    – StefanH
    Jun 19 '17 at 10:21
  • Thanks. That's a better solution. I've updated my answer.
    – Ulysses
    Jul 3 '17 at 6:00
2

enter image description here

Here are some hints about how to customize the table as shown in the question:

  • \captionsetup{justification=centering, labelfont=bf, labelsep=quad} to customize the caption as shown above.
  • Equalized column widths is best handled by defining a new column type using \newcolumntype{C}{ >{ \arraybackslash \Centering } X } in the preamble where C is the new column type. Or you can use \newcolumntype{R}{ >{ \arraybackslash \RaggedLeft } X } where R is a new column type where entries are justified to the right. Many publications use such format for the first column.
  • \cmidrule(lr){col} allows for trimmed rulings from left and right
  • \colorbox{LightBlue}{text} to highlight in the color shown above

The overall code is:

\documentclass{report}


% Text justification package
\usepackage{ragged2e}


% Table packages
\usepackage{booktabs}
\usepackage{tabularx}

    % New column types
    \newcolumntype{C}{ >{ \arraybackslash \Centering } X } % centered
    \newcolumntype{L}{ >{ \arraybackslash \RaggedRight } X } % left justified
    \newcolumntype{R}{ >{ \arraybackslash \RaggedLeft } X } % right justified
    \newcolumntype{S}[1]{ >{ \arraybackslash \Centering } m{#1} } % centered with specified width


% Caption package
\usepackage{caption}
\captionsetup{justification=centering, labelfont=bf, labelsep=quad} % centers floats caption, makes float name in bold font, and adds space between float name and the caption

% Highlighting packages
\usepackage[svgnames]{xcolor}

    % Shortcut command for highlighting in LightBlue
    \newcommand{\LB}[1]{\colorbox{LightBlue}{#1}}



\begin{document}



\begin{table}[htp]


    % Center the table
    \centering

    \caption{Scholarly works, time allocation, satisfaction, and income by US-versus foreign-born status}
    \label{tbl:crossref-label}


    \begin{tabularx}{1\textwidth}{C >{\hsize=0.2\hsize}C >{\hsize=0.2\hsize}C >{\hsize=0.2\hsize}C >{\hsize=0.2\hsize}C >{\hsize=0.2\hsize}C }


        \toprule[0.8pt]


        &
        \multicolumn{2}{S{0.9in}}{Born in US N = $2900^{*}$} &
        \multicolumn{3}{S{1.4in}}{Foreign Born N = $1190$}
        \\
        \cmidrule(lr){2-3} \cmidrule(lr){4-6}


        & Mean & SD & Mean & SD & $p$
        \\
        \midrule


        Recent Scholarly Works & & & & &
        \\


        \LB{Refereed Articles} & \LB{12.34} & \LB{1.234} & \LB{1.23} & \LB{1.234} & \LB{**}
        \\



        \bottomrule[0.8pt]



    \end{tabularx}


\end{table}

\end{document}
1

Using @Ulysses answer as missing MWE in question .., , packages siunitx and threeparttable for S column type and for limit table caption to table width and eventually add table notes below table for example for description of ** in last column (it is not clear what they meaning) respectively:

\documentclass{article}
\usepackage{booktabs, threeparttable} 
\usepackage{siunitx} % Formats units, numbers, numbers in table
\usepackage[font=small, labelfont=bf, skip=1ex]{caption} % Formats captions of floats
\newcommand{\mcx}[2]{\multicolumn{#1}{c}{#2}} % shortcut for multicolumn

\begin{document}
    \begin{table}[ht]
    \centering
    \begin{threeparttable}
\caption{Scholarly works, time allocation, satisfaction, and income by US-versus foreign-born status}
    \label{tbl:crossref-label}
\begin{tabular}{l *{2}{S[table-format=2.2] S[table-format=1.4]} c}
    \toprule
            & \mcx{2}{multicolumn title}    & \mcx{3}{multicolumn title}    \\
    \cmidrule(lr) {2-3} \cmidrule(lr){4-6}
            & {Mean}    & {SD}              & {Mean}    & {SD}  & $p$       \\
    \midrule
text        &           &                   &           &       &           \\
more text   & 12.34     & 1.234             & 1.23      & 1.234 & **        \\
more text   & 1.23      & 1.2345            & 12.3      & 1.23  & **        \\
    \bottomrule
\end{tabular}
    \end{threeparttable}
    \end{table}
\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.