表格的行/列标签交叉处应放什么?

表格的行/列标签交叉处应放什么?

我有一个带有单独标签行和列。但是,我还想标记这些标签本身(通过指示标签的“类型”,例如 SI 单位等)。

这是一个 MWE,它有三种变体(检查abc/def左上角的条目,描述行标签abc和列标签def):

\documentclass{article}
\begin{document}
\begin{table}
\caption{Forward slash.}
\[\begin{array}{c|ccccc}
abc/def & 1 & 2 & 3 & 4 & 5\\
\hline
1 & a & b & c & d & e\\
2 & f & g & h & i & j\\
3 & k & l & m & n & o\\
\end{array}\]
\end{table}

\begin{table}
\caption{Vertical bar.}
\[\begin{array}{c|ccccc}
abc|def & 1 & 2 & 3 & 4 & 5\\
\hline
1 & a & b & c & d & e\\
2 & f & g & h & i & j\\
3 & k & l & m & n & o\\
\end{array}\]
\end{table}

\begin{table}
\caption{Backslash.}
\[\begin{array}{c|ccccc}
abc\backslash def & 1 & 2 & 3 & 4 & 5\\
\hline
1 & a & b & c & d & e\\
2 & f & g & h & i & j\\
3 & k & l & m & n & o\\
\end{array}\]
\end{table}

\end{document}

在此处输入图片描述

但是,这个 MWE 至少存在以下两个问题:第一列(标记行)太宽,居中的标签距离数组本身的核心太远(右对齐可能会有所帮助,但是……这会引发其他问题)。其次,abc/def 周围的间距看起来不正确。

问题基本上是,我应该如何很好地排版这个数组?我应该把什么放在左上角的位置来代替abc/def?我不希望将abcdef放入两个不同的(多)列中。也许堆叠abc在上方(或下方?)def是一个开始,但我仍然需要在该单元格内使用某种视觉分隔符(充当符号的角色\|/)。我可能还应该澄清标签abcdef实际上都是很短,通常我会写x/yn/mn/k,所以是单字符数学变量,而不是冗长的文本。


有关的:如何创建带有标签的表格(第一行和第一列)

答案1

我建议“三种可能性都不要”。相反,考虑使用经典的“画面”设置,标题中具有清晰的层次结构。这样的设置有助于避免创建“拥挤”的外观,而这几乎是上述三种可能性中不可避免的。

在此处输入图片描述

\documentclass{article}
\usepackage{booktabs}% for \toprule, \midrule, \bottomrule, and \cmidrule macros
\usepackage{amsmath} % for \text macro
\begin{document}
\begin{table}
\caption{Still another approach}
\[
\begin{array}{@{}l*{5}{c}@{}}
\toprule
\text{abc} & \multicolumn{5}{c@{}}{\text{def}}\\
    \cmidrule(l){2-6}
    & 1 & 2 & 3 & 4 & 5\\
\midrule
1 & a & b & c & d & e\\
2 & f & g & h & i & j\\
3 & k & l & m & n & o\\
\bottomrule
\end{array}
\]
\end{table}
\end{document}

答案2

也可以使用 TiZ 直接在表格内,根本不需要保存箱来获取长度:

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{table}
\caption{Diagonal Split}
\[\begin{array}{c|ccccc}
\tikz{\node[below left, inner sep=1pt] (def) {def};%
      \node[above right,inner sep=1pt] (abc) {abc};%
      \draw (def.north west|-abc.north west) -- (def.south east-|abc.south east);}
 & 1 & 2 & 3 & 4 & 5\\
\hline
1 & a & b & c & d & e\\
2 & f & g & h & i & j\\
3 & k & l & m & n & o\\
\end{array}\]
\end{table}
\end{document}

在此处输入图片描述

