问题:
我想要生成一个类似(表格#2)的表格,该表格对于一个父列有两个子列,但我还希望此表格遵守页边距且不会从其余表格中突出来。 (我页面上的其他表格与表格#1类似,不需要子标题。)这种不遵守页边距的情况发生在较短和较长的表格中。
我从表 #1 中得到了部分信息。有人可以提供一些专业知识或指导吗?
梅威瑟:
\documentclass{letter}
\usepackage[explicit]{titlesec}
\usepackage[letterpaper, inner=18mm, outer=18mm, top=8mm, bottom=25mm]{geometry}
\usepackage{tabularx}
\usepackage{graphicx}
\let\svtikzpicture\tikzpicture
\def\tikzpicture{\noindent\svtikzpicture}
\usepackage[scaled]{helvet}
\renewcommand\familydefault{\sfdefault}
\usepackage[T1]{fontenc}
\usepackage{multirow}
\usepackage[table,xcdraw]{xcolor}
\usepackage{parskip}
\newcolumntype{x}{>{\centering\arraybackslash}X}
\newcolumntype{M}{>{\centering\arraybackslash}m{2cm}}
\newcolumntype{Y}{>{\raggedleft\arraybackslash}p{4cm}}
\begin{document}
\begingroup
\renewcommand{\tabularxcolumn}[1]{>{\small}m{#1}}
\rowcolors{1}{}{gray!15}
Obeys margin rules but doesn't quite give me the functionality of the multicolumn to span multiple columns..
I noticed this table also wraps it's column headers..
\begin{tabularx}{\textwidth}{Mxxxxxxxxxxxx }
\rowcolor{black}
\multicolumn{ 13 }{l}{\tiny\textbf{ Non-Multicolumn Table }} \\
\rowcolor{black!60}
\tiny
& \tiny Long Desc
& \tiny
& \tiny Longer Desc
& \tiny
& \tiny Even Longer Description
& \tiny Even Longer Description
& \tiny Normal
& \tiny
& \tiny Short
& \tiny
& \tiny An Even Longer Description
& \tiny
\\
\rowcolor{black!40}
\tiny
& \tiny child data 1
& \tiny child data 2
& \tiny child data 1
& \tiny child data 2
& \tiny
& \tiny
& \tiny child data 1
& \tiny child data 2
& \tiny child data 1
& \tiny child data 2
& \tiny child data 1
& \tiny child data 2
\\
\tiny price
& \tiny price
& \tiny price
& \tiny price
& \tiny price
& \tiny
& \tiny
& \tiny price
& \tiny price
& \tiny price
& \tiny price
& \tiny price
& \tiny price
\\
\end{tabularx}
Does not obey Margin rules but gives me the functionality for multiple column spanning
I noticed this table does not wrap it's headers, and forces the table to expand their length.
\begin{tabularx}{\textwidth}{Mxxxxxxxxxxxx }
\rowcolor{black}
\multicolumn{ 13 }{l}{\tiny\textbf{ Multicolumn Table }} \\
\rowcolor{black!60}
\multicolumn{1}{c}{\tiny }
& \multicolumn{2}{c}{\tiny Long Desc }
& \multicolumn{2}{c}{\tiny Longer Desc }
& \multicolumn{1}{c}{\tiny A description so very long that you probably didn't read it all }
& \multicolumn{1}{c}{\tiny Even Longer Description }
& \multicolumn{2}{c}{\tiny Normal }
& \multicolumn{2}{c}{\tiny Short }
& \multicolumn{2}{c}{\tiny An even longer description }
\\
\rowcolor{black!40}
\multicolumn{1}{c}{\tiny }
& \multicolumn{1}{c}{\tiny child data }
& \multicolumn{1}{c}{\tiny child data}
& \multicolumn{1}{c}{\tiny child data}
& \multicolumn{1}{c}{\tiny child data}
& \multicolumn{1}{c}{\tiny }
& \multicolumn{1}{c}{\tiny }
& \multicolumn{1}{c}{\tiny child data}
& \multicolumn{1}{c}{\tiny child data}
& \multicolumn{1}{c}{\tiny child data}
& \multicolumn{1}{c}{\tiny child data}
& \multicolumn{1}{c}{\tiny child data}
& \multicolumn{1}{c}{\tiny child data}
\\
\rowcolor{white}
\multicolumn{1}{c}{\tiny Text }
& \multicolumn{1}{c}{\tiny Text }
& \multicolumn{1}{c}{\tiny Text }
& \multicolumn{1}{c}{\tiny Text }
& \multicolumn{1}{c}{\tiny Text }
& \multicolumn{1}{c}{\tiny Text }
& \multicolumn{1}{c}{\tiny Text }
& \multicolumn{1}{c}{\tiny Text }
& \multicolumn{1}{c}{\tiny Text }
& \multicolumn{1}{c}{\tiny Text }
& \multicolumn{1}{c}{\tiny Text }
& \multicolumn{1}{c}{\tiny Text }
& \multicolumn{1}{c}{\tiny Text }
\\
\end{tabularx}
\medskip
This uses multicolumn headers and regular body. As you can see the multicolumn doesn't quite match up to the cell.
\begin{tabularx}{\textwidth}{Mxxxxxxxxxxxx }
\rowcolor{black}
\multicolumn{ 13 }{l}{\tiny\textbf{ Multicolumn Table }} \\
\rowcolor{black!60}
\multicolumn{1}{c}{\tiny }
& \multicolumn{2}{c}{\tiny Long Desc }
& \multicolumn{2}{c}{\tiny Longer Desc }
& \multicolumn{1}{c}{\tiny A description so very long that you probably didn't read it all }
& \multicolumn{1}{c}{\tiny Even Longer Description }
& \multicolumn{2}{c}{\tiny Normal }
& \multicolumn{2}{c}{\tiny Short }
& \multicolumn{2}{c}{\tiny An even longer description }
\\
\rowcolor{black!40}
{\tiny }
& {\tiny child data }
& {\tiny child data}
& {\tiny child data}
& {\tiny child data}
& {\tiny }
& {\tiny }
& {\tiny child data}
& {\tiny child data}
& {\tiny child data}
& {\tiny child data}
& {\tiny child data}
& {\tiny child data}
\\
\rowcolor{white}
{\tiny Text }
& {\tiny Text }
& {\tiny Text }
& {\tiny Text }
& {\tiny Text }
& {\tiny Text }
& {\tiny Text }
& {\tiny Text }
& {\tiny Text }
& {\tiny Text }
& {\tiny Text }
& {\tiny Text }
& {\tiny Text }
\\
\end{tabularx}
\endgroup
\end{document}