我是 Latex 的新手,我尝试重现一个表格(见上图)作为大学练习。我需要垂直和水平拆分单元格,如图所示。此外,我需要给表格添加标题。使用我的代码,我可以水平拆分行,但对于垂直拆分,我找不到适合我的解决方案。
\begin{document}
\begin{tabular}
\hline
\multicolumn{2}{|l|}{learning process} & learning tools & search space \\
\hline
\multicolumn{2}{|l|}{feature engineering} & (subsequent) classifiers & feature sets \\
\cline{3-3}
\multicolumn{2}{|l|}{} & & feature enhancing methods and their hyper-parameters \\
\hline
\multicolumn{2}{|l|}{model selection} & classifiers & classifiers and their hyper-parameters \\
\hline
\multicolumn{2}{|l|}{optimization algorithm selection} & classifiers & algorithms and their hyper-parameters \\
\hline
\end{tabular}
\caption{\label{tab:table-name}Caption}
\end{document}
编辑:这是我所掌握的有关我的文档类型的信息:
%\documentclass[headsepline,footsepline,footinclude=false,fontsize=11pt,paper=a4,listof=totoc,bibliography=totoc,BCOR=12mm,DIV=12]{scrbook} % two-sided % original source stated: BCOR=12mm,DIV=12 \documentclass[headsepline,footsepline,footinclude=false,oneside,fontsize=11pt,paper=a4,listof=totoc,bibliography=totoc,DIV=12]{scrbook} % one-sided
答案1
看看以下解决方案是否能提供您想要获得的内容:
\documentclass{article}
\usepackage[margin=20mm]{geometry}
\usepackage{multirow}
\newcommand\mcl[1]{\multicolumn{2}{|l|}{#1}}
\begin{document}
\begin{table}
\footnotesize
\sffamily
\renewcommand\arraystretch{1.2}
\centering
\begin{tabular}{|*{4}{l|}}
\hline
\mcl{\textbf{learning process}}
& \textbf{learning tools}
& \textbf{search space} \\
\hline
\mcl{\multirow{2}{*}{feature engineering}}
& \multirow{2}{*}{(subsequent) classifiers}
& feature sets \\
\cline{4-4}
\mcl{}
& & feature enhancing methods and their hyper-parameters \\
\hline
\mcl{model selection}
& classifiers
& classifiers and their hyper-parameters \\
\hline
\mcl{optimization algorithm selection}
& classifiers
& algorithms and their hyper-parameters \\
\hline
\multirow{2}{12mm}{full scope}
& general
& classifiers
& xxx \\
\cline{2-4}
& neural arcitecture search (NAS)
& neural networks
& networtk structure \\
\hline
\end{tabular}
\caption{Caption}
\label{tab:table-name}
\end{table}
\end{document}
附录:
表格使用tabularx
表格环境,可在单元格中启用多行文本:
\documentclass{article}
\usepackage{geometry}
\usepackage{multirow, tabularx}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\newcommand\mcl[1]{\multicolumn{2}{|l|}{#1}}
\begin{document}
\begin{table}
\renewcommand\tabularxcolumn[1]{m{#1}}
\sffamily
\renewcommand\arraystretch{1.2}
\centering
\begin{tabularx}{\linewidth}{|l
|l
|>{\hsize=0.6\hsize}L
|>{\hsize=1.4\hsize}L|}
\hline
\mcl{\textbf{learning process}}
& \textbf{learning tools}
& \textbf{search space} \\
\hline
\mcl{\multirow{3}{*}{feature engineering}}
& \multirow{3}{=}{(subsequent) classifiers}
& feature sets \\
\cline{4-4}
\mcl{}
& & feature enhancing methods and their hyper-parameters \\
\hline
\mcl{model selection}
& classifiers
& classifiers and their hyper-parameters \\
\hline
\mcl{optimization algorithm selection}
& classifiers
& algorithms and their hyper-parameters \\
\hline
\multirow{2}{8mm}{full scope}
& general
& classifiers
& xxx \\
\cline{2-4}
& neural arcitecture search (NAS)
& neural networks
& networtk structure \\
\hline
\end{tabularx}
\caption{Caption}
\label{tab:table-name}
\end{table}
\end{document}
答案2
类似于中的解决方案@Zarko 的回答,不同之处在于(a)它使用一个sidewaystable
环境而不是一个table
环境,因为表格非常宽,如果以横向格式排版则更适合页面(对于纵向格式,需要小而难以阅读的字体大小\footnotesize
),并且(b)使用长度参数的非零值\extrarowheight
以获得更开放的表格“外观”。
\documentclass{article} % or some other suitable document class
\usepackage[a4paper,margin=2cm]{geometry} % set page parameters appropriately
\usepackage{rotating} % for 'sidewaystable' environment
\usepackage{array} % for '\extrarowheight' macro
\usepackage{multirow} % for '\multirow' macro
\begin{document}
\renewcommand\familydefault\sfdefault % optional: switch to sans-serif (globally)
\begin{sidewaystable} % 'table' in landscape mode
\setlength\extrarowheight{2pt} % for a more open 'look'
\centering
\begin{tabular}{|*{4}{l|}}
\hline
\multicolumn{2}{|l|}{\bfseries learning process}
& \bfseries learning tools & \bfseries search space \\
\hline
\multicolumn{2}{|l|}{\multirow{2}{*}{feature engineering}}
& \multirow{2}{*}{(subsequent) classifiers} & feature sets \\
\cline{4-4}
\multicolumn{2}{|l|}{}
& & feature enhancing methods and their hyper-parameters \\
\hline
\multicolumn{2}{|l|}{model selection}
& classifiers & classifiers and their hyper-parameters \\
\hline
\multicolumn{2}{|l|}{optimization algorithm selection}
& classifiers & algorithms and their hyper-parameters\\
\hline
\multirow{2}{*}{full scope} & general
& classifiers & a union of search space in feature, model, and/or algorithm \\
\cline{2-4}
& neural architecture search (NAS) & neural networks & network structures \\
\hline
\end{tabular}
\caption{Caption}\label{tab:table-name}
\end{sidewaystable}
\end{document}