6

I am interested in creating a symbol-sized tikz drawing with a rectangle half the width of the symbol (and the height of a symbol) and an arrow coming out from the middle right side of the rectangle pointing to the right (the arrow head should be rather small). I tried to do something like that here (the A symbol is for comparison in size), but it didn't quite work right:

\documentclass{article}

\usepackage{tikz}

\usetikzlibrary{positioning}

\begin{document}

\begin{tikzpicture}[
  node distance = 0mm,
box/.style = {% definition of rectangle as node
    draw, line width=0.35mm,
  text width=11pt, minimum height=11pt, align=left,
  inner sep=1mm, outer sep=0pt}
                    ]
\node (box1) [label=above:{}] {};
\node (B) [draw, right=of box1] {};
\draw [->] (box1) -- (B);

\end{tikzpicture}

A

\end{document}
  1. How do I make the width of the square half its size?

  2. How do I make the arrow leave the right side of the rectangle?

  3. How do I make an "empty" node to the right of the rectangle so I can draw an arrow to it?

  4. How do I make the arrow head smaller?

enter image description here

  • Could you post a (hand-made) sketch of what you want? Compiling your code is not very explicit about it. – Bernard Feb 22 '16 at 23:54
5

Perhaps like this...

\documentclass[varwidth,border=5]{standalone}
\usepackage{tikz}
\def\abx{\tikz[x=0.75em,y=0.75em,baseline=0]\fill[even odd rule]
(0,0)--(.5,0)--(.5,.45)--(.75,.45)--(.75,.25)--(1,.5)--(.75,.75)--
(.75,.55)--(.5,.55)--(.5,1)--(0,1)--cycle(.1,.1)rectangle(.4,.9);}
\hbadness=10000
\begin{document}
\foreach \f in {\scriptsize,\footnotesize,\small,\normalsize,\large,\huge}{%
\noindent\hbox to1.125in{\texttt{\expandafter\string\f:}} 
\f xX \abx\ yY \\[.5ex]}
\end{document}

enter image description here

  • thanks! How would you make the arrow point to the other direction, meaning still on the right side, only pointing towards the rectangle instead of outside of it? – tikzUser Feb 23 '16 at 11:04
  • @tikzUser Try using (0,0)--(.5,0)--(.5,.5)--(.75,.25)--(.75,.45)--(1,.45)--(1,.55)--(.75,.55)--(.75,.75)--(.5,.5)--(.5,1)--(0,1)--cycle (.1,.1)rectangle(.4,.9); – Mark Wibrow Feb 23 '16 at 12:02
5

I don't fully understand your question, what symbol are you talking about? Here I've addressed your questions, if the size does not suit your need simply scale or re-size the objects:

  1. \draw (0,0) rectangle (1,2);
  2. \draw [->] (1,1)--+(1,0);
  3. Empty node is bad practice, rather use \coordinate (name) at (1,1); that leads to \draw [->] (name)--+(1,0);
  4. Using the library arrows.meta (have a look at this link) you can scale the size of the arrow in this way \draw [-{>[scale=0.7]}] (name)--+(1,0);

It could be useful to define a pic that allows you to place a predefined shape like a "stamp". I've defined a pic named mybox:

\documentclass[tikz,convert]{standalone}
\usetikzlibrary{arrows.meta}
\tikzset{mybox/.pic={
\draw (-0.5,-1) rectangle (.5,1);
\draw [-{>[scale=0.5]}] (0.5,0)--+(0.5,0);
}
}
\begin{document}
\begin{tikzpicture}[>=Stealth]
\pic at (0,0) {mybox};
\draw (1,1) arc (135:45:3) pic [red,pos=0.3,scale=0.5,sloped] {mybox}; 
\end{tikzpicture}
\end{document}

The result would be: mybox pic and its usage

3

I'm not sure why you wish to use TikZ for this. However, since you do, here is one way you might go about it:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\newcounter{mybox}
\newlength\myboxminheight
\settoheight\myboxminheight{ABCDEFGHIJKLMNOPQRSTUVWXYZ}
\tikzset{%
  pics/my box/.style={%
    code={%
      \stepcounter{mybox}%
      \tikzset{%
        >/.tip={Triangle[length=2.5pt,width=2.5pt]},
        outer sep=0pt,
        every node/.append style={draw},
        make my box/.cd,
        #1,
        /tikz/.cd,
        make my box/my box look,
      }
      \node (box\themybox) [make my box/my box look, label=above:{\myboxlabel}, inner sep=\myboxisep, minimum height=\myboxminht-\myboxlinewidth, minimum width=.5*\myboxminht-.5*\myboxlinewidth] at (0,0) {};
      \draw [->, make my box/my box look, line width=\myboxlinewidth,] (box\themybox.east) -- +(\myboxextarrow,0);
    }
  },
  make my box/.search also={/tikz},
  make my box/.cd,
  line width/.store in=\myboxlinewidth,
  minimum height/.store in=\myboxminht,
  inner sep/.store in=\myboxisep,
  label/.store in=\myboxlabel,
  extend arrow/.store in=\myboxextarrow,
  look/.code={\tikzset{make my box/my box look/.append style={#1}}},
  line width=.35mm,
  minimum height=\myboxminheight,
  inner sep=0pt,
  label={},
  extend arrow=5pt,
  my box look/.style={draw, line width=\myboxlinewidth},
}
\newcommand\mybox[1][]{%
  \tikz{\pic {my box={#1}};}}
\begin{document}
  X \mybox{} \mybox[label={My Box}] \mybox[look={text=red, draw=blue}, extend arrow=25pt, minimum height=20pt, inner sep=2mm, line width=2.5pt, label={My Other Box}, >/.tip={Stealth[]}]
\end{document}

arrows

Note that the box of a glyph may include space above the drawn letter and that not all capital letters look of equal height close up. Hence, you'll need to tweak this according to your preferences, font configuration and needs.

  • Note that if you zoom the first box aligns with the top and base of the X. But it looks smaller due, probably, to the shapes and line widths. Hence, you might want to remove -\myboxlinewidth from the value passed to minimum height in the node options. – cfr Feb 23 '16 at 2:54
2

Here is a solution with pstricks:

\documentclass{article}

\usepackage{pst-node}
\usepackage{auto-pst-pdf} \newcommand\mysymbol{\begin{pspicture}%
\fnode[linewidth=0.4pt, linecolor=blue, framesize=3.5pt 7pt, dimen=middle](0,3pt){R}
\uput{2.5ex}[r](R){\pnode{W}}\ncline[arrows=->, linecolor = red, linewidth=0.6pt, linejoin=1, nodesepA=0.5pt, arrowinset=0.15,arrowsize=2pt]{R}{W} \end{pspicture}}%

\begin{document} 

A\enspace\mysymbol 

\end{document} 

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.