设计带有对角线标题的表格时,标题行下方的间隙

设计带有对角线标题的表格时,标题行下方的间隙

我正在尝试制作一个带有对角线标题的表格。为此,我使用了 Heiko Oberdiek 在帖子中的回答中的一些函数 带对角线的特殊表格

我使用 Heiko 的提议创建了以下功能并对其进行了修改,以便具有上下一行、多行支持和增加角度选择的能力:

\usepackage{makecell}
\newcolumntype{M}{>{\centering\arraybackslash}m{3mm}}

\renewcommand*{\arraystretch}{1.5}%

\newcommand*{\headformat}[1]{{\small#1}}%
\newcommand*{\vcorr}{%
      \vadjust{\vspace{-\dp\csname @arstrutbox\endcsname}}%
      \global\let\vcorr\relax
    }%
    \newcommand*{\HeadAux}[5]{%
      \multicolumn{#2}{@{}#3@{}}{%
        \vcorr
        \sbox0{\headformat{\strut #1}}%
        \sbox2{\headformat{Maintenance}}%
        \sbox4{\kern\tabcolsep\redtriangle\kern\tabcolsep}%
        \sbox6{\rotatebox{#4}{\rule{0pt}{\dimexpr\ht0+\dp0\relax}}}%
        \sbox0{\raisebox{0.25\dimexpr\dp0-\ht0\relax}[0pt][0pt]{\unhcopy0}}%

        \dimen0=\dimexpr\wd2+0.5\wd4\relax
       \ifx\HeadLine Y% 
          \rlap{\rotatebox{#5}{\hbox{\vrule width\dimen0 height .4pt}}}%
        \fi
        \kern.75\wd4 %

        \rlap{%
          \raisebox{.1\wd4}{\rotatebox{#4}{\unhcopy0}}%
        }%

        \kern.25\wd4 %
        \ifx\HeadLine Y%
          \rlap{\rotatebox{#5}{\hbox{\vrule width\dimen0 height .4pt}}}%
        \fi
      }%
    }%
    \newcommand*{\head}[1]{\HeadAux{\global\let\HeadLine=Y#1} {1} {r} {45} {45}}%
    \newcommand*{\headNoLine}[1]{\HeadAux{\global\let\HeadLine=N#1} {1} {r} {45} {45}}%
    \newcommand*{\headmulti}[2]{\HeadAux{\global\let\HeadLine=N#1} {#2} {l} {0} {45}}%

然后我在单独的 tex 文件中创建了我的表格,方法如下:

\documentclass[./main.tex]{subfiles}

\begin{document}

\begin{tabular}{%
       >{\bfseries}rM|M|M|M|M|M|M|M|M|M|M%
    }%
    & \head{Maintenance}
    & \head{Flight n-i}
    & \headmulti{\thead{$n^{th}$ - Flight Conditions}}{5}
    & \head{Flight n+i}
    & \head{Maintenance}
    \\
    \toprule
    \sbox0{S}%
      \rule{0pt}{\dimexpr\ht0 + 2ex\relax}%
    Repercussion Phase 
            & {\cellcolor{blue!25}}  & \cellcolor{gray!25}\greencheck
            &\greencheck &\greencheck & \greencheck 
            &\greencheck & \greencheck &  \cellcolor{gray!25}\greencheck 
            & {\cellcolor{blue!25}}\\ 
    \hline
    S1 Detection 
            & {\cellcolor{blue!25}}  & \cellcolor{gray!25}\redtriangle
            & \redtriangle & \redtriangle & \redtriangle 
            & \redtriangle & \redtriangle &  \cellcolor{gray!25}\redtriangle 
            & {\cellcolor{blue!25}}\\ 
    \hline
    Risk Time 
            & {\cellcolor{blue!25}}  & \cellcolor{gray!25}\greencheck 
            &\greencheck & \greencheck & \greencheck 
            &\greencheck&\greencheck&  \cellcolor{gray!25}\greencheck
            & {\cellcolor{blue!25}}\\
    \hline
    \multicolumn{3}{c|}{\multirow{2}{*}{Time(s)}}
            & \multicolumn{5}{c|}{$t_0$}\\
            \cline{3-9}
    \multicolumn{2}{c|}{} & \multicolumn{7}{c|}{Mainteance Time $MT_1$} \\
    \cline{3-9}
    \end{tabular}%
    \kern19.5mm 
\newline
\begin{tabular}{%
      >{\bfseries}lc|>{\quad}c
      *{4}{c|}c>{\quad}c
      *{4}{c|}c>{\quad}c
      *{2}{c|}c%
    }%
      &
      \head{Data Dimensions} &
      &
      \head{Single Input/Output} &
      \head{Statc Rates} &
      \head{Hierachical Memory} &
      \head{Complex Data Movement} &
      \headNoLine{Single Kernel Execution} &
      &
      \head{Application graph} &
      \head{Implicit memory access} &
      \head{Theoretical Framework} &
      \head{Out-of-band control} &
      \headNoLine{Real-time constraints} &
      &
      \head{Data Parallelism} &
      \head{Pipeline Parallelism} &
      \headNoLine{Task Parallelism}
      \\
      \sbox0{S}%
      \rule{0pt}{\dimexpr\ht0 + 2ex\relax}%
      StreamIt & \textcolor{tabred}{\bfseries 1} &&
      \redtriangle & \redtriangle & & & &&
      \greenbullet & \greenbullet & \orangecirc & \greenbullet & &&
      \greenbullet & \greenbullet & \greenbullet
      \\\hline
      StreamC/KernelC & \textcolor{tabred}{\bfseries 1} &&
      & & & & \redtriangle &&
      \greenbullet & \greenbullet & & \greenbullet & &&
      \greenbullet & &
      \\\hline
      SDF & \textcolor{tabred}{\bfseries 1} &&
      & \redtriangle & & & &&
      \greenbullet & \greenbullet & \greenbullet & & &&
      & \greenbullet & \greenbullet
      \\\hline
      MDSDF & \textcolor{tabgreen}{\bfseries\itshape n} &&
      & \redtriangle & & \redtriangle & &&
      \greenbullet & \greenbullet & \greenbullet & & &&
      \greenbullet & \greenbullet & \greenbullet
      \\\hline
      ArrayOL & \textcolor{tabgreen}{\bfseries\itshape n} &&
      & \redtriangle & & \redtriangle & &&
      \greenbullet & \greenbullet & \orangecirc & & &&
      \greenbullet & \greenbullet & \greenbullet
      \\\hline
      Brook & \textcolor{tabgreen}{\bfseries\itshape n} &&
      & & & & \redtriangle &&
      & \greenbullet & & & &&
      \greenbullet & &
      \\\hline
      Sequoia & \textcolor{tabgreen}{\bfseries\itshape n} &&
      & & \redtriangle & \redtriangle & \redtriangle &&
      & & & & &&
      \greenbullet & &
      \\\hline
      \rowcolor{tabyellow}%
      Block-parallel & \textcolor{tabbrown}{\bfseries 2} &&
      & \redtriangle & & & &&
      \greenbullet & \greenbullet & \orangecirc & \greenbullet &
        \greenbullet &&
      \greenbullet & \greenbullet & \greenbullet
      \\[.5ex]
      \multicolumn{3}{c}{} &
      \multicolumn{5}{c}{\bfseries Limitations} &&
      \multicolumn{5}{c}{\bfseries Features} &&
      \multicolumn{3}{c}{\bfseries Parallelism}
      \\
    \end{tabular}%
    \kern19.5mm % manually with the help of the next \vrule
    % \vrule height 50mm
\end{document}

除了标题行和第一个数据原始之间的间隙外,它运行良好(对于初学者来说还不错......)。

带间隙的对角线标题

您知道我可以减少/删除第一行之间的间隙吗?

我尝试修改几个参数,但不幸的是,它什么也没做。我认为问题出在 vcorr 上,

\newcommand*{\vcorr}{%
      \vadjust{\vspace{-\dp\csname @arstrutbox\endcsname}}%
      \global\let\vcorr\relax
    }

我不明白这种行为,也不明白@arstrutbox 的目标。事实上,我发现关于它的信息很少……

此外,如果有人能向我解释如何将水平文本推入多行......?想想看,我必须使用一些余弦和正弦函数来实现完美的行为......

非常感谢您的支持

答案1

您必须使用\specialrule命令,上下填充等于 0pt 才能消除间隙。我擅自用\head更简单的命令(在我看来)替换了这些命令\myrothead,这使列标题的宽度为零,并\rotatebox{45}{{\phantom{longest head}}补偿垂直间距。

请注意,第二个表格太大,无法容纳在页面上,因此也许您应该考虑交换行和列:

\documentclass{article}
\usepackage[utf8]{inputenc} 

\usepackage[T1]{fontenc} 
\usepackage{booktabs, multirow} 
\usepackage[table]{xcolor} 
\usepackage{rotating, graphicx}
\usepackage{amsmath, amssymb} 
\usepackage{bbding} 
\newcommand*{\redtriangle}{\ensuremath{\color{red}{\triangle}}}
\newcommand*{\greencheck}{\ensuremath{\color{green}{\XSolidBrush}}}
\newcommand*{\greenbullet}{\color{green}{\textbullet}}
\newcommand*{\orangecirc}{\ensuremath{\color{orange}{\circ}}}
\colorlet{tabred}{red}
\colorlet{tabgreen}{green}
\colorlet{tabyellow}{yellow}
\colorlet{tabbrown}{brown}

    \usepackage{makecell}
    \newcolumntype{M}{>{\centering\arraybackslash}m{3mm}}

    \renewcommand*{\arraystretch}{1.5}%

    \newcommand\myrothead[1]{ \multicolumn{1}{c}{\rothead {\rlap{#1}}}}
    \usepackage{lipsum}
    \begin{document}
    \lipsum[2]
    \renewcommand{\theadfont}{\small}
    \renewcommand{\cellrotangle}{45}
    \begin{tabular}{%
           >{\bfseries}rM|M|M|M|M|M|M|M|M|M|M%
        }%
    \rotatebox{45}{\phantom{\theadfont Maintenance}} & \myrothead{Maintenance}
        & \myrothead{Flight n-i} 
        & \multicolumn{5}{c}{\thead[b]{$n^\text{th}$ - Flight Conditions}}{5}
        &\myrothead {Flight n+i}
        & \myrothead{Maintenance}
        \\
 \specialrule{\heavyrulewidth}{0pt}{0pt}%\toprule%\addlinespace[-\belowrulesep]
 \sbox0{S}%
 \rule{0pt}{\dimexpr\ht0 + 2ex\relax}%
        Repercussion Phase
                & {\cellcolor{blue!25}} & \cellcolor{gray!25}\greencheck
                &\greencheck &\greencheck & \greencheck
                &\greencheck & \greencheck & \cellcolor{gray!25}\greencheck
                & {\cellcolor{blue!25}}\\
        \hline
        S1 Detection
                & {\cellcolor{blue!25}} & \cellcolor{gray!25}\redtriangle
                & \redtriangle & \redtriangle & \redtriangle
                & \redtriangle & \redtriangle & \cellcolor{gray!25}\redtriangle
                & {\cellcolor{blue!25}}\\
        \hline
        Risk Time
                & {\cellcolor{blue!25}} & \cellcolor{gray!25}\greencheck
                &\greencheck & \greencheck & \greencheck
                &\greencheck&\greencheck& \cellcolor{gray!25}\greencheck
                & {\cellcolor{blue!25}}\\
        \hline
        \multicolumn{3}{c|}{\multirow{2}{*}{Time(s)}}
                & \multicolumn{5}{c|}{$t_0$}\\
                \cline{3-9}
        \multicolumn{2}{c|}{} & \multicolumn{7}{c|}{Maintenance Time $MT_1$} \\
        \cline{3-9}
        \end{tabular}%
        \kern19.5mm
    \newline
    \begin{tabular}{%
          >{\bfseries}lc|>{\quad}c
          *{4}{c|}c>{\quad}c
          *{4}{c|}c>{\quad}c
          *{2}{c|}c%
        }%
    \rotatebox{45}{\phantom{\theadfont Complex Data Movement}}
          &
          \myrothead{Data Dimensions} &
          &
          \myrothead{Single Input/Output} &
          \myrothead{Statc Rates} &
          \myrothead{Hierachical Memory} &
          \myrothead{Complex Data Movement} &
          \myrothead{Single Kernel Execution} &
          &
          \myrothead{Application graph} &
          \myrothead{Implicit memory access} &
          \myrothead{Theoretical Framework} &
          \myrothead{Out-of-band control} &
          \myrothead{Real-time constraints} &
          &
          \myrothead{Data Parallelism} &
          \myrothead{Pipeline Parallelism} &
          \myrothead{Task Parallelism}
          \\
          \sbox0{S}%
          \rule{0pt}{\dimexpr\ht0 + 2ex\relax}%
          StreamIt & \textcolor{tabred}{\bfseries 1} &&
          \redtriangle & \redtriangle & & & &&
          \greenbullet & \greenbullet & \orangecirc & \greenbullet & &&
          \greenbullet & \greenbullet & \greenbullet
          \\\hline
          StreamC/KernelC & \textcolor{tabred}{\bfseries 1} &&
          & & & & \redtriangle &&
          \greenbullet & \greenbullet & & \greenbullet & &&
          \greenbullet & &
          \\\hline
          SDF & \textcolor{tabred}{\bfseries 1} &&
          & \redtriangle & & & &&
          \greenbullet & \greenbullet & \greenbullet & & &&
          & \greenbullet & \greenbullet
          \\\hline
          MDSDF & \textcolor{tabgreen}{\bfseries\itshape n} &&
          & \redtriangle & & \redtriangle & &&
          \greenbullet & \greenbullet & \greenbullet & & &&
          \greenbullet & \greenbullet & \greenbullet
          \\\hline
          ArrayOL & \textcolor{tabgreen}{\bfseries\itshape n} &&
          & \redtriangle & & \redtriangle & &&
          \greenbullet & \greenbullet & \orangecirc & & &&
          \greenbullet & \greenbullet & \greenbullet
          \\\hline
          Brook & \textcolor{tabgreen}{\bfseries\itshape n} &&
          & & & & \redtriangle &&
          & \greenbullet & & & &&
          \greenbullet & &
          \\\hline
          Sequoia & \textcolor{tabgreen}{\bfseries\itshape n} &&
          & & \redtriangle & \redtriangle & \redtriangle &&
          & & & & &&
          \greenbullet & &
          \\\hline
          \rowcolor{tabyellow}%
          Block-parallel & \textcolor{tabbrown}{\bfseries 2} &&
          & \redtriangle & & & &&
          \greenbullet & \greenbullet & \orangecirc & \greenbullet &
            \greenbullet &&
          \greenbullet & \greenbullet & \greenbullet
          \\[.5ex]
          \multicolumn{3}{c}{} &
          \multicolumn{5}{c}{\bfseries Limitations} &&
          \multicolumn{5}{c}{\bfseries Features} &&
          \multicolumn{3}{c}{\bfseries Parallelism}
          \\
        \end{tabular}%
        \kern19.5mm % manually with the help of the next \vrule
        % \vrule height 50mm

    \end{document} 

在此处输入图片描述

答案2

谢谢@Bernard,我修改了代码。这里是用于头部描述的代码

\usepackage{pifont}
\usepackage{makecell}
\newcolumntype{M}{>{\centering\arraybackslash}m{3mm}}
\renewcommand*{\arraystretch}{1.5}
\newcommand*{\headformat}[1]{{\small#1}}
    \newcommand*{\HeadAux}[5]{%
      \multicolumn{#2}{@{}#3@{}}{%
        \sbox0{\headformat{\strut #1}}%
        \sbox2{\headformat{Maintenance}}%
        \sbox4{\kern\tabcolsep\redtriangle\kern\tabcolsep}%
        \sbox0{\raisebox{0.25\dimexpr\dp0-\ht0\relax}[0pt][0pt]{\unhcopy0}}%
        \dimen0=\dimexpr\wd2+0.5\wd4\relax
       \ifx\HeadLine Y% 
          \rlap{\rotatebox{#5}{\hbox{\vrule width\dimen0 height .4pt}}}%
        \fi
        \kern.75\wd4 %
        \rlap{%
          \raisebox{0.1\wd4}{\rotatebox{#4}{\unhcopy0}}%
        }%
        \kern.25\wd4 %
        \ifx\HeadLine Y%
          \rlap{\rotatebox{#5}{\hbox{\vrule width\dimen0 height .4pt}}}%
        \fi
      }%
    }%
    \newcommand*{\head}[1]{\HeadAux{\global\let\HeadLine=Y#1} {1} {r} {45} {45}}%
    \newcommand*{\headNoLine}[1]{\HeadAux{\global\let\HeadLine=N#1} {1} {r} {45} {45}}%
    \newcommand*{\headmulti}[2]{\HeadAux{\global\let\HeadLine=N#1} {#2} {l} {0} {45}}%

我使用以下几行创建了表格:

\begin{tabular}{%
       >{\bfseries}rM|M|M|M|M|M|M|M|M|M|M%
    }%

    & \head{Maintenance}
    & \head{Flight n-i}
    & \headmulti{\thead{$n^{th}$ - Flight Conditions}}{5}
    & \head{Flight n+i}
    & \head{Maintenance}\\
    \specialrule{\heavyrulewidth}{-5.5pt}{0pt}%\toprule%\addlinespace[-\belowrulesep]
    Repercussion Phase 
            & {\cellcolor{blue!25}}  & \cellcolor{gray!25}\greencheck
            &\greencheck &\greencheck & \greencheck 
            &\greencheck & \greencheck &  \cellcolor{gray!25}\greencheck 
            & {\cellcolor{blue!25}}\\ 
    \hline
    S1 Detection 
            & {\cellcolor{blue!25}}  & \cellcolor{gray!25}\redtriangle
            & \redtriangle & \redtriangle & \redtriangle 
            & \redtriangle & \redtriangle &  \cellcolor{gray!25}\redtriangle 
            & {\cellcolor{blue!25}}\\ 
    \hline
    Risk Time 
            & {\cellcolor{blue!25}}  & \cellcolor{gray!25}\greencheck 
            &\greencheck & \greencheck & \greencheck 
            &\greencheck&\greencheck&  \cellcolor{gray!25}\greencheck
            & {\cellcolor{blue!25}}\\
    \hline
    \multicolumn{3}{c|}{\multirow{2}{*}{Time(s)}}
            & \multicolumn{5}{c|}{$t_0$}\\
            \cline{3-9}
    \multicolumn{2}{c|}{} & \multicolumn{7}{c|}{Mainteance Time $MT_1$} \\
    \cline{3-9}
    \end{tabular}%

应手动调整 {\heavyrulewidth}{-5.5pt}{0pt}... 以避免表格头部和子部分之间的间隙。

相关内容