然后,在\tikz命令里面你有 Tivery thin shortenZ 力量可以做任何事情......这是一个重新定位节点、 ed 分割线和字体的版本\footnotesize

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{table}
\caption{Diagonal Split}
\[\begin{array}{c|ccccc}
\tikz[diag text/.style={inner sep=0pt, font=\footnotesize},
      shorten/.style={shorten <=#1,shorten >=#1}]{%
        \node[below left, diag text] (def) {def};
        \node[above right=2pt and -2pt, diag text] (abc) {abc};
        \draw[shorten=4pt, very thin] (def.north west|-abc.north west) -- (def.south east-|abc.south east);}
 & 1 & 2 & 3 & 4 & 5\\
\hline
1 & a & b & c & d & e\\
2 & f & g & h & i & j\\
3 & k & l & m & n & o\\
\end{array}\]
\end{table}
\end{document}

在此处输入图片描述

答案3

这里有两个选项:

在此处输入图片描述

\documentclass{article}

\usepackage{mathtools,eqparbox}

\newcommand{\indices}[2]{{% \indices{<rows>}{<columns>}
  \begin{array}{@{}r@{}}
    \scriptstyle #2~\smash{\eqmakebox[ind]{$\scriptstyle\rightarrow$}} \\[-\jot]  
    \scriptstyle #1~\smash{\eqmakebox[ind]{$\scriptstyle\downarrow$}}
  \end{array}}}

\begin{document}

\[
  \begin{array}{c|ccccc}
    \indices{\text{abc}}{\text{def}}
    & 1 & 2 & 3 & 4 & 5 \\
    \hline
    1 & a & b & c & d & e \\
    2 & f & g & h & i & j \\
    3 & k & l & m & n & o
  \end{array}
\]

\[
  \begin{array}{cc|ccccc}
    &\multicolumn{1}{c}{} & \multicolumn{5}{c}{\text{def}} \\
    && 1 & 2 & 3 & 4 & 5 \\
    \cline{2-7}
    & 1 & a & b & c & d & e \\
    \smash{\rotatebox[origin=c]{90}{\text{abc}}} & 2 & f & g & h & i & j \\
    & 3 & k & l & m & n & o
  \end{array}
\]

\end{document}

如果你对类似矩阵的命令感兴趣,可以参考以下示例命令在哪里\matrix. 包括使用\bordermatrix,kbordermatrixblkarray,所有这些都允许您放置索引来识别行/列。

答案4

有时我会使用对角线或黑框:

\documentclass{article}
\usepackage{fp}
\usepackage{graphicx}

\newbox\MytempboxA
\newbox\MytempboxB
\newcommand\myTempA{}
\newcommand\myTempB{}
\newcommand\myTempC{}
\newcommand\myTempD{}

\begin{document}

\begin{table}%
\caption{Diagonal line approach}%
\[%
\setbox\MytempboxA\hbox{\mbox{abc}}%
\setbox\MytempboxB\hbox{\mbox{def}}%
\begin{array}{@{}|r|*{5}{c}|}
\hline
\multicolumn{1}{|l}{%
  \edef\myTempA{%
    \number\numexpr\dimexpr\wd\MytempboxA+2\arraycolsep\relax\relax
  }%
  \edef\myTempB{%
    \number
    \numexpr
      \dimexpr\dp\csname @arstrutbox\endcsname+%
              \ht\csname @arstrutbox\endcsname+%
              \arrayrulewidth
      \relax
    \relax
  }%
  \FPpow\myTempC\myTempA{2}%
  \FPpow\myTempD\myTempB{2}%
  \FPadd\myTempC\myTempC\myTempD
  \FProot\myTempC\myTempC{2}% length of diagonal line in sp
  \FPdiv\myTempD\myTempB\myTempA
  \FParctan\myTempD\myTempD% angle of diagonal line in rad
  \smash{%
    \kern-\arraycolsep
    \rlap{%
      \lower
        \dimexpr
          \dp\csname @arstrutbox\endcsname+\arrayrulewidth
        \relax
        \hbox{%
          \rotatebox[units=-6.283185,origin=br]{\myTempD}{%
            \rule{\myTempC sp}{\arrayrulewidth}%
          }%
        }%
    }%
  }%
}&\multicolumn{5}{c|}{\copy\MytempboxB}\\%
\cline{2-6}%
\copy\MytempboxA& 1 & 2 & 3 & 4 & 5\\%
\hline
1 & a & b & c & d & e\\%
2 & f & g & h & i & j\\%
3 & k & l & m & n & o\\%
\hline
\end{array}%
\]%
\end{table}

\begin{table}
\caption{Black box approach}%
\setbox\MytempboxA\hbox{\mbox{abc}}%
\setbox\MytempboxB\hbox{\mbox{def}}%
\[%
\begin{array}{@{}|r|*{5}{c}|}%
\hline
\multicolumn{1}{|l|}{%
  \smash{%
    \kern-\arraycolsep
    \rlap{%
      \rule[{-\dp\csname @arstrutbox\endcsname}]%
           {\dimexpr\wd\MytempboxA+2\arraycolsep\relax}%
           {%
             \dimexpr
               \dp\csname @arstrutbox\endcsname+%
               \ht\csname @arstrutbox\endcsname
             \relax
           }%
    }%
  }%
}&\multicolumn{5}{c|}{\copy\MytempboxB}\\
\hline
\copy\MytempboxA& 1 & 2 & 3 & 4 & 5\\%
\hline
1 & a & b & c & d & e\\%
2 & f & g & h & i & j\\%
3 & k & l & m & n & o\\%
\hline
\end{array}%
\]%
\end{table}


\begin{table}%
\caption{Tangram puzzle approach}%
\[%
\setbox\MytempboxA\hbox{\mbox{abc}}%
\setbox\MytempboxB\hbox{\mbox{def}}%
\begin{array}{@{}|r|*{5}{c}|}
\hline
\multicolumn{1}{|l}{%
  \edef\myTempA{%
    \number\numexpr\dimexpr\wd\MytempboxA+2\arraycolsep\relax\relax
  }%
  \edef\myTempB{%
    \number
    \numexpr
      \dimexpr\dp\csname @arstrutbox\endcsname+%
              \ht\csname @arstrutbox\endcsname+%
              \arrayrulewidth
      \relax
    \relax
  }%
  \FPpow\myTempC\myTempA{2}%
  \FPpow\myTempD\myTempB{2}%
  \FPadd\myTempC\myTempC\myTempD
  \FProot\myTempC\myTempC{2}% length of diagonal line in sp
  \FPdiv\myTempD\myTempB\myTempA
  \FParctan\myTempD\myTempD% angle of diagonal line in rad
  \smash{%
    \kern-\arraycolsep
    \rlap{%
      \lower
        \dimexpr
          \dp\csname @arstrutbox\endcsname+\arrayrulewidth
        \relax
        \hbox{%
          \rotatebox[units=-6.283185,origin=br]{\myTempD}{%
            \rule{\myTempC sp}{\arrayrulewidth}%
          }%
        }%
    }%
  }%
}&\multicolumn{5}{c|}{\copy\MytempboxB}\\%
\copy\MytempboxA& 1 & 2 & 3 & 4 & 5\\%
\cline{2-6}%
1 & a & b & c & d & e\\%
2 & f & g & h & i & j\\%
3 & k & l & m & n & o\\%
\hline
\end{array}%
\]%
\end{table}

\begin{table}
\caption{squares approach}%
\setbox\MytempboxA\hbox{\mbox{abc}}%
\setbox\MytempboxB\hbox{\mbox{def}}%
\[%
\begin{array}{@{}|r|*{5}{c}|}%
\hline
\multicolumn{1}{|l|}{}&\multicolumn{5}{c|}{\copy\MytempboxB}\\
\copy\MytempboxA& 1 & 2 & 3 & 4 & 5\\%
\cline{2-6}%
1 & a & b & c & d & e\\%
2 & f & g & h & i & j\\%
3 & k & l & m & n & o\\%
\hline
\end{array}%
\]%
\end{table}

\end{document}

在此处输入图片描述

在此处输入图片描述

在此处输入图片描述

在此处输入图片描述

有时我会使用类似角度箭头的东西:

\documentclass{article}

\usepackage{tikz}

\newbox\MytempboxA
\newbox\MytempboxB
\newbox\MytempboxC
\newcommand\Upbox[1]{%
  \lower\dimexpr-\ht\MytempboxA+\ht\MytempboxB\relax\hbox{#1}%
  %#1%
}%
\newcommand\leftbox[1]{%
  \hbox to\wd\MytempboxC{\hss#1\hss}\hbox to\wd\MytempboxB{\hfill}%
}%
\begin{document}

\begin{table}%
\caption{Angle arrow.}%
\setbox\MytempboxB=\hbox{\mbox{def}}%
\setbox\MytempboxC=\hbox{\mbox{abc}}%
\setbox\MytempboxA=\hbox{\lower\dp\MytempboxC\vbox{%
  \hbox{%
    \begin{tikzpicture}[x=.25cm, y=.25cm, inner sep=0pt]
    \draw[->,thin] (0,0) -- (1,0) node[right]{\copy\MytempboxB};
    \draw[->,thin] (0,0) -- (0,-1) node[below]{\copy\MytempboxC};
    \end{tikzpicture}%
  }%
}}%
\[%
  \begin{array}{c|ccccc}%
  \copy\MytempboxA&\Upbox{1}&\Upbox{2}&\Upbox{3}&\Upbox{4}&\Upbox{5}\\%
  \hline
  \leftbox{1}& a & b & c & d & e\\%
  \leftbox{2} & f & g & h & i & j\\%
  \leftbox{3} & k & l & m & n & o\\%
  \end{array}%
\]
\end{table}


\begin{table}
\caption{Another angle arrow.}%
\setbox\MytempboxB=\hbox{\mbox{def}}%
\setbox\MytempboxC=\hbox{\mbox{abc}}%
\[%
  \begin{array}{c@{}c|ccccc}%
  \smash{%
    \hbox{%
      \kern.5\wd\MytempboxC
      \lower.75\ht\MytempboxB
      \hbox{%
        \begin{tikzpicture}[x=.25cm, y=.25cm, inner sep=0pt]
        \draw[->,thin] (0,0) -- (1,0) node[right]{};
        \draw[->,thin] (0,0) -- (0,-1) node[below]{};
        \end{tikzpicture}%
      }%
    }%
  }&\copy\MytempboxB&1&2&3&4&5\\%
  \copy\MytempboxC&&\\%
  \hline
  1&& a & b & c & d & e\\%
  2&& f & g & h & i & j\\%
  3&& k & l & m & n & o\\%
  \end{array}%
\]%
\end{table}

\end{document}

在此处输入图片描述

在此处输入图片描述

您还可以使用数组的水平和垂直线创建坐标系轴的外观:

\documentclass{article}

\usepackage{tikz}

\newbox\MytempboxA
\newbox\MytempboxB
\newbox\MytempboxC

\begin{document}

\begin{table}%
\caption{Coordinate axes approach.}%
\setbox\MytempboxC=\hbox{\mbox{abc}}%
\setbox\MytempboxB=\hbox{\mbox{def}}%
\setbox\MytempboxA\hbox{%
  \lower\arrayrulewidth\hbox{%
  \begin{tikzpicture}[x=.25cm, y=.05cm, inner sep=0pt]%
  \draw[->,line width=\arrayrulewidth] (0,1) -- (1,1) node[right]{};
  \end{tikzpicture}%
  }%
}%
\[%
  \begin{array}{c|cccccl}%
  &1&2&3&4&5&\\%
  \cline{1-6}%
  1& a & b & c & d & e&%
  \kern\dimexpr-\arraycolsep-.5\arrayrulewidth\relax\null
  \smash{%
      \lower\dimexpr-\ht\csname @arstrutbox\endcsname+.75\arrayrulewidth+0pt\relax\copy\MytempboxA
      \lower\dimexpr-\ht\csname @arstrutbox\endcsname+0.5ex+.75\arrayrulewidth\relax\copy\MytempboxB
  }%
  \\%
  2 & f & g & h & i & j&\\%
  3 & k & l & m & n & o&\\%
  \multicolumn{1}{r}{}&%
  \multicolumn{6}{l}{%
    \kern\dimexpr-.5\wd\MytempboxC-\arraycolsep\relax\null
    \vbox{%
      \kern\dimexpr-.5\arrayrulewidth\relax\hbox{%
        \begin{tikzpicture}[x=.25cm, y=.075cm, inner sep=0pt]%
        \draw[->,line width=\arrayrulewidth] (0,1) -- (0,-1) node[below]{\copy\MytempboxC};
        \end{tikzpicture}%
      }%
    }%
  }%
  \\%
  \end{array}%
\]
\end{table}

\end{document}

在此处输入图片描述

相关内容