我在表格生成方面遇到了问题。
这是我正在使用的代码:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tabularx}
\usepackage{float}
\RequirePackage[a4paper, left=2.5cm, right=2.5cm, bottom=2.5cm, top=2.5cm]{geometry}
\usepackage[usenames, dvipsnames]{color}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{array,multirow,graphicx}
\definecolor{lightgray}{rgb}{0.95,0.95,0.95}
\RequirePackage{ragged2e}
\begin{document}
\renewcommand{\arraystretch}{1.6}
\newcolumntype{Y}{>{\hsize=.7\hsize\RaggedRight\arraybackslash}X}
\newcolumntype{a}{>{\columncolor{lightgray}}Y}
\newcolumntype{C}[1]{>{\columncolor{lightgray}}p{#1}}
\begin{table}[H]
\caption{XXXXXXXXXXXXXXXXXXXXXXX}
\begin{tabularx}{\textwidth}{C{5mm}@{}a*{3}{Y}@{}}
%% table header
\hline
\rowcolor{lightgray}\multicolumn{2}{r@{}}{XXXXXX $\rightarrow$} & \multicolumn{3}{c@{}}{The content of the word} \\
\rowcolor{lightgray}\multicolumn{2}{l@{}}{$\downarrow$ XXXXXX} & XXXXX & XXXXXX & XXXXX \\ \hline
%% body of table
&XXXXX & XXXXX & XXXX & XXXXX \\
&XXXXX
& XXXXX
& XXXXX \par XXXXXXXXXX
& XXXX, \par XXXX,\par XXXX/XXXX,\par XXXXX,\par XXXXXX, etc. \par \\
\multirow{-3}{12mm}{\rotatebox{90}{\parbox{\linewidth}{XXXXXXX}}} &XXXXXX XXXXX & XXXXXXXX \par sequence
& XXXXXX
& XXXXXX, \par XXXXX, \par XXXXX \\ \hline
\end{tabularx}
\end{table}
\end{document}
表格生成正确并且看起来正常,但是显示了很多类似这样的警告:
Overfull \hbox (18.35681pt too wide) in paragraph at lines 35--35
[]\OT1/cmr/m/n/10 XXXXXXX
[]
Overfull \hbox (19.91693pt too wide) in paragraph at lines 35--35
[]|[]|
[]
Underfull \hbox (badness 10000) in alignment at lines 35--35
[][][][][]
[]
先感谢您。
答案1
您收到的只是警告...它们是由于使用RaggedRight
第一列并且定义第一列时不一致而导致的。尝试对表格进行以下更改后的代码:
\documentclass{article}
\usepackage[a4paper, margin=2.5cm]{geometry}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\definecolor{lightgray}{rgb}{0.95,0.95,0.95}
\usepackage{ragged2e}
\usepackage{multirow, tabularx}
\newcolumntype{Y}{>{\raggedright\arraybackslash}X}
\newcolumntype{a}{>{\columncolor{lightgray}}Y}
\newcolumntype{C}[1]{>{\columncolor{lightgray}}p{#1}}
\usepackage{graphicx}
\begin{document}
\renewcommand{\arraystretch}{1.6}
\begin{table}[ht]
\caption{XXXXXXXXXXXXXXXXXXXXXXX}
\begin{tabularx}{\textwidth}{C{12mm} a*{3}{Y}}
%% table header
\hline
\rowcolor{lightgray}
\multicolumn{2}{r}{XXXXXX $\rightarrow$}
& \multicolumn{3}{c}{The content of the word} \\
\rowcolor{lightgray}
\multicolumn{2}{l}{$\downarrow$ XXXXXX}
& XXXXX & XXXXXX & XXXXX \\
\hline
%% body of table
& XXXXX & XXXXX & XXXX & XXXXX \\
& XXXXX & XXXXX & XXXXX XXXXXXXXXX
& XXXX, XXXX,
XXXX/XXXX,
XXXXX, XXXXXX, etc. \\
\multirow{-4}{=}{\rotatebox{90}{XXXXXXX}}
& XXXXXX XXXXX
& XXXXXXXX sequence
& XXXXXX
& XXXXXX, XXXXX, XXXXX \\
\hline
\end{tabularx}
\end{table}
\end{document}
对我来说,表格并不好看。我会使用caption
包来作为标题,省略颜色并用于booktabs
水平线。