# Spacing of symbols defined in tikz

So I have been defining some new symbols with the help of tikz. My goal is to be able to put these symbols in table such as these ones:

However, these tables have to be read as kind of string diagrams, so I would like the symbols to match with one another (for example, in the left table, the vertical lines from the two symbols should be facing each other). Is there a good way to do that?

Here is the code that produced the previous picture:

\documentclass[preview,border=10pt]{standalone}
\usepackage{tikz}

\newcommand{\cornerur}{%
\begin{tikzpicture}%
\draw[line width=.4mm] (0,0) -- (0,2ex);%
\draw[line width=.4mm] (0,0) -- (2ex,0);%
\end{tikzpicture}%
}

\newcommand{\cornerul}{%
\begin{tikzpicture}%
\draw[line width=.4mm] (2ex,2ex) -- (2ex,0);%
\draw[line width=.4mm] (0,0) -- (2ex,0);%
\end{tikzpicture}%
}

\newcommand{\cornerdr}{%
\begin{tikzpicture}%
\draw[line width=.4mm] (0,0) -- (0,2ex);%
\draw[line width=.4mm] (2ex,2ex) -- (0,2ex);%
\end{tikzpicture}%
}

\newcommand{\cornerdl}{%
\begin{tikzpicture}%
\draw[line width=.4mm] (0,2ex) -- (2ex,2ex);%
\draw[line width=.4mm] (2ex,0) -- (2ex,2ex);%
\end{tikzpicture}%
}

\newcommand{\horiz}{%
\begin{tikzpicture}%
\node at (0,0) {}; {}%
\draw[line width=.4mm] (0,.5ex) -- (2ex,.5ex);%
\end{tikzpicture}%
}

\newcommand{\vertic}{%
\begin{tikzpicture}%
\draw[line width=.4mm] (.5ex,0) -- (.5ex,2ex);%
\end{tikzpicture}%
}

\begin{document}
$\renewcommand{\arraystretch}{1.5} \begin{tabular}{ | c | c | } \hline \cornerdr &  \horiz \\ \hline \vertic & \cornerdr \\ \hline \end{tabular} \qquad \begin{tabular}{ | c | } \hline \cornerdr \\ \hline  \cornerul \\ \hline \end{tabular}$
\end{document}

• Why not simply use MnSymbol Binary Operators? – user36296 Jan 24 '17 at 15:12
• Just to understand you: the vertical lines of the symbols in the left column should be aligned to each other? – Jan Jan 24 '17 at 15:16
• @jan Yes, and the horizontal ones in the first row too. – Maxime Lucas Jan 24 '17 at 15:17
\hline
\end{tabular}
\end{document}

• Congratulations to your answer. :-) – Jan Jan 24 '17 at 16:23
• Hey, that is a very nice answer, this way I know what is going on. Thank you very much! – Maxime Lucas Jan 24 '17 at 16:47

I'm not sure of the naming conventions, but here it is how I interpreted them. Change the names, if you prefer.

No need for TikZ: picture is good as well and even easier.

\documentclass{article}
\usepackage{pict2e}

\linethickness{1pt}
\roundcap\roundjoin

\newcommand{\cornerur}{%
\begingroup\setlength{\unitlength}{2ex}% current font
\begin{picture}(1,1)
\roundcap
\polyline(1,0)(1,1)(0,1)
\end{picture}%
\endgroup
}

\newcommand{\cornerul}{%
\begingroup\setlength{\unitlength}{2ex}% current font
\begin{picture}(1,1)
\polyline(0,0)(0,1)(1,1)
\end{picture}%
\endgroup
}

\newcommand{\cornerdr}{%
\begingroup\setlength{\unitlength}{2ex}% current font
\begin{picture}(1,1)
\polyline(0,0)(1,0)(1,1)
\end{picture}%
\endgroup
}

\newcommand{\cornerdl}{%
\begingroup\setlength{\unitlength}{2ex}% current font
\begin{picture}(1,1)
\polyline(0,1)(0,0)(1,0)
\end{picture}%
\endgroup
}

