使用 Tikz 展示考试

使用 Tikz 展示考试

这是我的实际文件

在此处输入图片描述

我想要的是下图(见下图),但我不知道怎么做。有人可以帮忙做这个演示吗?我希望左边有 2 厘米的边距用于分级(这里我有 4 厘米),右边有 4.5 厘米的边距,并写上:不要在此栏中写字(在更正期间添加评论)。 在此处输入图片描述

这是我的代码:

\documentclass [a4paper,10pt]{report}

%%%% PACKAGE %%%%%%%%%%%%%%%%%%%
\usepackage{fullpage}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{fancyhdr}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{mathrsfs}
\usepackage{hyperref}
\usepackage{enumitem}

\begin{document}
\subsection*{Exercise 1}
\begin{enumerate}
\item Let $f:\mathbb R\to \mathbb R$ the function defined by $f(x)=\frac{\sin(x)}{x}$. Prove it's continuous on $(0,1]$.\\


\begin{tikz}[color=gray!60]
\draw (0,0) grid[step=0.4] (15.2,2.4);
\end{tikz}
\ \\
\item Let $g:\mathbb R\to \mathbb R$ the function defined by $g(x)=\frac{\sin(x)}{x^2}$. Prove it's continuous on $(0,1]$.\\

\begin{tikz}[color=gray!60]
\draw (0,0) grid[step=0.4] (15.2,2.4);
\end{tikz}
\end{enumerate}
\end{document}

答案1

借助该geoemtry包,您可以调整边距大小。在下面的 MWE 中,我还添加了marginpar在右边距中写入文本的功能。最后,我还修改了网格的宽度以自动适应文本块。

在此处输入图片描述

\documentclass [a4paper,10pt]{report}

%%%% PACKAGE %%%%%%%%%%%%%%%%%%%
%\usepackage{fullpage}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{fancyhdr}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{mathrsfs}
\usepackage{hyperref}
\usepackage{enumitem}
\usepackage{marginnote}
\usepackage{calc}
\usepackage[left=2cm, right=4.5cm, marginparwidth=3.5cm]{geometry}
\begin{document}
\subsection*{Exercise 1}
\marginpar{Do not write in this column}
\begin{enumerate}
\item Let $f:\mathbb R\to \mathbb R$ the function defined by $f(x)=\frac{\sin(x)}{x}$. Prove it's continuous on $(0,1]$.\\


\begin{tikz}[color=gray!60]
\draw (0,0) grid[step=0.4] (\textwidth-\leftmargin,2.4);
\end{tikz}
\ \\
\item Let $g:\mathbb R\to \mathbb R$ the function defined by $g(x)=\frac{\sin(x)}{x^2}$. Prove it's continuous on $(0,1]$.\\

\begin{tikz}[color=gray!60]
\draw (0,0) grid[step=0.4] (\textwidth-\leftmargin,2.4);
\end{tikz}
\end{enumerate}
\end{document}

在此处输入图片描述

\documentclass [a4paper,10pt]{report}

%%%% PACKAGE %%%%%%%%%%%%%%%%%%%
%\usepackage{fullpage}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{fancyhdr}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{mathrsfs}
\usepackage{hyperref}
\usepackage{enumitem}
\usepackage{marginnote}
\usepackage{calc}
\usepackage[left=2cm-\leftmargin, right=4.5cm, marginparwidth=3.5cm]{geometry}
\begin{document}
\subsection*{Exercise 1}

\begin{enumerate}

\item Let $f:\mathbb R\to \mathbb R$ the function defined by $f(x)=\frac{\sin(x)}{x}$. Prove it's continuous on $(0,1]$.\\

\marginpar{\color{blue} \centering Do not write in this column \begin{tikzpicture}\draw (0,0) -- (\marginparwidth,2); \draw (\marginparwidth,0) -- (0,2);  \end{tikzpicture}}
\begin{tikz}[color=gray!60]
\draw (0,0) grid[step=0.4] (\textwidth-\leftmargin,2.4);
\end{tikz}
\ \\
\item Let $g:\mathbb R\to \mathbb R$ the function defined by $g(x)=\frac{\sin(x)}{x^2}$. Prove it's continuous on $(0,1]$.\\

\begin{tikz}[color=gray!60]
\draw (0,0) grid[step=0.4] (\textwidth-\leftmargin,2.4);
\end{tikz}
\end{enumerate}
\end{document}

答案2

