2

I'm trying to replicate this table below:

What I try to get with Latex

with the following code:

    \documentclass{article}
    \usepackage{array,booktabs}% http://ctan.org/pkg/{array,booktabs}
    \usepackage{lineno,hyperref,amsmath}
    \usepackage[table]{xcolor} %colour tables
    \usepackage{color, colortbl} % choose and define a colour
    \usepackage{tabu} %for the font size of the tables
    \usepackage{array}% tables
    \usepackage{booktabs} %tables
    \usepackage[tmargin=1in,bmargin=1in,lmargin=2.7cm,rmargin=2.7cm]{geometry}
    \modulolinenumbers[5]

    \begin{document}

    \begin{table}[ht]
    \definecolor{LightBlue}{rgb}{0.78,0.85,0.95}
    \centering
    \newcolumntype{A}{ >{\centering\arraybackslash}m{0.8cm} }
    \newcolumntype{B}{ >{\centering\arraybackslash}m{0.5cm} }
    \begin{tabu}{|p{4.5cm} B A A A A A|}
    \hline
    \rowcolor{LightBlue}    \textbf{Variable} & \textbf{Obs.} & \textbf{Mean} & \textbf{Median} & \textbf{SD} & \textbf{Min} & \textbf{Max} \\
    \hline
\rowfont{\small} \fontdimen2\font=0.6ex{Variable name with characters on the bottom line annoyingly} & 00 & 0.0000 & 0.0000 & 0.0000 & 0.0000 & 0.00\\
\hline
\rowfont{\small} \fontdimen2\font=0.6ex{In Latex you don't worry about floating numbers} & 00 & 0.0000 & 0.0000 & 0.0000 & 0.0000 & 0.00\\
    \end{tabu}
    \end{table}
    \end{document}

The results is this: Latex table

It is hard to say how many things are wrong with this table but particularly:

  1. The variable names touch the bottom line
  2. The numbers are up in the cell, and not in the middle despite my best efforts with the >{\centering\arraybackslash}.

Anyone knows how to fix any of this?

2 Answers 2

3

While I did not eliminate your column types, not do I use them to accomplish the goal. Instead, I use a \parbox[c] to vertically center the left text in the cell, which will resolve the issue about centering the other columns. I also add a \strut at the beginning and end of the \parbox to provide vertical buffer.

\documentclass{article}
\usepackage{array,booktabs}% http://ctan.org/pkg/{array,booktabs}
\usepackage{lineno,hyperref,amsmath}
\usepackage[table]{xcolor} %colour tables
\usepackage{color, colortbl} % choose and define a colour
\usepackage{tabu} %for the font size of the tables
\usepackage{array}% tables
\usepackage{booktabs} %tables
\usepackage[tmargin=1in,bmargin=1in,lmargin=2.7cm,rmargin=2.7cm]{geometry}
\modulolinenumbers[5]
\usepackage{stackengine}
\begin{document}

\begin{table}[ht]
\definecolor{LightBlue}{rgb}{0.78,0.85,0.95}
\centering
\newcolumntype{A}{ >{\centering\arraybackslash}m{0.8cm} }
\newcolumntype{B}{ >{\centering\arraybackslash}m{0.5cm} }
\begin{tabu}{|p{4.5cm} B A A A A A|}
\hline
\rowcolor{LightBlue}    \textbf{Variable} & \textbf{Obs.} & \textbf{Mean} & \textbf{Median} & \textbf{SD} & \textbf{Min} & \textbf{Max} \\
\hline
\parbox[c]{4.32cm}{\strut\small \fontdimen2\font=0.6ex{Variable name with characters on the bottom line annoyingly\strut}} & 00 & 0.0000 & 0.0000 & 0.0000 & 0.0000 & 0.00\\
\hline
\parbox[c]{4.32cm}{\strut\small \fontdimen2\font=0.6ex{\strut In Latex you don't worry about floating numbers\strut}} & 00 & 0.0000 & 0.0000 & 0.0000 & 0.0000 & 0.00\\
\hline
\end{tabu}
\end{table}
\end{document}

enter image description here

1
  • Thanks so much Steven, it looks really sleek. It's been some hours knocking my head against it!
    – User981636
    May 19, 2015 at 13:46
1

The table you try to copy is made by booktabs or similar. As you already load this package twice... you could actually use it here:

% arara: pdflatex

\documentclass{article}
\usepackage[tmargin=1in,bmargin=1in,lmargin=2.7cm,rmargin=2.7cm]{geometry}
\usepackage{array,booktabs,threeparttable}
\usepackage[table]{xcolor}
\definecolor{LightBlue}{rgb}{0.78,0.85,0.95}
\usepackage{siunitx}
\usepackage{ragged2e}
\usepackage{caption}

\newcommand{\topline}{\arrayrulecolor{black}\specialrule{0.08em}{\abovetopsep}{0pt}%
    \arrayrulecolor{LightBlue}\specialrule{\belowrulesep}{0pt}{-1pt}%
    \arrayrulecolor{black}
    }
\newcommand{\midline}{\arrayrulecolor{LightBlue}\specialrule{\aboverulesep}{-1pt}{0pt}%
    \arrayrulecolor{black}\specialrule{\lightrulewidth}{0pt}{0pt}%
    \arrayrulecolor{white}\specialrule{\belowrulesep}{0pt}{-1pt}%
    \arrayrulecolor{black}
    }

\begin{document}        
\begin{table}[ht]
    \centering
    \begin{threeparttable}
        \caption{Some caption}
    \begin{tabular}{%
        >{\RaggedRight}m{7.35cm} 
        S[table-format=1.0]
        S[table-format=1.4]
        S[table-format=1.4]
        S[table-format=1.4]
        S[table-format=1.4]
        S[table-format=1.2]
        }
        \topline
        \rowcolor{LightBlue} \textbf{Variable} & \textbf{Obs.} & \textbf{Mean} & \textbf{Median} & \textbf{SD} & \textbf{Min} & \textbf{Max} \\
        \midline
        Variable name with characters on the bottom line annoyingly & 00 & 0.0000 & 0.0000 & 0.0000 & 0.0000 & 0.00\\
        \midrule
        In \LaTeX{} you don't worry about floating numbers & 00 & 0.0000 & 0.0000 & 0.0000 & 0.0000 & 0.00\\\bottomrule
    \end{tabular}
    \begin{tablenotes}
        \item Legend: Obs.: Observation, SD: Standard Deviation.
    \end{tablenotes}
    \end{threeparttable}
\end{table}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .