我正在研究 overleaf,需要绘制一个像图中所示的表格。我有这个代码,但是当我尝试修改它时出现了错误
\documentclass{IEEEtran}
\usepackage{graphicx}
\usepackage[margin=1in]{geometry}
\usepackage{multirow,tabularx,booktabs}
\newcolumntype{Y}{>{\arraybackslash}X}
% \renewcommand{\arraystretch}{2}
\begin{document}
\pagestyle{empty}
\begin{tabularx}{\textwidth}{p{3cm}*{6}{Y}}
\toprule
State of Health
&\multicolumn{3}{c}{Fasting Value}
&\multicolumn{3}{c}{After Eating}\\
\cmidrule(r){2-4} \cmidrule(l){5-7}
&{Min}
&{Max}
&{Low}
&2hrs
&3hrs
&4hrs\\
\midrule
Healthy
&70
&100
&a
&$<$ 140
&
&\\
\midrule
Pre-Diabetes
&101
&126
&a
&140 -- 200
&
&\\
\midrule
Diabetes
&$>$126
&N/A
&a
&$>$ 200
&
&\\
\bottomrule
\end{tabularx}
\end{document}
答案1
问题不完全清楚,只是在表格开头插入了一个额外的行。您只需向l
列规范添加额外的列说明符(例如),并在现有列之前插入文本,如下所示。
\documentclass{IEEEtran}
\usepackage{graphicx}
%\usepackage[margin=1in]{geometry}
\usepackage{booktabs, multirow,tabularx}
\newcolumntype{Y}{>{\arraybackslash}X}
\begin{document}
\pagestyle{empty}
\begin{tabularx}{\textwidth}{l p{3cm}*{6}{Y}}
\toprule
text & State of Health
&\multicolumn{3}{c}{Fasting Value}
&\multicolumn{3}{c}{After Eating}\\
\cmidrule(r){3-5} \cmidrule(l){6-8}
& & Min
& Max
& Low
& 2hrs
& 3hrs
& 4hrs\\
\midrule
text & Healthy
&70
&100
&a
&$<$ 140
&
&\\
\midrule
text & Pre-Diabetes
&101
&126
&a
&140 -- 200
&
&\\
\midrule
text & Diabetes
&$>$126
&N/A
&a
&$>$ 200
&
&\\
\bottomrule
\end{tabularx}
\end{document}
答案2
以下屏幕截图中的第一个表格显示了在环境开始时添加一列的结果tabularx
。(它还将 6 个数据列的内容居中。)总体而言,我认为这个表格看起来不是特别好。屏幕截图中的第二个表格显示了使用基本环境的结果tabular
。我认为它比基于的表格更容易阅读tabularx
。
\documentclass{IEEEtran}
\usepackage[margin=1in]{geometry}
\usepackage{tabularx,booktabs}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\begin{document}
\begin{table*}
\caption{Solution with \texttt{tabularx}}
\begin{tabularx}{\textwidth}{@{} ll *{6}{Y} @{}}
\toprule
Heading 1 & State of Health
&\multicolumn{3}{c}{Fasting Value}
&\multicolumn{3}{c}{After Eating}\\
\cmidrule(lr){3-5} \cmidrule(l){6-8}
& &{Min} &{Max} &{Low} &2hrs &3hrs &4hrs\\
\midrule
add & Healthy &70 &100 &a &$< 140$ & &\\
\addlinespace %\midrule
del & Pre-Diabetes &101 &126 &a & 140--200 & &\\
\addlinespace %\midrule
mult & Diabetes &$>126$ &N/A &a & $>200$ & &\\
\bottomrule
\end{tabularx}
\bigskip\bigskip
\centering
\caption{Solution with \texttt{tabular}}
\begin{tabular}{@{} ll *{6}{c} @{}}
\toprule
Heading 1 & State of Health
&\multicolumn{3}{c}{Fasting Value}
&\multicolumn{3}{c}{After Eating}\\
\cmidrule(lr){3-5} \cmidrule(l){6-8}
& &{Min} &{Max} &{Low} &2hrs &3hrs &4hrs\\
\midrule
add & Healthy &70 &100 &a &$< 140$ & &\\
\addlinespace %\midrule
del & Pre-Diabetes &101 &126 &a & 140--200 & &\\
\addlinespace %\midrule
mult & Diabetes &$>126$ &N/A &a & $>200$ & &\\
\bottomrule
\end{tabular}
\end{table*}
\end{document}