我承认,在处理表格问题时,我处理得很糟糕。
在我的报告中,我想插入跨多页的表格(横向)。所以我使用了\longtable
。
格式化是一个挑战:
- 包含列表的列显示效果不佳
- 必须
\multicolumn
反复使用才能调整多行单元格 - 页码位置不正确。
以下是我所面临的问题的 MWE。
\documentclass{report}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{pdflscape}
\usepackage{afterpage}
\usepackage{makecell}
\renewcommand{\theadfont}{\normalsize\bfseries}
\usepackage{tabularx}
\usepackage{blindtext}
\usepackage{eso-pic,graphicx}
\usepackage{longtable}
\begin{document}
\section{Introduction}
\blindtext
\newpage
\begin{landscape}
\begin{longtable}{lclll }
\toprule
\thead{Algorithm} & \thead{Type of Problem} & \thead{Advantages} & \thead{Disadvantages} & \thead{Common Application areas} \\
\midrule
Decision Trees & \multicolumn{1}{c}{supervised/unsupervised} & \multicolumn{1}{l}{
\begin{itemize}
\item robust to outliers and missing values
\item item 2
\item item 3
\end{itemize}} &list advantages & some application areas\\
\midrule
\end{longtable}
\end{landscape}
\end{document}
答案1
这是一个使用的解决方案长桌和枚举项。此外,我还定义了一个列,通过注入一个\@minipagetrue
和itemize
通过将环境括在 中,将单元格与顶部基线对齐\parbox
。作为奖励(?),我可以删除 -commands\thead
和所有\multicolumn
s:
示例 1
\documentclass{report}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{pdflscape}
\usepackage{array}
\usepackage{blindtext}
\usepackage{longtable}
\usepackage{enumitem}
\makeatletter
\newcolumntype{P}{>{\raggedright\@minipagetrue}p{\dimexpr(3.2cm+2\tabcolsep)}}
\makeatother
\begin{document}
\section{Introduction}
\blindtext
\newpage
\begin{landscape}
\begin{longtable}[c]{@{}lcPll@{}}
\toprule
\bfseries Algorithm & \bfseries Type of Problem & \bfseries Advantages & \bfseries Disadvantages & \bfseries Common Application areas \\
\midrule
Decision Trees & supervised/unsupervised & \parbox[t]{3.2cm}{\begin{itemize}[itemsep=0pt,topsep=0pt, leftmargin=*]
\item robust to outliers and missing values
\item item 2
\item item 3
\end{itemize}} &list advantages & some application areas\\
\midrule
\end{longtable}
\end{landscape}
\end{document}
示例 2
\documentclass{report}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{pdflscape}
\usepackage{array}
\usepackage{blindtext}
\usepackage{longtable}
\usepackage{enumitem}
\makeatletter
\newcolumntype{P}{>{\raggedright\arraybackslash\@minipagetrue}p{\dimexpr(4.5cm+2\tabcolsep)}}
\newcolumntype{O}{>{\centering\arraybackslash}p{3cm}}
\makeatother
\begin{document}
\section{Introduction}
\blindtext
\newpage
\begin{landscape}
\begin{longtable}[c]{@{}lOPll@{}}
\toprule
\bfseries Algorithm & \bfseries Type of Problem & \bfseries Advantages & \bfseries Disadvantages & \bfseries Common Application areas \\
\midrule
Decision Trees & supervised/ unsupervised & \parbox[t]{\linewidth}{\begin{itemize}[itemsep=0pt,topsep=0pt, leftmargin=*]
\item robust to outliers and missing values
\item item 2
\item item 3
\end{itemize}} &list advantages & some application areas\\
\midrule
\end{longtable}
\end{landscape}
\end{document}
答案2
我提出了这个解决方案,它基于对包的重新定义tabularx
,该包带来了tabularx enumitemxltabular
的功能。它远非完美,前两个列标题没有垂直对齐,原因我看不出来。longtable to
, and
\documentclass{report}
\usepackage[utf8]{inputenc}
\usepackage{geometry}
\usepackage{booktabs}
\usepackage{pdflscape}
\usepackage{afterpage}
\usepackage{makecell}
\renewcommand{\theadfont}{\normalsize\bfseries}
\usepackage{tabularx}
\usepackage{blindtext}
\usepackage{eso-pic,graphicx}
\usepackage{longtable, xltabular}
\usepackage{ragged2e, enumitem}
\begin{document}
\section{Introduction}
\blindtext
\newpage
\begin{landscape}
\renewcommand{\tabularxcolumn}[1]{>{\RaggedRight\arraybackslash}m{#1}}
\setlist[itemize]{wide=0pt, leftmargin=*, nosep, before =\vspace*{-\baselineskip}, after=\vspace*{-\baselineskip}}
\begin{xltabular}{\linewidth}{@{}lc *{3}{X}@{}}
\toprule
\thead{Algorithm} & \thead{Type of Problem} & \thead[l]{Advantages} & \thead[l]{Disadvantages}
& \thead{Common Application\\ areas } \\
\midrule
Decision Trees & \multicolumn{1}{c}{supervised/unsupervised} &
\begin{itemize}
\item robust to outliers and missing values
\item item 2
\item item 3
\end{itemize}
&list advantages & some application areas\\
\midrule
\end{xltabular}
\end{landscape}
\end{document}