我想在表格下方添加标题,但我的表格太靠右对齐,我想将其移到左边。
这是我的表格的代码:
\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{array,booktabs}
% added packages and column definitions
\usepackage{ragged2e} % for smart align of cells' content
\usepackage{enumitem} % for nice list
\newlist{tabitemize}{itemize}{1}% <-- defined new list
\setlist[tabitemize]{nosep, % <-- new list setup
topsep = 0pt ,
partopsep = 0pt ,
leftmargin = * ,
label = $\bullet$ ,
before = \vspace{-0.6\baselineskip},
after = \vspace{-\baselineskip}
}
\newcolumntype{I}[1]{>{\RaggedRight\arraybackslash % <-- for lists in columns
\tabitemize} p{#1}<{\endtabitemize}}
\newcommand\mch[1]{\multicolumn{1}{c}{\small{#1}}} % <-- for columns headers
\begin{document}
\newcommand*{\tstack}[1]{%
\begingroup
\renewcommand*{\arraystretch}{1}%
\begin{tabular}[t]{@{}l@{}}#1\end{tabular}%
\endgroup
}
\xdef\BaseLineSkip{\the\baselineskip}
\def\TableCaption{Légende de table}
\begin{tabular}{@{} >{\RaggedRight}p{4cm} *{2}{I{4cm}} @{}}
\toprule
\mch{Méthode de validation}
& \mch{Avantages} & \mch{Inconvénients} \\
\midrule
Resubstitution Validation
& \item simple
\item effortles
& \item Surapprentissage \\
\addlinespace
\bottomrule
\end{tabular}
\end{document}
如何在表格后添加标题并调整表格的对齐方式?
答案1
对于标题,最简单的方法是将表格置于table
浮动环境中并添加标题:
\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{array,booktabs}
% added packages and column definitions
\usepackage{ragged2e} % for smart align of cells' content
\usepackage{enumitem} % for nice list
\newlist{tabitemize}{itemize}{1}% <-- defined new list
\setlist[tabitemize]{nosep, % <-- new list setup
topsep = 0pt ,
partopsep = 0pt ,
leftmargin = * ,
label = $\bullet$ ,
before = \vspace{-0.6\baselineskip},
after = \vspace{-\baselineskip}
}
\newcolumntype{I}[1]{>{\RaggedRight\arraybackslash % <-- for lists in columns
\tabitemize} p{#1}<{\endtabitemize}}
\newcommand\mch[1]{\multicolumn{1}{c}{\small{#1}}} % <-- for columns headers
\usepackage{showframe}% for show page layout
\renewcommand*\ShowFrameColor{\color{red}}
\begin{document}
\begin{table}[htb]
\centering %%%% <-- for horizontal centering table in text
\begin{tabular}{@{} >{\RaggedRight}p{4cm} *{2}{I{3.6cm}} @{}}
\toprule
\mch{Méthode de validation}
& \mch{Avantages} & \mch{Inconvénients} \\
\midrule
Resubstitution Validation
& \item simple
\item effortles
& \item Surapprentissage \\
\bottomrule
\end{tabular}
\caption{My caption below table} %%%% <-- caption
\label{tab:items}
\end{table}
\end{document}
表格比文本宽度略宽,因此我减少了最后两列的宽度。\centering
我将表格水平居中在文本区域。
我删除了代码中所有不相关的部分,并添加了\usepackage{showframe}
显示页面布局的部分。在实际使用中,必须删除此包和以下命令。