I'm making a list of problems and at the end of the statement of each question I'm making vertical and horizontal lines using tikzpicture. I'm setting the number of rows and columns manually. The number of columns is fixed, but the number of lines, I have to manually adjust each question, because the size of the statement is different. At the end of each question I use \newpage. I was wondering if there is a way to do this automatically. My code is

\usepackage[left=1cm,right=1cm,top=1cm,bottom=1.8cm]{geometry}% Margens

\usepackage{indentfirst}                % Coloca parágrafo no início texto
\usepackage[portuguese]{babel}          % Linguagem português
\usepackage[pdftex]{hyperref}           % Para criar anexar links
%\usepackage{lmodern}                   % Usa a fonte Latin Modern
\usepackage{multicol}                   % Texto em duas colunas
\newcommand{\fixspacing}{\vspace{0pt plus 1filll}\mbox{}}

\tikzstyle{dashdotted}=[dash pattern=on 9pt off 2pt on \the\pgflinewidth off 2pt]

%\setlength{\columnsep}{0.7cm}          % Separação entre as colunas
%\usepackage{chemformula}               % Para escrever fórmulas químicas
%\usepackage[version=4]{mhchem}         % |
%\usetikzlibrary{fit}                   % |Formatação das fórmulas químicas
%\usepackage{mol2chemfig}               % |
%\usepackage{caption}                   % Colocar caption em minipage
%\usepackage[font=footnotesize,labelfont=bf]{caption} %Coloca a "Figura" em negrito nas legendas
%\usepackage{microtype}                     % para melhorias de justificação
%\usepackage[brazilian,hyperpageref]{backref}    % Paginas com as citações na bibliografia
%\usepackage[alf]{abntex2cite}          % Citações padrão ABNT
%\usepackage{lipsum}                        % para geração de dummy text
\usepackage{subfigure}                  % Adicionar subfiguras
%\usepackage{fontawesome}               % Fonte e simbolos
\usepackage{xcolor}                     % Mudar cor das palavras
\usepackage{graphicx}                   % Inclusão de gráficos
%\hypersetup{colorlinks = true}         % Colorir Links
%\usepackage{nomencl}                   % Lista de simbolos
\usepackage[utf8]{inputenc}             % Codificacao do documento (conversão automática dos acentos)
%\usepackage{showframe}                 % Mostra margens
\usepackage{amsmath}                    % Ambiente Matemático
\usepackage{array}                      % Para colocar tabelas
\usepackage{float}                      % fixa a figura no lugar
\usepackage[a]{esvect}                  % vetor pra maiuscula
\setlist[enumerate]{wide=0pt, align=left}

\usepackage{calc}% http://ctan.org/pkg/calc


            myrectangle/.style={rectangle, draw, minimum width=160, minimum height=40, thick, rounded corners=5, black}
            \node[myrectangle] (a) at (0,0) {
                    CAMPUS CURVELO\\}
                %1ª lista de exercícios do 3° bimestre – 1ª ano\\
    %\centering Prof. 


\centering 1ª lista de exercícios do 4° bimestre - 1° ano - Prof. 


\centering \normalsize \textbf{Potência e rendimento}


\item Qual é o rendimento de um motor que recebe a potência de 300 W, durante 1 min, e realiza um trabalho de 4.320 J?

\begin{tikzpicture}[x=1cm, y=1cm, semitransparent]
    \draw[step=5mm, line width=0.2mm, black!60!white,dotted] (0,0) grid (19,22);

%   \draw[gray,dotted,help lines,xstep=.6cm, ystep=0.6cm,line width=0.1pt] (0,0) grid (1,1);

\item Uma máquina tem potência total de 500 HP e rendimento de 60\%. Determine:

    \item a potência útil que ela desenvolve;
    \item o trabalho útil que sua força pode realizar em 10 s. Dado: 1 HP = 746 W.

\begin{tikzpicture}[x=1cm, y=1cm, semitransparent]
    \draw[step=5mm, line width=0.2mm, black!60!white,dotted] (0,0) grid (19,25);
  • 1
    \begin{minipage}{0\textwidth} why 0pt wide? The image is clearly wider than this. Nov 5, 2022 at 0:57
  • 1
    you are not giving any scope to \centering so it applies to the rest of the document the second one is doing nothing Nov 5, 2022 at 1:00

1 Answer 1


I created a macro that fills any space with a grid using TikZ and basic \fill macros. The grid is drawn only up to the next full step that fits in horizontal and vertical dimension. The grid is anchored at the top left corner. You can use the optional argument to style the grid.


    \tikz[remember picture]{ \coordinate (grid start) at (0,0); }%
    \tikz[remember picture]{ \coordinate (grid end) at (0,0); }%
    \begin{tikzpicture}[remember picture, overlay, #1]
        \draw let \p1 = (grid start |- grid end),
                  \p2 = (grid start -| grid end), 
                  \n1 = {veclen(\x1,\y1)},
                  \n2 = {veclen(\x2,\y2)}
              in \pgfextra{
                  \pgfmathsetlength{\gridwidth}{int(\n1 / \gridstep) * \gridstep}
                  \pgfmathsetlength{\gridheight}{int(\n2 / \gridstep) * \gridstep}
                  \draw[shift={(grid start)}] (0,0) grid (\gridwidth,-\gridheight);



\gridfill[step=5mm, line width=0.2mm, opacity=0.5, dotted]




enter image description here

  • It´s exactaly what I'm looking for. Thanks Jasper
    – Ulisses
    Nov 7, 2022 at 13:51
  • @Ulisses: I suggest you upvote this answer if you haven't already and then accept it.
    – Sandy G
    Dec 8, 2022 at 2:35
  • Sorry, I forgot! It´s done!
    – Ulisses
    Dec 13, 2022 at 18:06

You must log in to answer this question.

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