以下提供的代码将用网格填充水平可用空间。水平方向仅填充网格步长的倍数。您可以指定line width、网格stepheightcolor

\documentclass [a4paper,10pt]{report}

%%%% PACKAGE %%%%%%%%%%%%%%%%%%%
\usepackage{fullpage}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{fancyhdr}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{mathrsfs}
\usepackage{hyperref}
\usepackage{enumitem}

\pgfkeys
  {%
    /surb/.cd,
    ,step/.initial=0.4cm
    ,height/.initial=2.4cm
    ,line width/.initial=0.4pt
    ,color/.initial=gray!60
  }
\newcommand\surbval[1]{\pgfkeysvalueof{/surb/#1}}
\newcommand\gridfill[1][]
  {%
    \begingroup
      \leavevmode
      \pgfkeys{/surb/.cd,#1}%
      \null
      \leaders\hbox
        {%
          \tikz\draw[color=\surbval{color}, line width=\surbval{line width}]
            (0,0) grid [step=\surbval{step}]
            (\surbval{step},\surbval{height})%
            (0,0) rectangle (\surbval{step},\surbval{height})
            ;%
          \kern-\surbval{line width}\relax
        }%
        \hfill
      \kern\surbval{line width}\relax
    \endgroup
  }

\usepackage{showframe} % just to show that it'll not create overfull lines

\begin{document}
\subsection*{Exercise 1}
\begin{enumerate}
\item Let $f:\mathbb R\to \mathbb R$ the function defined by
  $f(x)=\frac{\sin(x)}{x}$. Prove it's continuous on $(0,1]$.\\
  \gridfill
\item Let $g:\mathbb R\to \mathbb R$ the function defined by
  $g(x)=\frac{\sin(x)}{x^2}$. Prove it's continuous on $(0,1]$.\\
  \gridfill[height=4cm]
\end{enumerate}
\end{document}

在此处输入图片描述

编辑:因为有人在不相关的聊天中向我提到了这一点。

以下为 添加了另一个键\gridfill,即height target,它将像 键一样设置总体使用高度height,但实际网格将仅以 的倍数绘制step,因此剩余空间将为空白(填充到顶部)。如果height target大于0pt,它将被使用,并且必须是有效的 TeX 长度(因此需要有效的单位)。

\documentclass [a4paper,10pt]{report}

%%%% PACKAGE %%%%%%%%%%%%%%%%%%%
\usepackage{fullpage}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{fancyhdr}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{mathrsfs}
\usepackage{hyperref}
\usepackage{enumitem}

\pgfkeys
  {%
    /surb/.cd,
    ,step/.initial=0.4cm
    ,height/.initial=2.4cm
    ,height target/.initial=-\maxdimen
    ,line width/.initial=0.4pt
    ,color/.initial=gray!60
  }
\newcommand\surbval[1]{\pgfkeysvalueof{/surb/#1}}
\newcommand*\surbtmp{}
\newcommand\gridfill[1][]
  {%
    \begingroup
      \leavevmode
      \pgfkeys{/surb/.cd,#1}%
      \null
      \leaders\hbox
        {%
          \ifdim\surbval{height target}>0pt
            \pgfmathsetmacro\surbtmp
              {int(\surbval{height target}/\surbval{step})*\surbval{step}}%
            \pgfkeyssetvalue{/surb/height}{\surbtmp pt}%
            \rule{0pt}{\surbval{height target}}%
          \fi
          \tikz\draw[color=\surbval{color}, line width=\surbval{line width}]
            (0,0) grid [step=\surbval{step}]
            (\surbval{step},\surbval{height})%
            (0,0) rectangle (\surbval{step},\surbval{height})
            ;%
          \kern-\surbval{line width}\relax
        }%
        \hfill
      \kern\surbval{line width}\relax
    \endgroup
  }

\usepackage{showframe} % just to show that it'll not create overfull lines

\begin{document}
\subsection*{Exercise 1}
\begin{enumerate}
\item Let $f:\mathbb R\to \mathbb R$ the function defined by
  $f(x)=\frac{\sin(x)}{x}$. Prove it's continuous on $(0,1]$.\\
  \gridfill[height target=4.3cm]
\item Let $g:\mathbb R\to \mathbb R$ the function defined by
  $g(x)=\frac{\sin(x)}{x^2}$. Prove it's continuous on $(0,1]$.\\
  \gridfill[height=4cm]
\end{enumerate}
\end{document}

相关内容