3

I've been using the site since starting to learn LaTeX a few months ago, and find it to be very helpful thanks to you all.

My Issue is that some professors at my university do not like the assignments to be typed as it seems that some students copy and paste the answers from the internet, and we are told to solve the problems by hand. Now, I still want to keep the problem statements in latex, then print them and complete them by hand, I've been doing so, ever since, but find that without the grid is just too messy.

I would like the file to look like that in the picture, but I achieved that exporting my document as a PDF and using some "design software" to draw the grid, and it is too time consuming to do so on every page of the assignment (usually 8 pages long). enter image description here I'll leave you an example of the source code:

\documentclass[a4paper, 11pt]{article}
\usepackage{comment} % enables the use of multi-line comments (\ifx \fi)

\usepackage{fullpage} % changes the margin \usepackage[a4paper, total={7in, 10in}]{geometry} \usepackage[fleqn]{amsmath} \usepackage{amssymb,amsthm} % assumes amsmath package installed \newtheorem{theorem}{Theorem} \newtheorem{corollary}{Corollary} \usepackage{graphicx} \usepackage{tikz} \usetikzlibrary{arrows} \usepackage{verbatim} \usepackage{float} \usepackage{tikz} \usetikzlibrary{shapes,arrows} \usetikzlibrary{arrows,calc,positioning}

\tikzset{
    block/.style = {draw, rectangle,
        minimum height=1cm,
        minimum width=1.5cm},
    input/.style = {coordinate,node distance=1cm},
    output/.style = {coordinate,node distance=4cm},
    arrow/.style={draw, -latex,node distance=2cm},
    pinstyle/.style = {pin edge={latex-, black,node distance=2cm}},
    sum/.style = {draw, circle, node distance=1cm},
}

\usepackage{xcolor} \usepackage{mdframed} \usepackage[shortlabels]{enumitem} \usepackage{indentfirst} \usepackage{hyperref}

\renewcommand{\thesubsection}{\thesection.\alph{subsection}}

