2

I want to implement a raster graphic like this but i don't want to insert the image file. Does anybody know how to create some in latex?:enter image description here

  • 3
    And where is the problem? –  Oct 23 '17 at 13:23
  • As Herbert says, where is your question? This is easy to do in tikz, and even better, the output will be vector graphics – daleif Oct 23 '17 at 13:29
  • the problem is that i don't want to insert the image file, but i have no clue how to create graphics like this in latex... – Nils Fr. Oct 23 '17 at 13:31
  • 1
    Somewhat related: https://tex.stackexchange.com/questions/157080/can-tikz-create-pixel-art-images. Also this: https://tex.stackexchange.com/questions/308936/what-is-the-best-way-to-create-this-kind-of-binary-matrix – Steven B. Segletes Oct 23 '17 at 13:33

1 Answers1

3

EDIT: Added \bordercolor as a parameter, in addition to \thk rule thickness and \gsize grid size.

\documentclass{article}
\usepackage[usestackEOL]{stackengine}
\usepackage{xcolor, graphicx}
\newsavebox{\Bbox}\newsavebox{\Gbox}
\def\thk{.5pt}                   % RULE THICKNESS
\def\gsize{.65cm}                % GRID SIZE
\def\bordercolor{black}          % GRID BORDER COLOR
\def\coresize{\dimexpr\gsize-2\dimexpr\thk}
\setstackgap{S}{-\thk}
\def\Grid#1{\kern-\thk\fboxsep=0pt\relax\fboxrule=\thk\relax%
  \textcolor{\bordercolor}{\fbox{\textcolor{#1}{\rule[-.5\coresize]{\coresize}{\coresize}}}}}
\newcommand\Cgeneric[2][]{\stackinset{c}{.0pt}{c}{-.4pt}{\sffamily#1}{\Grid{#2}}}
\newcommand\Cw[1][]{\Cgeneric[#1]{white}\ignorespaces}
\newcommand\Ct[1][]{\Cgeneric[#1]{brown!40!gray!40}\ignorespaces}
\newcommand\Cb[1][]{\Cgeneric[#1]{cyan!30}\ignorespaces}
\begin{document}
\Shortstack{%
      \Ct\Ct   \Ct   \Ct   \Ct\\
      \Ct\Ct[C]\Ct[B]\Ct[D]\Ct\\
      \Ct\Ct[A]\Cb[X]\Cw   \Cw\\
      \Cw\Cw   \Cw   \Cw   \Cw\\
      \Cw\Cw   \Cw   \Cw   \Cw
}
\end{document}

enter image description here