1

I want to draw arrows horizontally or vertically beside to rectangle. How may I code for it in overleaf code? with tikz package or else

\begin{tikzpicture} 
\draw[black, thick] (0,0) rectangle (3,2) node[pos=.5] {text};
\end{tikzpicture}

enter image description here

Skillmon
  • 60,462
  • 1
    \documentclass[border=3.14mm,tikz]{standalone} \begin{document} \begin{tikzpicture} \node[minimum width=3cm,minimum height=2cm,draw,thick](n) {text}; \draw[-latex,thick] (n.east) -- ++ (2,0); \draw[-latex,thick] (n.north) -- ++ (0,2); \end{tikzpicture} \end{document} –  Mar 28 '19 at 18:22
  • In that code how to define position of node? – SANJAY GUPTA Mar 28 '19 at 18:32
  • 2
    As long as you only have one node, the position is meaningless (unless you are doing an overlay picture). If you have more stuff in the tikzpicture, you can say \node[minimum width=3cm,minimum height=2cm,draw,thick](n) at (1.5,1) {text};. However a great feature of tikz is relative positioning, so in many situations you do not need to use explicit coordinates but rather load the positioning library and put the nodes relative to each other. –  Mar 28 '19 at 18:36

1 Answers1

0

@marmot has proposed a nice approach in the comment. Here I use another way, which is based on coordinates.

\documentclass[tikz]{standalone}
\usepackage{siunitx}
\begin{document}
\begin{tikzpicture} 
\draw[black, thick] (0,0) rectangle (3,2) node[pos=.5] {text};
\draw[stealth-stealth] (-.2,0) -- (-.2,2) node[midway,above,sloped] {\SI{2}{cm}};
\draw[stealth-stealth] (0,2.2) -- (3,2.2) node[midway,above] {\SI{3}{cm}};
\end{tikzpicture}
\end{document}

enter image description here