jeudi 4 décembre 2014

Table caption inside tabular environment


I would like to write a table with latex which looks as similar as possible to this one here but I do not know how to add the caption to the header of the table as seen down below:


enter image description here


I reach as far as this here (see code down below) with only a "normal" standardized caption as we are used to from latex.



\documentclass[oneside,a4paper]{article}

\usepackage{mathpazo}
\linespread{1.05}

\usepackage[table,hideerrors]{xcolor}
\usepackage{booktabs,ctable}
\usepackage{caption}

\begin{document}
\begin{center}
\definecolor{blue}{HTML}{E7E8E8}
\rowcolors{1}{blue}{blue}
\begin{tabular}{ l c }
Parameter & Value \\
\specialrule{.1em}{.05em}{.05em}
\textbf{Parameter} & \textbf{Value} \\
\midrule
Number of territories & 22 \\
Age of sexual maturity (years) & 2 \\
& \\
Winter mortality & \\
Mean of the winter strength distribution (days) & 117\\
\specialrule{.1em}{.05em}{.05em}
\end{tabular}
\captionof{table}{Overview of processes, parameters and default values of the marmot model}
\label{tab:variables}
\end{center}


Edit: Modified (near perfect!) table based on the responses to work with multicol package.



\begin{center}
\refstepcounter{table} \label{tab:variables}
\definecolor{blue}{HTML}{E7E8E8}
\rowcolors{1}{blue}{blue}
\begin{tabular}{ L{5.1cm} C{2cm} }
\multicolumn{2}{L{\dimexpr7.1cm+2\tabcolsep\relax}}{%
\cellcolor{black}\color{white}\textbf{\small Table \ref{tab:variables} - Overview of processes, parameters, and default values of parameters of the Rapa Nui model}} \\
Parameter & Value \\
\specialrule{.1em}{.05em}{.05em}
\textbf{Parameter} & \textbf{Value} \\
\specialrule{.1em}{.05em}{.05em}
Number of territories & 22 \\
Age of sexual maturity (years) & 2 \\
& \\
Winter mortality & \\
Mean of the winter strength distribution (days) & 117\\
\specialrule{.1em}{.05em}{.05em}
\end{tabular}
\end{center}


So far, I have only two complains left:



  • The caption has too much space above, unlike @Mico's example. I did not figure out how to change that!

  • I did not managed to get the above code to function with dcolumn to align numbers suggested by @fldpi


Edit2: my final version (updated Mico's final version of the table)



\begin{center}
\refstepcounter{table} \label{tab:variables}
\definecolor{blue}{HTML}{E7E8E8}
\rowcolors{1}{blue}{blue}
\begin{tabular}{ L{5.1cm} d{3.0} }
\multicolumn{2}{L{\dimexpr7.1cm+2\tabcolsep\relax}}{%
\cellcolor{black}
\bfseries\small%
\textcolor{white}{Table \ref{tab:variables} -- Overview of processes, parameters, and default values of parameters of the marmot model}} \\
Parameter &
\multicolumn{1}{C{2cm}}{Value} \\
\specialrule{.1em}{.05em}{.05em}
Number of territories & 22 \\
Age of sexual maturity (years) & 2 \\[1ex]
Winter mortality & \\
Mean of the winter strength distribution (days) & 117\\
\specialrule{.1em}{.05em}{.05em}
\end{tabular}
\end{center}




Aucun commentaire:

Enregistrer un commentaire