2

I have this code that I have worked on:

\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}

but I need revision because I want to achieve this: enter image description here

3
  • I am able to fill the blue, now I want to draw x on certain point Nov 14, 2022 at 16:28
  • I manage to solve it by myself, thanks! Nov 14, 2022 at 16:34
  • Why not starting with \draw[cyan] (0,0) rectangle (24,9); which would result in the right aspect ratio? You can always scale later ... Nov 14, 2022 at 16:35

2 Answers 2

3

I suggest simplifying your code using rectangle. You can add labels (like x) using node. The lengths on bottom and right can be added using {Bar[width=8mm]Latex}-{{Latex}Bar[width=8mm]} (which requires the arrows.meta library.

enter image description here

\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}

Here is the rest of the diagram:

enter image description here

Code:

\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

This shows how to use tikz-3dplot. You can use almost the same code both times (above and below may change). OTOH, tikz-3dplot uses orthonomal coordineate only.

Interestingly, the shift coordinates are not converted to 3d when given units.

\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}

demo

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .