答案1
这是一个简短的解决方案pstricks
。加载auto-pst-pdf
,您可以使用进行编译pdflatex
,如果您使用--enable-write18' switch for MiKTeX,
shell-escape for TeX Live or MacTeX. Alternatively you can compile directly with
xelatex`:
\documentclass[a4paper, 11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}%
\usepackage{lmodern}
\usepackage[x11names]{pstricks}%, pdf[]
\usepackage{pst-poly}
\usepackage{auto-pst-pdf} % for pdflatex
\pagestyle{empty}
\begin{document}
\begin{pspicture}%
\psset{unit=1.5cm, linewidth=0.6pt, arrows=c, shortput=nab, linejoin=1}
\rput(0,0){\PstSquare[PolyName=A]}
\rput(2,0){\PstSquare[PolyName=B]}
\psset{fillstyle=solid, fillcolor=Grey0!60!}
\pspolygon(A2)(A3)(A4)
\pspolygon(B2)(B1)(B4)
\psset{linestyle=solid, labelsep=2.5ex}
\ncline{A2}{A4}_{$ L $}
\ncline{B4}{B2}_{$ U $}
\end{pspicture}
\end{document}
答案2
TikZ 不需要特殊处理;这会产生边长为 2cm 的正方形。
\documentclass{article}
\usepackage{tikz,xcolor}
\begin{document}
\begin{tikzpicture}
\fill[black!30] (0,0)--(0,2)--(2,0)--cycle ; % the filled triangle
\draw (0,0)--(0,2)--(2,2)--(2,0)--cycle ; % the square
\draw (0,2)--(2,0) ; % the diagonal
\node at (0.5,0.5) {$L$} ; % the label
\end{tikzpicture}\quad
\begin{tikzpicture}
\fill[black!30] (2,2)--(0,2)--(2,0)--cycle ;
\draw (0,0)--(0,2)--(2,2)--(2,0)--cycle ;
\draw (0,2)--(2,0) ;
\node at (1.5,1.5) {$U$} ;
\end{tikzpicture}
\end{document}