7

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: enter image description here

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
  • Your newly defined commands like \cornerul are not mathematical. Therefore, your table does not need any mathematical envorinments. You can strip the \[ ... \] and the $s. – Jan Jan 24 '17 at 15:18
  • @samcarter Because I didn't know that MnSymbol had such symbols. But I just tested it and I don't think it fixes my alignment problems, does it? – Maxime Lucas Jan 24 '17 at 15:19
8

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}
  • 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
7

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

  • 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
2

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

2

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}
\quad%
\begin{tabular}{|c|}
\hline
\Xlt \\
\hline
\Xrb\\
\hline
\end{tabular}
\end{document}

enter image description here

  • So we seemed to have the same idea how to solve this problem. :-) Congratulations to this nice answer. – Jan Jan 24 '17 at 16:17

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.