tikz 矩形内接于矩形

tikz 矩形内接于矩形

我如何将其转换为 latex tikz?

在此处输入图片描述

另外,我想插入带箭头的较大矩形的长度 (2x + 6) 和宽度 (x+6)。我是 LaTeX 新手。欢迎回答。谢谢!

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

相关内容