\newcommand{\horiz}{%
\begingroup\setlength{\unitlength}{2ex}% current font
\begin{picture}(1,1)
\polyline(0,1)(1,1)
\end{picture}%
\endgroup
}

\newcommand{\vertic}{%
\begingroup\setlength{\unitlength}{2ex}% current font
\begin{picture}(1,1)
\polyline(0,0)(0,1)
\end{picture}%
\endgroup
}

\begin{document}
\begin{center}
\verb|\cornerur|: \cornerur\\
\verb|\cornerul|: \cornerul\\
\verb|\cornerdr|: \cornerdr\\
\verb|\cornerdl|: \cornerdl
\end{center}

$\renewcommand{\arraystretch}{1.5} \begin{tabular}{ | c | c | } \hline \cornerdr & \horiz \\ \hline \vertic & \cornerdr \\ \hline \end{tabular} \qquad \begin{tabular}{ | c | } \hline \cornerdr \\ \hline \cornerul \\ \hline \end{tabular}$

\end{document}


A variant with two horizontal and two vertical symbols. The height is tailored to the capital height in the current font. The glyphs link well together. If you instead want some side bearings, it's easy to add them.

\documentclass{article}
\usepackage{pict2e}

\newcommand{\skysurf}[1]{%
\begingroup
\setlength{\unitlength}{\fontcharht\fontA}%
\linethickness{1pt}\roundcap\roundjoin
\begin{picture}(1,1)
\polyline#1
\end{picture}%
\endgroup
}

\newcommand{\cornerur}{\skysurf{(1,0)(1,1)(0,1)}}
\newcommand{\cornerul}{\skysurf{(0,0)(0,1)(1,1)}}
\newcommand{\cornerdr}{\skysurf{(0,0)(1,0)(1,1)}}
\newcommand{\cornerdl}{\skysurf{(0,1)(0,0)(1,0)}}
\newcommand{\horizd}  {\skysurf{(0,0)(1,0)}}
\newcommand{\horizu}  {\skysurf{(0,1)(1,1)}}
\newcommand{\verticl} {\skysurf{(0,0)(0,1)}}
\newcommand{\verticr} {\skysurf{(1,0)(1,1)}}

\begin{document}

\begin{tabular}{ccc}
\cornerul & \horizu & \cornerur\\
\verticl & & \verticr \\
\cornerdl & \horizd & \cornerdr\\
\end{tabular}

\bigskip

ABC \cornerul \horizu \cornerur \verticl \verticr \cornerdl \horizd \cornerdr

\bigskip

\begingroup\setlength{\tabcolsep}{0pt}\renewcommand{\arraystretch}{0}
\begin{tabular}{ccc}
\cornerul & \horizu & \cornerur\\
\verticl & & \verticr \\
\cornerdl & \horizd & \cornerdr\\
\end{tabular}
\endgroup

\end{document}


• Thank you! your answer doesn't work as-is (in particular on the example on the right), but with the picture package I was able to change a few things around and change and make it work. In particular, I used \begin{picture}(2,2) and then changed the polyline coordinate a bit such that the lines go out in the middle of the sides (if I make sense). So for example \polyline(1,0)(1,1)(2,1) for \cornerul. – Maxime Lucas Jan 24 '17 at 15:55

Based on your code, I tried to do some similar. Being lazy at typing, I shortened your command names. I also introduced two new vertical or horizontal lines. Both have a white line on white background so tend to be invisible, but use the needed amount of space. The variants differ in the position of the visible line being on the left or right side of the vertical alignment or being on the top or bottom side of the horizontal alignment.

Having said that, you are now able to place almost any combination with alignment (I hope).

Ah, being lazy at typing, I also defined TikZ-stlyes and used them.

As you can see, you don't need math mode.

\documentclass[preview,border=10pt]{standalone}
\usepackage{tikz}

\tikzset{my style/.style={line width=.4mm}, blind/.style={white}}

\newcommand{\ur}{%
\begin{tikzpicture}%
\draw[my style] (2ex,0) -- (0,0) -- (0,2ex);%
\end{tikzpicture}%
}

