如何在 latex 中添加行跨度

如何在 latex 中添加行跨度

嗨,我正在尝试绘制如图所示的表格。有人可以帮忙吗?我试过这段代码,但它不完全像这样工作

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{multirow,tabularx}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\renewcommand{\arraystretch}{2}
\begin{document}\pagestyle{empty}
\begin{tabularx}{\textwidth}{|*{5}{Y|}}
\hline
\multirow{2}{*}{State of Health} 
  &\multicolumn{3}{c|}{Fasting Value}&After Eating\\
\cline{2-4} 
             &Minimum       &Maximum &low &2 hours after eating\\
\hline
Healthy      &70            &100     &a &Less than 140\\
\hline
Pre-Diabetes &101           &126     &a &140 to 200\\
\hline
Diabetes     &More than 126 &N/A     &a &More than 200\\
\hline
\end{tabularx}
\end{document}

在此处输入图片描述

答案1

像这样

在此处输入图片描述

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{multirow,tabularx,booktabs}
\newcolumntype{Y}{>{\arraybackslash}X}
% \renewcommand{\arraystretch}{2}
\begin{document}
\pagestyle{empty}
\begin{tabularx}{0.6\textwidth}{*{5}{Y}}
\toprule
State of Health 
  &\multicolumn{3}{c}{Fasting Value}
   &\multicolumn{1}{c}{After Eating}\\
\cmidrule(r){2-4} \cmidrule(l){5-5}
             &Min     &Max &Low &2 hours\\
\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}

或者

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{multirow,tabularx,booktabs}
\newcolumntype{Y}{>{\arraybackslash}X}
% \renewcommand{\arraystretch}{2}
\begin{document}
\pagestyle{empty}
\begin{tabularx}{0.6\textwidth}{p{3cm}*{3}{Y}p{3cm}}
\toprule
State of Health 
  &\multicolumn{3}{c}{Fasting Value}
   &\multicolumn{1}{c}{After Eating}\\
\cmidrule(r){2-4} \cmidrule(l){5-5}
             &\multicolumn{1}{c}{Min}     &\multicolumn{1}{c}{Max} &\multicolumn{1}{c}{Low} &\multicolumn{1}{c}{2 hours}\\
\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}

在此处输入图片描述

根据评论进行编辑

\documentclass{article}
\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}

在此处输入图片描述

答案2

你的问题不太清楚。假设 MWE(最小工作示例)没有重现显示的图像。因此,

  • 表格应该有多少列
  • 是否需要在行“1”和行“2”之间设置两条水平线,或者它应该位于行“1”之前?
  • 表格左侧的符号是表格的一部分吗?

编辑:考虑了 OP 的评论。

无论如何,您可能喜欢以下表格设计,它采用新tabularray包装,考虑表体中的七列和三行:

\documentclass{article}
\usepackage[showframe,
            margin=1in]{geometry}
\usepackage{tabularray}

\begin{document}
\pagestyle{empty}
    
\noindent\begin{tblr}{%
            hline{1,3,Z}=1pt, hline{2}={solid}, hline{4-Y} ={dashed}, vlines,
            colspec = {l *{6}{X[1,l]}},
            rowsep = 3pt
             }
\SetCell[r=2]{l} State of Health
    & \SetCell[c=3]{c} Fasting Value
        &   &   & \SetCell[c=3]{c} After Eating
                    &   &                       \\ 
    & Minimum   & Maximum   & Low
    & Minimum   & Maximum   & Low   \\
Healthy         & a & a & a     & a & a & a     \\
Pre-Diabetes    & a & a & a     & a & a & a     \\
Diabetes        & a & a & a     & a & a & a     \\
    \end{tblr}
\end{document}

在此处输入图片描述

booktabs或者使用、makecell和包multirow的经典“专业”外观tabularx:-)

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{ragged2e}
\usepackage{booktabs, multirow, makecell, tabularx}
\newcolumntype{L}{>{\RaggedRight}X}
\NewExpandableDocumentCommand\mcc{O{1}m}{\multicolumn{#1}{c}{#2}}

\begin{document}
\pagestyle{empty}
{\setcellgapes{2pt}
 \makegapedcells
\begin{tabularx}{\linewidth}{ l LLl LLl }
    \toprule
\multirow{2.4}{*}{\makecell[l]{State of\\ Health}}
    & \mcc[3]{Fasting Value}    
    & \mcc[3]{After Eating}         \\ 
    \cmidrule(r){2-4}\cmidrule(l){5-7}
    & Minimum   & Maximum   & Low
    & Minimum   & Maximum   & Low   \\
    \midrule
Healthy         & a & a & a     & a & a & a     \\
Pre-Diabetes    & a & a & a     & a & a & a     \\
Diabetes        & a & a & a     & a & a & a     \\
    \bottomrule
\end{tabularx}
}
\end{document}

在此处输入图片描述

相关内容