在表格的行/列標籤的交集中放置什麼?

在表格的行/列標籤的交集中放置什麼?

我有一個帶有單獨的網格/表格/矩陣標籤對於行和列。但是,我也想為這些標籤本身加上標籤(透過指示標籤的“類型”,例如 SI 單位等)

abc/def這是一個 MWE,具有三個變體(檢查左上角位置的條目,描述行標籤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

我會建議「三種可能性都不是」。相反,請考慮使用經典的“tableau”設置,在標題中具有清晰的層次結構。這樣的設置有助於避免創建“狹窄”的外觀,這對於您提供的三種可能性中的任何一種來說幾乎都是不可避免的。

在此輸入影像描述

\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

也可以使用鈦kZ 直接在表格內,根本不需要保存箱來取得長度:

\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命令中你有 TikZ 力量可以做任何事...這是一個帶有重新定位節點、very thin shortened 分割線和\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。這包括使用\bordermatrixkbordermatrixblkarray,所有這些都允許您放置索引來標識行/列。

答案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}

在此輸入影像描述

相關內容