9

Sadly I didn't found any source showing this. I just need a grid behind some math. Usually I box equations using:

\documentclass[preview]{standalone}

\usepackage[most]{tcolorbox}

\begin{document}

\newcommand{\frameGrid}[1]{\tikz[baseline=(X.base)]\node [draw = gray,fill=gray!20, inner sep=0pt] (X) {#1};}

\frameGrid{$\sqrt{\dfrac{1}{2}-\dfrac{1}{4}}$}

\end{document}

It'd be cool to have squared paper inside the box as well. Even if I can't imagine how.

3 Answers 3

9

Sticking with your tikz solution and modifying it:

\documentclass{standalone}

\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{patterns.meta}

\begin{document}

\newcommand{\frameGrid}[2]{
    \tikz[baseline=(X.base)]
    \node[
        preaction={fill, black!10!white},
        pattern={Hatch[distance=#1, xshift=0.5*#1, yshift=0.5*#1, line width=0.05*#1]},
        pattern color=black!20!white,
        draw=gray,
        inner sep=0pt
    ] (X) {#2};
}

\frameGrid{2mm}{$\sqrt{\dfrac{1}{2}-\dfrac{1}{4}}$}

\end{document}

equation grid

2
  • Looks exactly like the pattern I'm searching. It just gives me " Package pgf Error: Undefined pattern `Hatch' ". Following exactly your code
    – Leon
    Nov 14, 2021 at 21:17
  • 1
    Try updating your TeX distribution. I don't know when the Hatch pattern was added to patterns.meta but maybe your version of tikz is to old.
    – mais
    Nov 15, 2021 at 9:37
9

With tcolorbox package

\documentclass{article}
\usepackage[most]{tcolorbox}
\tcbset{enhanced, colframe=green!80!black, colback=yellow!10!white,
    underlay={
        \begin{tcbclipinterior}
            \draw[help lines, step=5mm, red!20, shift={(interior.north west)}]
                (interior.south west) grid (interior.north east);
        \end{tcbclipinterior}
    }
}
\begin{document}
\tcbox{$\sqrt{\dfrac{1}{2}-\dfrac{1}{4}}$}
\end{document}

enter image description here

8

The following draws a 25 by 6 grid (grid size 0.75em) and places a formula in its center. The color of the grid is set through \special{ps:...} commands.

\newdimen\grid \grid=.75em
\def\gridrow#1#2{\hbox{\leaders\hbox{\hskip.3\grid\vrule height#2\grid
  \hskip-.4pt\hskip.7\grid}\hskip#1\grid}}
\special{ps:gsave 0.75 setgray}
\vbox to0pt{
  \leaders\vbox{\gridrow{25}{.3}\hrule\vskip-.4pt\gridrow{25}{.7}}\vskip 6\grid
  \vss
}
\special{ps:grestore}
\vbox to 6\grid{\vfil\hbox to25\grid{\hfil$1=2$\hfil}\vfil}

enter image description here

2
  • 1
    Extra points for the elaborate formula of alternative math!
    – thymaro
    Nov 15, 2021 at 1:00
  • @thymaro worth a bounty! Nov 15, 2021 at 4:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .