答案1
这是一个完全硬编码的示例,如果矩形的比例发生变化,可能会有更好的解决方案,更优雅,并且可以更容易地更新:
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
% rectangles
\draw[very thick] (0,0) rectangle (6, 4) [fill=gray]; % gray rectangle
\draw[very thick] (1, 1) rectangle (5,3) [fill=white]; % white rectangle
% outer dimensions
\draw[thick, <->] (3,0) -- (3,1) node [midway,right] {3}; % bottom
\draw[thick, <->] (3,3) -- (3,4) node [midway,right] {3}; % top
\draw[thick, <->] (0,2) -- (1,2) node [midway,above] {3}; % left
\draw[thick, <->] (5,2) -- (6,2) node [midway,above] {3}; % right
% inner dimensions
\node[below] at (3,3) {$2x$}; % top
\node[left] at (5,2) {$x$}; % right
% complete dimensions
\draw[thick, <->] (0,4.5) -- (6,4.5) node [midway,above] {$2x+6$}; % top
\draw[thick, <->] (6.5,0) -- (6.5,4) node [midway,right] {$x+6$}; % right
\end{tikzpicture}
\end{document}