\newcommand{\ul}{%
\begin{tikzpicture}%
\draw[my style] (2ex,2ex) -- (2ex,0) -- (0,0);%
\end{tikzpicture}%
}

\newcommand{\dr}{%
\begin{tikzpicture}%
\draw[my style] (0,0) -- (0,2ex) -- (2ex,2ex);%
\end{tikzpicture}%
}

\newcommand{\dl}{%
\begin{tikzpicture}%
\draw[my style] (0,2ex) -- (2ex,2ex) -- (2ex,0);%
\end{tikzpicture}%
}

\newcommand{\hb}{%
\begin{tikzpicture}%
\draw[my style] (0,0) -- (2ex,0);%
\draw[blind] (0,0) -- (0,2ex);%
\end{tikzpicture}%
}

\newcommand{\hh}{%
\begin{tikzpicture}%
\draw[my style] (0,2ex) -- (2ex,2ex);%
\draw[blind] (0,0) -- (0,2ex);%
\end{tikzpicture}%
}

\newcommand{\vl}{%
\begin{tikzpicture}%
\draw[my style] (0,0) -- (0,2ex);%
\draw[blind] (0,0) -- (2ex,0);%
\end{tikzpicture}%
}

\newcommand{\vr}{%
\begin{tikzpicture}%
\draw[my style] (2ex,0) -- (2ex,2ex);%
\draw[blind] (0,0) -- (2ex,0);%
\end{tikzpicture}%
}

\begin{document}

Using \verb!\fbox!-commands:
\fbox{\ur}\fbox{\hb}

This is the old style, without math mode.
\renewcommand{\arraystretch}{1.5}
\begin{tabular}{ | c | c | }
\hline
\dr &  \hh \\
\hline
\vl & \dr \\
\hline
\end{tabular}
\begin{tabular}{ | c |c | c |}
\hline
\dr & \hh & \dl\\
\hline
\vl &  & \vr \\
\hline
\ur & \hb & \ul\\
\hline
\end{tabular}
\end{document}


To proof it worked:

Here I create the elements by superimposing a white \rule atop a black \rule, offset as needed. The elements are currently defined with \rlthk thickness and \boxsize size. The form of the macros are \X<horz><vert>, where <horz can be l, c, or r, and <vert> can be b, c, or t.

\documentclass[12pt]{article}
\usepackage{stackengine,xcolor}
\def\rlthk{\dimexpr1pt\relax}
\def\boxsize{\dimexpr1ex\relax}
\def\blbox{\rule{\boxsize}{\boxsize}}
\def\whbox{\textcolor{white}{\blbox}}
%
\def\Xrt{\kern-\rlthk\stackinset{r}{\rlthk}{t}{\rlthk}{\whbox}{\blbox}}
\def\Xlt{\stackinset{l}{\rlthk}{t}{\rlthk}{\whbox}{\blbox}\kern-\rlthk}
\def\Xrb{\kern-\rlthk\stackinset{r}{\rlthk}{b}{\rlthk}{\whbox}{\blbox}}
\def\Xlb{\stackinset{l}{\rlthk}{b}{\rlthk}{\whbox}{\blbox}\kern-\rlthk}
%
\def\Xtt{\stackinset{c}{}{t}{\rlthk}{\whbox}{\blbox}}
\def\Xll{\stackinset{l}{\rlthk}{c}{}{\whbox}{\blbox}\kern-\rlthk}
\def\Xbb{\stackinset{c}{}{b}{\rlthk}{\whbox}{\blbox}}
\def\Xrr{\kern-\rlthk\stackinset{r}{\rlthk}{c}{}{\whbox}{\blbox}}
\begin{document}
Building blocks:\par
\Xlt{} \Xtt{} \Xrt\par
\Xll{} \hspace{\boxsize} \Xrr\par
\Xlb{} \Xbb{} \Xrb

\begin{tabular}{|c|c|}
\hline
\Xlt & \Xtt\\
\hline
\Xll & \Xlt\\
\hline
\end{tabular}
`