[英]Centering the latex table in the page
I have the following table in LaTeX
, and although I have used the \centering
in the code, it is not centred when knitted.我在
LaTeX
中有下表,虽然我在代码中使用了\centering
,但在编织时它没有居中。 In addition it extends more than the text width as shown in the figure below此外,它超出了文本宽度,如下图所示
\begin{table}[H]
\centering
\caption[mnodels summary]{Summary results of the models \label{tab:modelssummary}}
\begin{tabular}{cccccc}
\toprule
\multicolumn{6}{c}{~ \textbf{~~Models Performance }} \\
\hline
\textbf{Model} & \textbf{Residual Mean} & \textbf{Constant Variance} & \textbf{Autocorrelation} & \textbf{Adj. R-Squared} & \textbf{AIC} \\
\hline\hline
\textbf{Model 1} & OK & OK & YES & 0.83 & 4804.8 \\
\textbf{Model 2} & OK & OK & YES & 0.84 & 4569.5 \\
\textbf{Model 3} & OK & OK & YES & 0.83 & 4763.7 \\
\textbf{Model 4} & OK & OK & YES & 0.87 & 3760.5 \\
\textbf{Model 5} & OK & OK & YES & 0.86 & 3964.5 \\
\textbf{Model 6} & No & No & YES & 0.32 & 10879.7~ \\
\textbf{Model 7} & No & No & YES & 0.80 & 5434.2 \\
\bottomrule
\end{tabular}
\end{table}
and it will look like this:它看起来像这样:
How can I resolve this?我该如何解决这个问题?
If you accept multi lines in headings and abbreviations, you can squeeze the table and even fit within the default latex page.如果您接受标题和缩写中的多行,您可以压缩表格,甚至适合默认的 latex 页面。 Then,
\centering
will work然后,
\centering
将工作
and the code和代码
\documentclass{article}
\usepackage{booktabs}
\usepackage{caption}
\captionsetup[table]{position=top,skip=6pt}
\usepackage{makecell}
\usepackage{ragged2e} % Centering
\usepackage{siunitx} % S[...]
% Makecell - settings
\renewcommand\theadfont{\normalsize\normalfont\bfseries}
\renewcommand\theadalign{tc}
% Custom column types
\newcolumntype{C}{>{\Centering\bfseries}p{1.4cm}}
\newcolumntype{P}[1]{>{\Centering}p{#1}}
\begin{document}
\begin{table}[tbh]
\centering
\setlength\tabcolsep{0pt}
\caption[mnodels summary]{Summary results of the models}\label{tab:modelssummary}
\begin{tabular}{
C @{\hspace{1em}}
*4{P{1.25cm}}
@{\hspace{0.75em}}
S[group-minimum-digits=4,table-format=4.1]
}
\toprule
& \multicolumn{5}{c}{\textbf{Models Performance}} \\
\cmidrule{2-6}
\thead{Model}
& \thead{Resid.\\Mean}
& \thead{Const.\\Var.}
& \thead{Auto\\corr.}
& \thead{Adj.\\R\textsuperscript{2}}
& {\thead{AIC}} \\ % {} required for S[] to work
\midrule\midrule
1 & OK & OK & YES & 0.83 & 4804.8 \\
2 & OK & OK & YES & 0.84 & 4569.5 \\
3 & OK & OK & YES & 0.83 & 4763.7 \\
4 & OK & OK & YES & 0.87 & 3760.5 \\
5 & OK & OK & YES & 0.86 & 3964.5 \\
6 & No & No & YES & 0.32 & 10879.7 \\
7 & No & No & YES & 0.80 & 5434.2 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.