如何將網格插入環境“Ans”。好像是手工完成的?

如何將網格插入環境“Ans”。好像是手工完成的?

自從幾個月前開始學習 LaTeX 以來,我就一直在使用這個網站,並且發現它非常有幫助,謝謝大家。

我的問題是,我大學的一些教授不喜歡列印作業,因為似乎有些學生從網路上複製並貼上答案,然後我們被告知要手動解決問題。現在,我仍然想將問題陳述保留在乳膠中,然後列印它們並手動完成它們,從那時起我就一直這樣做,但發現沒有網格太混亂了。

我希望文件看起來像圖片中的那樣,但我實現了將文檔導出為 PDF 並使用一些“設計軟體”來繪製網格,並且在作業的每一頁上都這樣做太耗時(通常有8頁長)。 在此輸入影像描述 我會給你一個原始碼的例子:

\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}

我讀到環境不是這樣運作的,而且不可能在其中嵌套一些東西,所以如果我的問題表述得不好,有人可以指出我實現我所要求的目標的正確方法是什麼嗎?

先致謝!

答案1

據我了解,您想要列印所有問題的網格,因此solution環境是多餘的,相反,您可以使problem環境自動添加網格。使用以下命令可以輕鬆繪製網格蒂克茲,所以主要問題是知道網格應該有多大,或者等效地,知道頁面底部在哪裡。幸運的是,tikz頁面節點套件定義了一個current page text area節點,因此足以繪製從目前位置到 的網格(current page text area.south east)。這樣做的結果是:

在此輸入影像描述

有一些額外的技巧來確保在網格中只列印完整的正方形,因為我認為在網格的右側和底部有“半正方形”看起來相當普通。為此,我將網格中的正方形設為 20pt x 20pt,然後將座標四捨五入為 20 的倍數。

除了添加網格之外,我還添加了一個problem計數器來自動對問題進行編號。其次,我建議使用一個環境,​​而不是手動輸入a)b)enumerate我已經使用\setlist列舉項包,以便您獲得 OP 中的計數器。最後,我不會$$...$$在問題中使用方程式,而是使用$\displaymath ...$- 請參閱為什麼 \[ ... \] 優於 $$ ... $$?

這是更新後的程式碼:

\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={20*int(\x1/20)},
            \n2={20*int(\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}

相關內容