표의 셀 상단 모서리에 테두리가 있는 작은 셀을 만드는 방법은 무엇입니까?

표의 셀 상단 모서리에 테두리가 있는 작은 셀을 만드는 방법은 무엇입니까?

여기에 이미지 설명을 입력하세요테두리가 있는 테이블의 셀 상단 모서리에 있는 노드를 가져오고 테이블의 빈 셀 정렬을 방해하지 않는 방법은 무엇입니까?

\documentclass[12pt]{standalone}
\usepackage{tikz}
\usepackage{array}
\begin{document}
\begin{tabular}{|c|c|c|c|c}\cline{1-4} 
20 \raisebox{0.2cm}{\small 4} & \raisebox{0.2cm}{\small 6} & \raisebox{0.2cm}{\small 8} & \raisebox{0.2cm}{\small 8} & 40\\ 
\cline{1-4} 
& & & & 60\\ \cline{1-4} 
& & & & 50 \\ \cline{1-4} 
\multicolumn{1}{c}{20} & \multicolumn{1}{c}{30} & \multicolumn{1}{c}{50} & \multicolumn{1}{c}{50} & 
150\\ 
\end{tabular}

답변1

Ti와 함께케이Z 이건 매우 쉽습니다. 이 답변은 inlay이에 사용할 수 있는 스타일을 정의합니다 . 해당 셀에 추가할 수 있습니다.

|[inlay=<content>]|

암호:

\documentclass[tikz,border=3mm]{standalone}
\usepackage{amsmath}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}[mmat/.style={matrix of math nodes,nodes in empty cells,
        row sep=-\pgflinewidth,column sep=-\pgflinewidth,
        nodes={minimum width=5.5em,minimum height=3.5em,
            draw,anchor=center,
            text depth=0.25ex,text height=0.8em}},
        inlay/.style={label={[draw,thin,anchor=north east,minimum width=0em,
        minimum height=0em,inner sep=1.4pt]north east:#1}}]
 \matrix[mmat] (mat){
 &  P & Q & R & S & \textit{Supply} \\
 A & |[inlay=180]| 12& |[inlay=150]| 10 & |[inlay=170]| 12 & 13 & 500 \\
 };         
 \draw (mat-1-1.north west) -- (mat-1-1.south east);
 \draw[stealth-] ([yshift=2ex,xshift=-0.5ex]mat-1-1.east) 
    -- ++ (-2ex,0) node[left,font=\itshape]{To};
 \draw[stealth-] ([xshift=3ex,yshift=0.5ex]mat-1-1.south west) 
    -- ++ (0,2ex) node[above,font=\itshape]{From};
\end{tikzpicture}
\end{document}

여기에 이미지 설명을 입력하세요

답변2

{NiceArray}다음은 of 를 사용한 솔루션입니다 nicematrix. 해당 환경은 {nicearray}(의 ) 클래식 환경과 유사 array하지만 셀, 행 및 열 아래에 PGF/Tikz 노드를 생성합니다. 저는 이 노드를 사용하여 배열 구성 후 작은 모서리를 추가합니다.

\documentclass{article}
\usepackage{nicematrix,tikz}

\ExplSyntaxOn
\makeatletter
\cs_new_protected:Nn \__rakatex_draw_angle:nnn 
  { 
    \begin{tikzpicture}
    \draw ([xshift=-5.5mm]#1-|#2) |- ([yshift=-4mm]#1-|#2) ; 
    \node at ([xshift=-2.75mm,yshift=-2mm]#1-|#2) { \small #3 } ;
    \end{tikzpicture}
  }

\NewDocumentCommand{\Cell}{mm}
  {
    #1
    \tl_gput_right:Nx \g_nicematrix_code_after_tl
      { 
        \__rakatex_draw_angle:nnn
          { \int_use:N \c@iRow } 
          { \int_eval:n { \c@jCol + 1 } } 
          { #2 } 
      }
  }
\makeatother
\ExplSyntaxOff

\begin{document}

\renewcommand{\arraystretch}{2}
$\begin{NiceArray}{c*{4}{wc{1.5cm}}c}[hvlines]
\diagbox{\downarrow\emph{From}}{\emph{To}\to}& P & Q & R & S & \text{\emph{Supply}} \\
A & \Cell{12}{180} & \Cell{10}{150} & \Cell{12}{170} & 13 & 500 \\
B & 7 & 11 & \Cell{8}{180} & \Cell{14}{120} & 300 \\
C & 6 & 16 & 11 & \Cell{7}{200} & 200 \\
\text{Demand} & 180 & 150 & 350 & 320 & 1000
\end{NiceArray}$


\end{document}

위 코드의 출력

관련 정보