[Tex/LaTex] Connecting vertical box drawing characters

beamermintedunicode

I've been working on some diagrams for a slide deck using beamer and minted (and buliding the PDF with Xelatex). When using the Unicode box-drawing characters, the vertical bars are not actually "connecting" like the rest of the characters. I thought it was an issue with my font at first (DejaVu Sans), but I've since tried several different monospace fonts with no luck. I've also tried tweaking the baseline options on the minted environment, but with no change (negative numers don't appear to affect it at all). Finally, I tried adding a new Unicode character that would replace the vertical line with a tikz drawing (of a vertical line), but that was a bit of a hack and I could never get it to look quite right where it intersected the normal box drawing characters, and don't want to redefine every character I might ever use).

I'd like to know what's causing this problem. Note that the same thing happens outside of the Minted environment, and if I'm using another class, however, the knowledge that it's in a Beamer/Verbatim environment may affect the solution, so I've included it in the MWE below:

\documentclass[xelatex,aspectratio=169]{beamer}

\usepackage{fontspec,minted}

\setmonofont{Source Code Pro}
% \setmonofont{DejaVu Sans} % Same thing

% Don't display annoying red boxes around errors
\renewcommand{\fcolorbox}[4][]{#4}
\begin{document}

\begin{frame}[fragile]
\begin{minted}{C}
      ╭─────────────────────────────╮
      │                  ╭───╮      │
      │  ╭───╮           │╭─╮│      │
      │  ↑   │           │↑ ││      │
void (*signal(int, void (*fp)(int)))(int);
 ↑    ↑      │      ↑    ↑  ││      │
 │    ╰──────╯      │    ╰──╯│      │
 │                  ╰────────╯      │
 ╰──────────────────────────────────╯
\end{minted}
\end{frame}

\end{document}

which produces (note the gaps in the vertical bars):

broken vertical box drawing characters

Best Answer

The reason is that the arrow is much shorter than the character U+2502, BOX DRAWINGS LIGHT VERTICAL, as shown in this picture:

enter image description here

The other reason is that \lineskip enters the way.

An acceptable version can be obtained by using an arrow in another font, then scaling it a bit to reflect the dimensions of the box drawing characters.

\documentclass{article}

\usepackage{fontspec,minted,color,graphicx}
\usepackage{newunicodechar}

\setmonofont{Source Code Pro}
\newfontfamily{\Carrows}{TeX Gyre Adventor}
\newunicodechar{↑}{\arrowresize{\Carrows ↑}}
\newcommand{\arrowresize}[1]{%
  \sbox0{\ttfamily │}%
  \setlength{\dimen8}{\dimexpr\ht0+\dp0\relax}%
  \makebox[\wd0]{\raisebox{-.5\dp0}[\ht0][\dp0]{\resizebox{\width}{.8\dimen8}{#1}}}%
}

% Don't display annoying red boxes around errors
\renewcommand{\fcolorbox}[4][]{#4}

\begin{document}

\setlength{\lineskip}{0pt}
\begin{minted}{C}
      ╭─────────────────────────────╮
      │                  ╭───╮      │
      │  ╭───╮           │╭─╮│      │
      │  ↑   │           │↑ ││      │
void (*signal(int, void (*fp)(int)))(int);
 ↑    ↑      │      ↑    ↑  ││      │
 │    ╰──────╯      │    ╰──╯│      │
 │                  ╰────────╯      │
 ╰──────────────────────────────────╯
\end{minted}

\end{document}

Do the assignment to \lineskip only locally.

enter image description here

Related Question