我有一段我曾经研究过的代码:
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\begin{tikzpicture} [baseline=1.2in]
\draw [thick] (1,2) -- (1,1) -- (5,1) -- (5,2) -- (6,2) -- (6,5) -- (5,5) -- (5,6) -- (1,6) -- (1,5) -- (0,5) -- (0,2) -- (1,2) ;
% Draw small box on each corner
\draw [thick] (0,2) -- (0,1) -- (1,1) -- (1,2) -- (0,2) ;
\draw [thick] (6,2) -- (5,2) -- (5,1) -- (6,1) -- (6,2) ;
\draw [thick] (5,5) -- (6,5) -- (6,6) -- (5,6) -- (5,5) ;
\draw [thick] (1,5) -- (1,6) -- (0,6) -- (0,5) -- (1,5) ;
\draw [semithick,dashed] (1,2) -- (1,5) -- (5,5) -- (5,2) -- (1,2);
\draw [thick, decorate,decoration={brace,amplitude=10pt},xshift=0pt,yshift=2pt] (0.05,6) -- (5.95,6) node [black,midway,yshift=16pt] {\footnotesize $24$ cm};
\draw [thick, decorate,decoration={brace,amplitude=10pt},xshift=2pt] (6,5.95) -- (6,1.05) node [black,midway,xshift=26pt] {\footnotesize $9$ cm};
\end{tikzpicture}
\end{document}
答案1
我建议使用 简化您的代码rectangle
。您可以使用 添加标签(如x
)node
。可以使用 添加底部和右侧的长度{Bar[width=8mm]Latex}-{{Latex}Bar[width=8mm]}
(这需要arrows.meta
库)。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
\draw[thick] (0,0) rectangle (12,4.5);
\draw[thick, fill=gray!30] (0,0) rectangle (1,1) (12,0) rectangle (11,1)
(12,4.5) rectangle node[below=5mm]{$x$}node[left=5mm]{$x$} (11,3.5) (0,4.5) rectangle (1,3.5);
\draw[semithick, dashed] (1,1) rectangle (11,3.5);
\draw[thick, {Bar[width=8mm]Latex}-{{Latex}Bar[width=8mm]}] (0,-.5) --node[fill=white]{24} (12,-.5);
\draw[thick, {Bar[width=8mm]Latex}-{{Latex}Bar[width=8mm]}] (12.5,0) --node[fill=white]{9} (12.5,4.5);
\end{tikzpicture}
\end{document}
该图的其余部分如下:
代码:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
\draw[thick] (0,0) rectangle (12,4.5);
\draw[thick, fill=gray!30] (0,0) rectangle (1,1) (12,0) rectangle (11,1)
(12,4.5) rectangle node[below=5mm]{$x$}node[left=5mm]{$x$} (11,3.5) (0,4.5) rectangle (1,3.5);
\draw[semithick, dashed] (1,1) rectangle (11,3.5);
\draw[thick, {Bar[width=8mm]Latex}-{{Latex}Bar[width=8mm]}] (0,-.5) --node[fill=white]{24} (12,-.5);
\draw[thick, {Bar[width=8mm]Latex}-{{Latex}Bar[width=8mm]}] (12.5,0) --node[fill=white]{9} (12.5,4.5);
\begin{scope}[shift={(0,-6)}, line join=round]
\draw[thick] ([shift={(2,2)}]1,1) rectangle ([shift={(2,2)}]11,2);
\draw[thick] (1,1) -- ([shift={(2,2)}]1,1) -- ([shift={(2,2)}]1,2) -- (1,2) -- cycle;
\draw[thick, fill=white] (1,1) rectangle (11,2);
\draw[thick, fill=white] (11,1) -- ([shift={(2,2)}]11,1) --node[right=2.5mm]{$x$} ([shift={(2,2)}]11,2) -- (11,2) -- cycle;
\draw[thick, {Bar[width=8mm]Latex}-{{Latex}Bar[width=8mm]}] (1,.5) --node[fill=white]{$24-2x$} (11,.5);
\draw[thick] ([shift={(2,2)}]11,.9)--([shift={(2,2)}]11,.1);
\draw[thick, {Latex[slant=1]}-{Latex[slant=1]}] (11,.5) --node[inner sep=0](M){} ([shift={(2,2)}]11,.5);
\draw[Latex-] (M)--++(1,-1)node[below]{$9-2x$};
\draw[thick, -{{Latex}Bar[width=8mm]}] ([shift={(2,2)}]11.5,2.5)--([shift={(2,2)}]11.5,2);
\draw[thick, -{{Latex}Bar[width=8mm]}] ([shift={(2,2)}]11.5,.5)--([shift={(2,2)}]11.5,1);
\end{scope}
\end{tikzpicture}
\end{document}
答案2
这显示了如何使用 tikz-3dplot。两次都可以使用几乎相同的代码(above
可能below
会更改)。另一方面,tikz-3dplot 仅使用正交坐标。
有趣的是,当给定单位时,移位坐标不会转换为 3d。
\documentclass[tikz]{standalone}
\usepackage{tikz-3dplot}
%\usetikzlibrary{decorations.pathreplacing}
\tdplotsetmaincoords{60}{10}
\begin{document}
\begin{tikzpicture}
\draw [thick] (1,2) -- (1,1) -- (5,1) -- (5,2) -- (6,2) -- (6,5) -- (5,5) -- (5,6) -- (1,6) -- (1,5) -- (0,5) -- (0,2) -- cycle ;
% Draw small box on each corner
\draw [thick] (0,2) -- (0,1) -- (1,1) -- (1,2) -- cycle ;
\draw [thick] (6,2) -- (5,2) -- (5,1) -- (6,1) -- cycle ;
\draw [thick] (5,5) -- (6,5) -- (6,6) -- (5,6) -- cycle ;
\draw [thick] (1,5) -- (1,6) -- (0,6) -- (0,5) -- cycle ;
\draw [semithick,dashed] (1,2) -- (1,5) -- (5,5) -- (5,2) -- cycle;
\begin{scope}[shift={(0,0.2)}]
\draw[<->] (0,6) -- (6,6) node [black,midway,above,sloped] {\footnotesize $24$ cm};
\end{scope}
\begin{scope}[shift={(0.2,0)}]
\draw[<->] (6,6) -- (6,1) node [black,midway,above,sloped] {\footnotesize $9$ cm};
\end{scope}
\end{tikzpicture}
\begin{tikzpicture}[tdplot_main_coords]
\draw [thick] (1,2) -- (1,1) -- (5,1) -- (5,2) -- (6,2) -- (6,5) -- (5,5) -- (5,6) -- (1,6) -- (1,5) -- (0,5) -- (0,2) -- cycle ;
% Draw small box on each corner
\draw [thick] (0,2) -- (0,1) -- (1,1) -- (1,2) -- cycle ;
\draw [thick] (6,2) -- (5,2) -- (5,1) -- (6,1) -- cycle ;
\draw [thick] (5,5) -- (6,5) -- (6,6) -- (5,6) -- cycle ;
\draw [thick] (1,5) -- (1,6) -- (0,6) -- (0,5) -- cycle ;
\draw [semithick,dashed] (1,2) -- (1,5) -- (5,5) -- (5,2) -- cycle;
\begin{scope}[shift={(0,0.2)}]
\draw[<->] (0,6) -- (6,6) node [black,midway,above,sloped] {\footnotesize $24$ cm};
\end{scope}
\begin{scope}[shift={(0.2,0)}]
\draw[<->] (6,6) -- (6,1) node [black,midway,below,sloped] {\footnotesize $9$ cm};
\end{scope}
\end{tikzpicture}
\end{document}