如何用方格纸作为背景创建方框

如何用方格纸作为背景创建方框

如何为我的方框添加方格纸背景?

例子:

\documentclass{article}
\usepackage{framed}

\begin{document}
Calculate the Solution of $5+3$

\begin{framed}
\vspace{5cm}
\end{framed}

\end{document}

盒子

答案1

tikz这可以通过自定义样式来实现mdframed(而不是framed

\documentclass{article}

\usepackage[framemethod=tikz]{mdframed}
\usetikzlibrary{backgrounds}

\mdfdefinestyle{graphpaper}{%
    apptotikzsetting={\tikzset{mdfbackground/.style={}}},
    singleextra={%
        \scoped[on background layer,yshift=\mdfboundingboxheight]{\draw[step=5mm, line width=0.2mm, black!20!white] (0,0) grid (\mdfboundingboxwidth,-\mdfboundingboxheight);}
    },
}

\begin{document}
Calculate the Solution of $5+3$

\begin{mdframed}[style=graphpaper]
\vspace{5cm}
\end{mdframed}

\end{document}

带方格纸背景的盒子

答案2

这可以通过 tcolorbox 的自定义样式(而不是框架)来实现

\documentclass{article}

\usepackage{tcolorbox}
\tcbuselibrary{hooks,breakable,skins}


\newtcolorbox{graphpaperBox}[1][]{
    enhanced,
    sharp corners,
    breakable,
    colback=white,
    underlay={%
        \begin{tcbclipinterior}
            \draw[step=5mm, line width=0.2mm, black!20!white, shift={(interior.north west)}] (0,0)  grid (interior.south east);
        \end{tcbclipinterior}
    }
    #1}

\begin{document}
Calculate the Solution of $5+3$

\begin{graphpaperBox}
    \vspace{5cm}
\end{graphpaperBox}

\end{document}

解决方案

相关内容