I am new to Latex. I have been recommended Overleaf, which I like as there are templates for theses - which is my current project.
However, as I produce many tables in my thesis, I would like to add further formatting which I would like to always be present in any table I produce. Table formatting is done in the table with "renewenvironment". See the code - which works fine - just below.
Code: Select all
% Table formatting
\let\table@default\table
\let\endtable@default\endtable
\define@key{table}{caption}{\newcommand{\table@caption}{#1}}
\define@key{table}{toc}{\newcommand{\table@toc}{#1}}
\define@key{table}{label}{\newcommand{\table@label}{#1}}
\define@key{table}{columns}{\newcommand{\table@columns}{#1}}
\define@key{table}{placement}{\newcommand{\table@placement}{#1}}
\renewenvironment{table}[1][]{%
\begingroup%
% Insert keys from above
\setkeys{table}{#1}%
\newcommand{\table@internal@placement}{H}%
\expandafter\table@default\expandafter[\table@internal@placement]%
\ifthenelse{\isundefined{\table@toc}}{%
% Without dedicated TOC caption
\caption{\table@caption\label{\table@label}}%
}{%
% With dedicated TOC caption
\caption[\table@toc]{\table@caption\label{\table@label}}%
}%
% \beginntabular%
}{%
% \endtabular%
\endtable@default%
\endgroup%
}
I would like to
- 1. always center the table
2. align the table to the "textwidth" when the table is bigger than the textwith (). If it is not, keep the original size (and don't stretch it)Code: Select all
\resizebox{\textwidth}{!}{}
3. Caption at the top, centered
4. I actually convert tables from R to TEX. I already define the caption in R. The R package "xtable" then lists the caption right before. But in the environment that can be seen above, the caption is an input afterCode: Select all
\end{table}
. Now, I always have to cut the caption from the R output and insert it into the right place. Can I somehow automate this?Code: Select all
\begin{table}
5. add \toprule, \cmidrule, and \bottomrule
I know this is a lot, but any help is greatly appreciated. Thank you in advance!
Alexander