\newenvironment{problem}[2][Problem] { \begin{mdframed} \textbf{#1 #2} \} { \end{mdframed}}

% Define solution environment \newenvironment{solution} {\textbf{\textit{Ans.\ \ \}}} {}

\renewcommand{\qed}{\quad\qedsymbol} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{document} %Header-Make sure you update this information!!!! \noindent %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \large\textbf{Homework - #4} \hfill \textbf{Leonardo Sánchez} \ Calculus 1 \hfill Civil & Electromechanical Engineering \ Professor Fang Jung Shiou \hfill Due date: $30^{th}$ March, 2020\ Teacher Assistant: Paulo C. C. Galeano \ \noindent\rule{7in}{2.8pt} %Problem 1% \begin{problem}{1 - (Section 11.3 Exs. 17 & 21 - Page 726 - Stewart $8^{th}$ ed.)} Determine whether the series is convergent or divergent.\ a) $$\sum_{n=1}^\infty \cfrac{1}{n^2 + 4}.$$ b) $$\sum_{n=2}^{\infty}\cfrac{1}{n \ln n}.$$ \end{problem} \begin{solution} \pagebreak
\end{solution} \end{document}

I read that environments do not work that way and it's not possible to nest some things inside them, so if my question is bad formulated, can someone point to me what would be the right way to achieve what I'm asking?

Thanks in advance!

  • Welcome to TeX.SX! Please try to make the code compilable: 'mcode.sty' not found. Moreover, many people will not have the font SimSun, maybe you can do without it? – gernot Sep 15 '20 at 18:19
  • Thank you! it is my first post, I'll try to modify the code and re-upload it, I forgot I change a lot of configs here and there for the chinese characters – LSanchez.Dev Sep 15 '20 at 19:57
  • Edited and tested without the "mcode.sty" "xelatex" compiler and "Chinese characters" in a new document alone in folder, and compiled succesfuly. Hope it works now, and thanks again! – LSanchez.Dev Sep 15 '20 at 20:13

1 Answers1

5

As I understand it, you want to print the grid for all questions so the solution environment is redundant and, instead, you can make the problem environment automatically add the grid. It is easy to draw a grid using TikZ, so the main issue is knowing how big the grid should be or, equivalently, knowing where the bottom of the page is. Luckily, the tikzpagenodes package defines a current page text area node so it is enough to draw a grid from the current position to (current page text area.south east). Doing this results in:

enter image description here

There is a little bit of extra trickery to ensure that only full squares are printed in the grid because I thought that having "half squares" on the right hand side and on the bottom of the grid looked rather ordinary. To do this I have made the squares in the grid 20pt x 20pt and then rounded the coordinates to multiples of 20. I would have preferred to give the grid size in millimeters but this turned out to be painful.

In addition adding the grid I have added a problem counter to automatically number the problems. Secondly, rather than typing a), b) etc by hand I recommend using an enumerate environment -- I have used \setlist from the enumitem package so that you get the counters in the OP. Finally, I would not put use $$...$$ for the equations in the questions and would instead use $\displaymath ...$ -- and please see Why is \[ ... \] preferable to $$ ... $$?

Here is the updated code:

\documentclass[a4paper, 11pt]{article}
\usepackage{comment} % enables the use of multi-line comments (\ifx \fi)

\usepackage{fullpage} % changes the margin \usepackage[a4paper, total={7in, 10in}]{geometry} \usepackage[fleqn]{amsmath} \usepackage{amssymb,amsthm} % assumes amsmath package installed \newtheorem{theorem}{Theorem} \newtheorem{corollary}{Corollary} \usepackage{graphicx} \usepackage{tikz} \usetikzlibrary{arrows} \usepackage{verbatim} \usepackage{float} \usepackage{tikz} \usetikzlibrary{shapes,arrows} \usetikzlibrary{arrows,calc,positioning}

\tikzset{
    block/.style = {draw, rectangle,
        minimum height=1cm,
        minimum width=1.5cm},
    input/.style = {coordinate,node distance=1cm},
    output/.style = {coordinate,node distance=4cm},
    arrow/.style={draw, -latex,node distance=2cm},
    pinstyle/.style = {pin edge={latex-, black,node distance=2cm}},
    sum/.style = {draw, circle, node distance=1cm},
}

\usepackage{tikzpagenodes} \usepackage{xcolor} \usepackage{mdframed} \usepackage[shortlabels]{enumitem} \usepackage{indentfirst} \usepackage{hyperref}

\renewcommand{\thesubsection}{\thesection.\alph{subsection}}

\newcounter{problem} \newenvironment{problem}[2][Problem] { \refstepcounter{problem}% \begin{mdframed}% % the \detokenize checks to see if #2 is empty in which case % nothing is printed \textbf{#1 \theproblem\if\relax\detokenize{#2}\relax\else~-- (#2)\fi} \ } { \end{mdframed}% \textbf{\textit{Ans.}}\newline% \begin{tikzpicture}[remember picture, overlay] % some extra trickery to ensure that the grid only has whole squares \draw[step=20pt, gray!40, thin] let \p1=(current page text area.south east), \n1={20int(\x1/20)}, \n2={20int(\y1/20)} in (0,0) grid (\n1,\n2); \end{tikzpicture}% \pagebreak% }

\usepackage{enumitem} \setlist[enumerate]{label=\alph*)}

\renewcommand{\qed}{\quad\qedsymbol} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{document} %Header-Make sure you update this information!!!! \noindent %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \large\textbf{Homework - #4} \hfill \textbf{Leonardo Sánchez} \ Calculus 1 \hfill Civil & Electromechanical Engineering \ Professor Fang Jung Shiou \hfill Due date: $30^{th}$ March, 2020\ Teacher Assistant: Paulo C. C. Galeano \ \noindent\rule{7in}{2.8pt} %Problem 1% \begin{problem}{Section 11.3 Exs. 17 & 21 - Page 726 - Stewart $8^{th}$ ed.} Determine whether the series is convergent or divergent. \begin{enumerate} \item $\displaystyle \sum_{n=1}^\infty \cfrac{1}{n^2 + 4}$. \item $\displaystyle \sum_{n=2}^{\infty}\cfrac{1}{n \ln n}$. \end{enumerate} \end{problem}

%Problem 2% \begin{problem}{} Determine whether the series is convergent or divergent. \begin{enumerate} \item $\displaystyle \sum_{n=1}^\infty \cfrac{1}{n^2 + 4}$. \item $\displaystyle \sum_{n=2}^{\infty}\cfrac{1}{n \ln n}$. \end{enumerate} \end{problem}

%Problem 3% \begin{problem}{Section 11.3 Exs. 17 & 21 - Page 726 - Stewart $8^{th}$ ed.} Determine whether the series is convergent or divergent. \begin{enumerate} \item $\displaystyle \sum_{n=1}^\infty \cfrac{1}{n^2 + 4}$. \item $\displaystyle \sum_{n=2}^{\infty}\cfrac{1}{n \ln n}$. \end{enumerate} \end{problem}

\end{document}

  • Thank you very much! yes I initially try to use "\begin{equation*}" but had some problems with justification (don't really remember what kind of issues i had encouner) but after a while started using "[]" instead of "$$\", this is an old example code I'd used last semester, because I wanted to get rid of the over-complicated format with Chinese characters, and the XeLaTeX compiler for that as well, as the previous comment suggested. – LSanchez.Dev Sep 16 '20 at 14:38
  • You saved my A LOT of tedious time drawing the squares with another software, really appreciated. Have a nice day, great work! – LSanchez.Dev Sep 16 '20 at 14:46
  • 1
    @LSanchez.Dev Glad it's of help –  Sep 16 '20 at 22:01
  • Is there a way to use the grid box as background for the problem resolution to be handled to students? – JPMD Apr 01 '23 at 08:32