有没有办法精确绘制这个简单的图表?使用表格的结果很难看,而且不太易读。或者我可能不太擅长用表格 :) 提前感谢您的帮助!
答案1
请在下一个问题中添加 TeX 代码。
\documentclass{article}
\begin{document}
\[
\begin{array}{ccccc}
1 & 2 & 3 & 4 & \\
\cline{1-4}
\multicolumn{1}{|c|}{a} & \multicolumn{1}{|c|}{b}
& \multicolumn{1}{|c|}{x} &\multicolumn{1}{|c|}{a} & 0\\
\cline{1-4}
& \multicolumn{1}{|c|}{a}
& \multicolumn{1}{|c|}{x} &\multicolumn{1}{|c|}{a} & 1\\
\cline{2-4}
& & \multicolumn{1}{|c|}{x} &\multicolumn{1}{|c|}{b} & 2\\
\cline{3-4}
& & &\multicolumn{1}{|c|}{x} & 3\\
\cline{4-4}
\end{array}
\]
\end{document}
答案2
语义上更清晰的解决方案blkarray
:
\documentclass{article}
\usepackage{blkarray}
\begin{document}
\[ \setlength{\BAextrarowheight}{2pt}
\makeatletter\setlength{\BA@colsep}{5pt}\makeatother
\begin{blockarray}{*{5}{c}}
1 & 2 & 3 & 4 \\
\cline{1-4}%
\begin{block}{*{4}{|c}|c}
a & b & x & a & 0 \\
\BAhhline{----|~}
\end{block}
\begin{block}{c*{3}{|c}|c}
& a & x & a & 1\\
\BAhhline{~|---|~}%
\end{block}
\begin{block}{cc*{2}{|c}|c}
& & x & b & 2 \\
\BAhhline{~~|--|~}%
\end{block}
\begin{block}{*{3}{c}|c|c}
& & & x & 3 \\
\BAhhline{~~~|-|~}%
\end{block}
\end{blockarray} \]
\end{document}
答案3
您只能使用\hbox
、\vbox
和原\hrule
语\vrule
:
\newdimen\bxwidth \bxwidth=1.2em
\def\p #1 #2 #3 #4 {\par\hbox{\bp{#1}\bp{#2}\bp{#3}\bp{#4}}}
\def\r #1 {\smallskip\hrule width\dimexpr 4\bxwidth+.4pt\relax}
\def\x #1 #2 #3 #4 #5 {\hbox{\bx{#1}\bx{#2}\bx{#3}\bx{#4}\vrule\bp{#5}}\nointerlineskip}
\def\bp#1{\hbox to\bxwidth{\hss#1\hss}}%
\def\bx#1{\ifx.#1\bp{}%
\else \lower\dimexpr.2\bxwidth+.4pt\vbox{
\bp{\unskip\vrule height.8\bxwidth depth.2\bxwidth\hfil $#1$}\hrule}%
\fi
}
\p 1 2 3 4
\r -------
\x a b x a 0
\x . a x a 1
\x . . x b 2
\x . . . x 3
\bye
答案4
更新
matrix
这是使用Ti 的版本钾Z,具有完美的方形框。
\documentclass[border=4mm,tikz]{standalone}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\tikzset{square matrix/.style = {
matrix of math nodes,
row sep = -\pgflinewidth,
column sep = -\pgflinewidth,
nodes = {draw,
minimum height = 2em,
text width = 2em,
anchor = center,
align = center,
inner sep = 0pt
},
},
square matrix/.default = 1cm
}
\matrix (m) [square matrix]
{
& & & & \\
a & b & x & a & |[white]|. \\
& a & x & a & |[white]|. \\
& & x & b & |[white]|. \\
& & & b & |[white]|. \\
};
\foreach \i in {2,...,5}
{
\pgfmathtruncatemacro{\y}{\i - 2}
\node at (m-\i-5) {$\y$};
\pgfmathtruncatemacro{\x}{\i - 1}
\node[above, inner sep = 3mm] at (m-2-\x.north) {$\x$};
}
\draw (m-2-5.north west)--(m-5-5.south west);
\end{tikzpicture}
\end{document}
只是为了好玩...这是一个奇怪的解决方案天际线之谜的LogicPuzzle 包。
\documentclass[border=4mm]{standalone}
\usepackage{logicpuzzle}
\begin{document}
\skylinesetup{rows=4, columns=4}
\begin{skyline}
\skylineT{1,2,3,4}
\skylineR{3,2,1,0}
\setrow{4}{$a$,$b$,$x$,$a$}
\setrow{3}{{},$a$,$x$,$a$}
\setrow{2}{{},{},$x$,$b$}
\setrow{1}{{},{},{},$x$}
\begin{puzzlebackground}
\fillarea{blue!20}{%
(4,1)--(5,1)--(5,5)--(1,5)--(1,4)--(2,4)--(2,3)--(3,3)--(3,2)--(4,2)--(4,1)}
%\fillarea{white}{(1,1)--(4,1)--(4,2)--(3,2)--(3,3)--(2,3)--(2,4)--(1,4)--(1,1)}
\end{puzzlebackground}
\end{skyline}
\end{document}
笔记
该包仅适用于矩形网格,因此在这种情况下无法制作出问题所需的精确图形。
注释
\fillarea{white}{...}
行用于着色并框住网格的其他部分。颜色可以随意更改。