我正在尝试用 latex 制作表格。但是我无法将我在标题中写的内容居中,后来我还想在每个块下面写一些文字,并且这些文字不在同一行(如果你理解我的意思的话)。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{tikz}
\begin{document}
\listoftables
\vspace{1cm}
\begin{table}[ht]
\caption{Exemplos de Modelos de Previsão de Tráfego}
\label{tab:hla:modelos}
\centering
\begin{tabular}{lllllll}
\toprule
\multicolumn{1}{c}{\parbox{1cm}{\centering\textbf{Paper}}} & \parbox{1cm}{\centering\textbf{Método}} & \parbox{2cm}{\centering\textbf{Fonte\\de\\Dados}} & \parbox{2cm}{\centering\textbf{Parâmetros\\de\\ Entrada}} & \parbox{2cm}{\centering\textbf{Horizonte\\de\\Previsão}} & \parbox{2cm}{\centering\textbf{ Período\\de\\ Estudo}} \\
\midrule
\cite{Beckman08} & ANN & GPS,Detetor de Veículos,Base de dados de incidentes & Velocidade, Volume,Ocupação,Data& Long-term 1 day Short-term 15 min & 1 \\
\cite{Artho03} & 1 & 4 & 1 & 1 & 1 \\
\cite{Artho03} & 1 & 2 & 1 & 1 & 1 \\
\cite{Artho03} & 1 & 1 & 1 & 1 & 1 \\
\cite{Artho04} & 1 & 4 & 1 & 1 & 1 \\
\cite{Artho04} & 0 & 7 & 0 & 1 & 1 \\
\cite{Artho04} & 0 & 2 & 0 & 1 & 1 \\
\cite{Flanagan04} & 1 & 0 & 0 & 1 & 1 \\
\cite{Praun03} & 1 & 1 & 1 & 1 & 1 \\
\cite{Praun03} & 1 & 2 & 1 & 1 & 1 \\
\bottomrule
\end{tabular}
\end{table}
\vspace{1cm}
\end{document}
答案1
像这样?
\documentclass{article}
\usepackage{geometry}
\usepackage[utf8]{inputenc}
\usepackage{ragged2e}
\usepackage{booktabs, makecell, tabularx}
\renewcommand\theadfont{\bfseries\small}
\renewcommand\theadgape{}
\newcolumntype{L}{>{\RaggedRight}X}
\newcommand\mcx[1]{\multicolumn{1}{L}{#1}}
\begin{document}
\begin{table}[ht]
\caption{Exemplos de Modelos de Previsão de Tráfego}
\label{tab:hla:modelos}
\centering
\small
\setlength\tabcolsep{4pt}
\begin{tabularx}{\linewidth}{@{} lc cc c c @{}}%ll ll l
\toprule
\thead[b]{Paper}
& \thead[b]{Método}
& \thead[b]{Fonte\\de Dados}
& \thead[b]{Parâmetros\\de Entrada}
& \thead[b]{Horizonte\\de Previsão}
& \thead[b]{Período\\de Estudo} \\
\midrule
\cite{Beckman08}
& ANN
& \mcx{GPS, Detetor de Veículos, Base de dados de incidentes }
& \mcx{Velocidade, Volume, Ocupação, Data}
& \mcx{Long-term 1 day Short-term 15 min}
& 1 \\
\cite{Artho03} & 1 & 4 & 1 & 1 & 1 \\
\cite{Artho03} & 1 & 2 & 1 & 1 & 1 \\
\cite{Artho03} & 1 & 1 & 1 & 1 & 1 \\
\cite{Artho04} & 1 & 4 & 1 & 1 & 1 \\
\cite{Artho04} & 0 & 7 & 0 & 1 & 1 \\
\cite{Artho04} & 0 & 2 & 0 & 1 & 1 \\
\cite{Flanagan04} & 1 & 0 & 0 & 1 & 1 \\
\cite{Praun03} & 1 & 1 & 1 & 1 & 1 \\
\cite{Praun03} & 1 & 2 & 1 & 1 & 1 \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
答案2
使用tabularx
、 和makecell
简化列标题的代码。此外,还caption
可以在标题和表格之间留出适当的垂直间距:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[showframe]{geometry}
\usepackage{ragged2e}
\usepackage{caption, booktabs, tabularx, makecell}
\renewcommand{\theadfont}{\normalsize\bfseries}
\begin{document}
\listoftables
\vspace{1cm}
\begin{table}[ht]
\caption{Exemplos de Modelos de Previsão de Tráfego}
\setlength{\tabcolsep}{3pt}
\label{tab:hla:modelos}
\centering
\begin{tabularx}{\linewidth}{cc*{3}{ >{\centering}X}c}
\toprule
\thead{Paper} & \thead{Método} & \thead{Fonte\\de Dados} & \thead{Parâmetros\\de Entrada} & \thead{Horizonte\\de Previsão} & \thead{Período\\de Estudo}\\
\midrule
\cite{Beckman08} & ANN & \RaggedRight GPS, Detetor de Veículos, Base de dados de incidentes & \RaggedRight Velocidade, Volume, Ocupação, Data & \RaggedRight Long-term 1 day Short-term 15 min & 1 \\
\cite{Artho03} & 1 & 4 & 1 & 1 & 1 \\
\cite{Artho03} & 1 & 2 & 1 & 1 & 1 \\
\cite{Artho03} & 1 & 1 & 1 & 1 & 1 \\
\cite{Artho04} & 1 & 4 & 1 & 1 & 1 \\
\cite{Artho04} & 0 & 7 & 0 & 1 & 1 \\
\cite{Artho04} & 0 & 2 & 0 & 1 & 1 \\
\cite{Flanagan04} & 1 & 0 & 0 & 1 & 1 \\
\cite{Praun03} & 1 & 1 & 1 & 1 & 1 \\
\cite{Praun03} & 1 & 2 & 1 & 1 & 1 \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}