1

enter image description here

can somebody help me with this, I tried my best but fail.

\documentclass[12pt,a4paper]{report}
\usepackage{tikz,graphicx}
\begin{document}
\begin{figure}[!tb]
\begin{center}
\begin{tikzpicture}
%drawing shapes 
\draw [fill=white] (1.5,0.3) rectangle (10,1.0);
\draw [thick] (6,1.5)-- (7,2)--(6.6,2)--(6.6,3.5)--(5.4,3.5)--(5.4,2)--(5,2)--(6,1.5);
\draw [fill=white] (5.4,3.56) rectangle (6.6,3.66);
\draw [fill=white] (5.4,3.7) rectangle (6.6,3.75);
\draw [thick] (1.8,3.9) to [out=180,in=270] (1.5,4.1)--(1.5,5.1) to [out=90,in=180] (1.8,5.3);
\draw [thick] (9.8,3.9) -- (10.5,3.9) --(10.5,5.3) -- (9.8,5.3);




\end{tikzpicture}
\end{center}
\end{figure}
\end{document}
5
  • 1
    There is no graphix package in a standard TeX installation as far as I know. I assume you mean the graphicx package (which is not needed to compile your code). Jun 20, 2023 at 6:47
  • 4
    Can you provide a better question title (as opposed to "how to draw this...")?
    – Werner
    Jun 20, 2023 at 6:48
  • You could just use nodes like \node at (6,4.6) {Foo}; \node at (5.75,0.65) {Bar}; and place the other things inside. Jun 20, 2023 at 6:52
  • May I ask how you got the code that you show? Do you need it to be excactly like this? Because the upper part looks like a matrix to me where the left side has a ( and the right side has a ] which is probably easiest to create using the nicematrix package. It would also be not too complicated to add the arrow. Jun 20, 2023 at 7:22
  • not exactly, i only need to produce what is in the picture.
    – Chamanga
    Jun 20, 2023 at 8:00

1 Answer 1

4

I would probably go with the nicematrix package to create the upper matrix and add the rest using TikZ (note that you might want to add some spacing above and below, since the bounding box is probably a bit off;

\documentclass[border=20pt]{standalone}
\usepackage{nicematrix, tikz}
\usetikzlibrary{calc}

\begin{document}
\(
\begin{NiceArray}{ l *{16}{c} }
\textbf{Dimension:} 
    &  1 &  2 &  3 &  4 &  5 &  6 &  7 &  8 &  9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 \\
\textbf{Position:} 
    &  0 &  1 &  1 &  0 &  1 &  0 &  0 &  1 &  1 &  0 &  0 &  1 &  0 &  1 &  1 &  0 \\[2cm]
\CodeAfter
    \OverBrace[shorten, yshift=5pt]{1-2}{1-9}{\textbf{First vehicle}}
    \OverBrace[shorten, yshift=5pt]{1-10}{1-17}{\textbf{Second vehicle}}
    \SubMatrix({1-2}{2-17}]
    \begin{tikzpicture}
        \coordinate (anchor) at ([shift={(-0.6,-0.35)}]$(2-9)!0.5!(2-10)$);
        \draw (anchor) rectangle ++(1.2,-0.05);
        \draw ([shift={(0,-0.125)}]anchor) rectangle ++(1.2,-0.1);
        \draw ([shift={(0,-0.3)}]anchor) -| ++(1.2,-0.5) 
            -- ++(0.5,0) -- ++(-1.1,-0.75) coordinate (tip)
            -- ++(-1.1,0.75) -- ++(0.5,0) -- cycle;
        \node[draw] at ([shift={(0,-0.5)}]tip) {
            (1,2), (2,1), (3,1), (4,2), (5,1), (6,2), (7,2), (8,1)
        };
    \end{tikzpicture}
\end{NiceArray}
\)
\end{document}

enter image description here


Or you could create it purely with TikZ and use a \matrix:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc, matrix, decorations.pathreplacing, calligraphy}

\begin{document}
\begin{tikzpicture}
    \matrix[matrix of nodes, every node/.style={anchor=base, minimum width={1.5em}}] (m) {
        |[text width={6em}, align=left]| \textbf{Dimension:} 
            &  1 &  2 &  3 &  4 &  5 &  6 &  7 &  8 
            &  9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 \\
        |[text width={6em}, align=left]|\textbf{Position:} 
            &  0 &  1 &  1 &  0 &  1 &  0 &  0 &  1 
            &  1 &  0 &  0 &  1 &  0 &  1 &  1 &  0 \\
    };

    \draw[decorate, decoration={calligraphic curved parenthesis, mirror}] 
        (m-1-2.north west) -- (m-2-2.south west);
    \draw (m-1-17.north east) -- ++(1.5pt,0) |- 
        (m-2-17.south east -| m-1-17.north east);
    
    \draw[decorate, decoration={calligraphic brace}] 
        ([xshift=2pt]m-1-2.north west) -- ([xshift=-2pt]m-1-9.north east)
        node[midway, above=2pt] {\textbf{First vehicle}};
    \draw[decorate, decoration={calligraphic brace}] 
        ([xshift=2pt]m-1-10.north west) -- ([xshift=-2pt]m-1-17.north east)
        node[midway, above=2pt] {\textbf{Secoond vehicle}};

    \coordinate (anchor) at ([yshift=-2pt]$(m-2-8.south)!0.5!(m-2-9.south)$);
    \draw (anchor) rectangle ++(1.2,-0.05);
    \draw ([shift={(0,-0.125)}]anchor) rectangle ++(1.2,-0.1);
    \draw ([shift={(0,-0.3)}]anchor) -| ++(1.2,-0.5) 
        -- ++(0.5,0) -- ++(-1.1,-0.75) coordinate (tip)
        -- ++(-1.1,0.75) -- ++(0.5,0) -- cycle;
    
    \node[draw] at ([shift={(0,-0.5)}]tip) {
        (1,2), (2,1), (3,1), (4,2), (5,1), (6,2), (7,2), (8,1)
    };
\end{tikzpicture}
\end{document}

enter image description here

5
  • thx, is there any other package similar to "nicematrix", I am facing trouble with it. my latex refuses to install the package
    – Chamanga
    Jun 20, 2023 at 8:45
  • 1
    You could also create the matrix using a TikZ matrix directly. I'll update my answer in a moment. Jun 20, 2023 at 8:54
  • maybe, it is my latex or something else. i use latex 11, and latest miktex. now it is does not find "calc, matrix, decorations.pathreplacing, calligraphy" in its libraries
    – Chamanga
    Jun 20, 2023 at 9:48
  • @Chamanga You can download these libraries from CTAN (ctan.org/pkg/pgf and ctan.org/pkg/spath3) and just place them inside your working directory. But actually, these libraries are part of every regular TeX distribution. You might want to update your TeX installation and make sure that the complete TikZ package and the spath3 package are installed. Jun 20, 2023 at 9:56
  • 1
    great, now everything is working wonderful.
    – Chamanga
    Jun 20, 2023 at 18:30

You must log in to answer this question.

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