Spacing of symbols defined in tikz

The problem with tikz pictures is that once the picture is finished, it is clipped to its bounding box, so a figure with a single line like \draw (0,0) -- (1,1); produces the same result as another with a single line like \draw (1,1) -- (2,2);. The second one does not look "displaced".

To position properly your lines inside each cell you need that each tikzpicture has the same size, which means the same bounding box. For example, if the following macro is defined:

\def\bbox{\path[fill=yellow, use as bounding box] (0,0) rectangle(2ex,2ex);}

and each tikz picture begins with command \bbox, then your code produces the figure:

Result

You can still see that the lines do not align as you wanted, but this is because those lines do not start at (0,0), but at (.5ex, 0) or (0, .5ex) instead. I don't know if this is intentional, but anyway the yellow background makes easier to see "whys" and adjust the result as required.

Once you are happy with the result you can remove the fill=yellow option in the definition of \bbox. The yellow boxes will disappear, but the alignment remains, since the same bounding box is used:

Final result

This is the full code. I altered it a bit in order to produce proper corners at the junctions, and remove the \[, \] around the tabular.

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

\def\bbox{\path[use as bounding box] (0,0) rectangle(2ex,2ex);}

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


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

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

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

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

\newcommand{\vertic}{%
\begin{tikzpicture}%
\bbox
\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}

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}

enter image description here

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\font`A}%
  \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}

enter image description here


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

enter image description here