2

I want to have a monospace font for block characters, U+2580, U+2584, U+2588 (see below).

For those characters, I use pmboxdraw.

\documentclass{article}
\usepackage{pmboxdraw}
\begin{document}\tiny\begin{verbatim}
████ ▄▄▄ █▄   ▄ ▄▄▄▄▀▀ ▄█▄ ▄▄▄ ▄ ▀█▄▀▄█▄▀ ▄█▀▀  ▀▄▀▄▀▄█ █████
████▄▀ ▀ █▄▀█▄▀▄▀  ▄ ▄ ▄█ ▀ ▀█ ██▄ ▄▀▀▀██ ▀▀▄▄▀▀ █▄▄▀▀█▄█████
████▄▀ ▀██▄ ▄▀█ ▄▀▀▀▄▄▄▄███▀ ▄█ ▄█▀ ▀████▀▀▀█▄ ▀█▀▀ ▄▄▄ ▄████
████▄▄▀ ▄▀▄█ ██ ▄▀█▀▀▄█▄▄▀▀▀▀▄██ █▀▀ ██▄ █▄ ▀ ▄▄▀▄ ▄█▄▄▀▄████
\end{verbatim}
\end{document}

However, with latex, this results in a non monospace font and the characters are shifted.

non monospace

How to get monospace characters with pmboxdraw?

2

The characters from pmboxdraw are monospaced by default (so verbatim is not strictly necessary, although it is convenient to avoid problems with indentation, line endings etc).

However, the empty characters that you draw (for example the 5th character on the first line) are regular space characters, which are not drawn by pmboxdraw. This means that the default typesetting of a space character is used, which is not necessarily the same width as the pmboxdraw characters, even in monospace.

To avoid this problem a workaround is to draw gray (i.e., shaded) boxes instead of spaces, and redefine a shaded box to be rendered in white. Of course this means that you cannot use shaded boxes anymore, but it is a quick workaround.

MWE:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{pmboxdraw}
\usepackage{color}
\makeatletter
\def\pmbd@Shade#1#2{%
  \pmbd@BeginBox{Shade}%
    \ltx@ifundefined{textcolor}{%
      \pmbd@colorwarning{#1}%
    }{%
      \textcolor{white}{\pmbd@Rule\pmbd@W\pmbd@H\z@}
    }%
  \pmbd@EndBox
}
\makeatother
\begin{document}\tiny
\begin{verbatim}
████░▄▄▄░█▄░░░▄░▄▄▄▄▀▀░▄█▄░▄▄▄░▄░▀█▄▀▄█▄▀░▄█▀▀░░▀▄▀▄▀▄█░█████
████▄▀░▀░█▄▀█▄▀▄▀░░▄░▄░▄█░▀░▀█░██▄░▄▀▀▀██░▀▀▄▄▀▀░█▄▄▀▀█▄█████
████▄▀░▀██▄░▄▀█░▄▀▀▀▄▄▄▄███▀░▄█░▄█▀░▀████▀▀▀█▄░▀█▀▀░▄▄▄░▄████
████▄▄▀░▄▀▄█░██░▄▀█▀▀▄█▄▄▀▀▀▀▄██░█▀▀░██▄░█▄░▀░▄▄▀▄░▄█▄▄▀▄████
\end{verbatim}
\end{document}

Result:

enter image description here

Another approach is to use a font that supports these characters and compile with XeLaTeX or LuaLaTeX. In this case the pmboxdraw package is not needed.

MWE:

\documentclass{article}
\usepackage{fontspec}
\setmonofont{DejaVu Sans Mono}
\begin{document}
\begin{verbatim}
████ ▄▄▄ █▄   ▄ ▄▄▄▄▀▀ ▄█▄ ▄▄▄ ▄ ▀█▄▀▄█▄▀ ▄█▀▀  ▀▄▀▄▀▄█ █████
████▄▀ ▀ █▄▀█▄▀▄▀  ▄ ▄ ▄█ ▀ ▀█ ██▄ ▄▀▀▀██ ▀▀▄▄▀▀ █▄▄▀▀█▄█████
████▄▀ ▀██▄ ▄▀█ ▄▀▀▀▄▄▄▄███▀ ▄█ ▄█▀ ▀████▀▀▀█▄ ▀█▀▀ ▄▄▄ ▄████
████▄▄▀ ▄▀▄█ ██ ▄▀█▀▀▄█▄▄▀▀▀▀▄██ █▀▀ ██▄ █▄ ▀ ▄▄▀▄ ▄█▄▄▀▄████
\end{verbatim}
\end{document}

Result:

enter image description here

| improve this answer | |
  • Thanks a lot for the comprehensive answer! – Martin Monperrus May 2 at 7:54
2

You can change the size of space to get the same width as a block:

\documentclass{article}
\usepackage{pmboxdraw}
\begin{document}


{%
\tiny\ttfamily \setbox0=\hbox{█}\fontdimen2\font=\wd0
\begin{verbatim}
████ ▄▄▄ █▄   ▄ ▄▄▄▄▀▀ ▄█▄ ▄▄▄ ▄ ▀█▄▀▄█▄▀ ▄█▀▀  ▀▄▀▄▀▄█ █████
████▄▀ ▀ █▄▀█▄▀▄▀  ▄ ▄ ▄█ ▀ ▀█ ██▄ ▄▀▀▀██ ▀▀▄▄▀▀ █▄▄▀▀█▄█████
████▄▀ ▀██▄ ▄▀█ ▄▀▀▀▄▄▄▄███▀ ▄█ ▄█▀ ▀████▀▀▀█▄ ▀█▀▀ ▄▄▄ ▄████
████▄▄▀ ▄▀▄█ ██ ▄▀█▀▀▄█▄▄▀▀▀▀▄██ █▀▀ ██▄ █▄ ▀ ▄▄▀▄ ▄█▄▄▀▄████
\end{verbatim}
}

\end{document}

enter image description here

| improve this answer | |
  • yes the \makeatletter remained from something else, thanks. – Ulrike Fischer May 1 at 13:20
  • Nice simplification, thanks! – Martin Monperrus May 2 at 7:54

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.